Loading...
Searching...
No Matches
restinio::http_field_parsers::qvalue_t Class Reference

A class for holding the parsed value of qvalue from RFC7231. More...

`#include <basics.hpp>`

## Public Types

using | underlying_uint_t = qvalue_details::underlying_uint_t
| The type of underlying small integer.
using | trusted = qvalue_details::trusted
| The type that doesn't check a value to be used for qvalue.
using | untrusted = qvalue_details::untrusted
| The type that checks a value to be used for qvalue.

## Public Member Functions

constexpr | qvalue_t ()=default
| qvalue_t (untrusted val) noexcept
constexpr | qvalue_t (trusted val) noexcept
constexpr | qvalue_t (qvalue_details::extremum_min_t) noexcept
constexpr | qvalue_t (qvalue_details::extremum_max_t) noexcept
constexpr auto | as_uint () const noexcept
auto | as_string () const

## Static Public Attributes

static constexpr qvalue_details::extremum_max_t | maximum
| The indicator that tells that new qvalue object should have the maximal allowed value.
static constexpr qvalue_details::extremum_min_t | zero
| The indicator that tells that new qvalue object should have the minimal allowed value.

## Private Types

using | underlying_char_array_t = std::array< char, 6 >

## Private Member Functions

underlying_char_array_t | make_char_array () const noexcept

## Private Attributes

underlying_uint_t | m_value {}

## Friends

std::ostream & | operator<< (std::ostream &to, const qvalue_t &what)

## Detailed Description

A class for holding the parsed value of qvalue from RFC7231.

An important note: qvalue in RFC7231 is defined as a number with fractional point. This number can have no more that three digits after a point. And the non-factional part can only be 0 or 1. If non-frational part is 1 then fractional part can only be 0. It means that qvalue can be in the range [0.000, 1.000].

To simplify work with qvalue RESTinio holds qvalue as a small integer in the range [0, 1000] where 0 corresponds to 0.000 and 1000 corresponds to 1.000. In means, for example, that value 0.05 will be represented and 50, and the value 0.001 will be represented as 1, and the value 0.901 will be represented as 901.

The integer representation of qvalue can be obtained via as_uint() method.

Method as_string() returns std::string with number with fractional part inside. It means:

assert("1.000" == qvalue_t{qvalue_t::maximum}.as_string());
assert("0.901" == qvalue_t{qvalue_t::untrusted{901}}.as_string());
restinio::http_field_parsers::qvalue_details::untrusted
A helper wrapper to indicate that value hasn't been checked yet and should be checked in the construc...
Definition: basics.hpp:64
restinio::http_field_parsers::qvalue_t
A class for holding the parsed value of qvalue from RFC7231.
Definition: basics.hpp:136
restinio::http_field_parsers::qvalue_t::maximum
static constexpr qvalue_details::extremum_max_t maximum
The indicator that tells that new qvalue object should have the maximal allowed value.
Definition: basics.hpp:147

Such representation is also used in `operator<<` for std::ostream.

Instances of qvalue_t can be compared, operations `==`, `!=`, `<` and `<=` are supported.

There are two ways to construct a new qvalue object.

The first and recommended way is intended for cases when the source value for a new qvalue object isn't known at the compile-time and produced somehow at the run-time. It's the usage of qvalue_t::untrusted wrapper:

qvalue_t weight{qvalue_t::untrusted{config.default_weigh() * 10}};
config_s
Definition: deflate.c:120

In that case the value of `untrusted` will be checked in qvalue_t::untrusted's constructor and an exception will be thrown if that value isn't in [0, 1000] range.

The second way is intended to be used with compile-time constants:

qvalue_t weight{qvalue_t::trusted{250}};
restinio::http_field_parsers::qvalue_details::trusted
A helper wrapper to indicate that value is already checked and shouldn't be checked again.
Definition: basics.hpp:51

In the case of `trusted` the value is not checked in qvalue_t's constructor. Therefore that way should be used with additional care.

Since
  v.0.6.1

Definition at line 135 of file basics.hpp.

## Member Typedef Documentation

## trusted

using restinio::http_field_parsers::qvalue_t::trusted = qvalue_details::trusted

The type that doesn't check a value to be used for qvalue.

Definition at line 141 of file basics.hpp.

## underlying_char_array_t

using restinio::http_field_parsers::qvalue_t::underlying_char_array_t = std::array<char, 6>

private

Definition at line 156 of file basics.hpp.

## underlying_uint_t

using restinio::http_field_parsers::qvalue_t::underlying_uint_t = qvalue_details::underlying_uint_t

The type of underlying small integer.

Definition at line 139 of file basics.hpp.

## untrusted

using restinio::http_field_parsers::qvalue_t::untrusted = qvalue_details::untrusted

The type that checks a value to be used for qvalue.

Definition at line 143 of file basics.hpp.

## Constructor & Destructor Documentation

## qvalue_t() [1/5]

constexpr restinio::http_field_parsers::qvalue_t::qvalue_t | ( |  | ) |

constexpr default

## qvalue_t() [2/5]

restinio::http_field_parsers::qvalue_t::qvalue_t | ( | untrusted | val | ) |

inline noexcept

Definition at line 188 of file basics.hpp.

## qvalue_t() [3/5]

constexpr restinio::http_field_parsers::qvalue_t::qvalue_t | ( | trusted | val | ) |

inline constexpr noexcept

Definition at line 192 of file basics.hpp.

## qvalue_t() [4/5]

constexpr restinio::http_field_parsers::qvalue_t::qvalue_t | ( | qvalue_details::extremum_min_t |  | ) |

inline constexpr noexcept

Definition at line 196 of file basics.hpp.

## qvalue_t() [5/5]

constexpr restinio::http_field_parsers::qvalue_t::qvalue_t | ( | qvalue_details::extremum_max_t |  | ) |

inline constexpr noexcept

Definition at line 200 of file basics.hpp.

## Member Function Documentation

## as_string()

auto restinio::http_field_parsers::qvalue_t::as_string | ( |  | ) | const

inline

Definition at line 206 of file basics.hpp.

## as_uint()

constexpr auto restinio::http_field_parsers::qvalue_t::as_uint | ( |  | ) | const

inline constexpr noexcept

Definition at line 204 of file basics.hpp.

## make_char_array()

underlying_char_array_t restinio::http_field_parsers::qvalue_t::make_char_array | ( |  | ) | const

inline private noexcept

Definition at line 161 of file basics.hpp.

## Friends And Related Function Documentation

## operator<<

std::ostream & operator<< | ( | std::ostream & | to,
|  | const qvalue_t & | what
| ) |  |

friend

Definition at line 211 of file basics.hpp.

## Member Data Documentation

## m_value

underlying_uint_t restinio::http_field_parsers::qvalue_t::m_value {}

private

Definition at line 158 of file basics.hpp.

## maximum

constexpr qvalue_details::extremum_max_t restinio::http_field_parsers::qvalue_t::maximum

static constexpr

Initial value:
=
qvalue_details::extremum_max_t::v
restinio::http_field_parsers::qvalue_details::extremum_max_t::v
@ v

The indicator that tells that new qvalue object should have the maximal allowed value.

Definition at line 147 of file basics.hpp.

## zero

constexpr qvalue_details::extremum_min_t restinio::http_field_parsers::qvalue_t::zero

static constexpr

Initial value:
=
qvalue_details::extremum_min_t::v
restinio::http_field_parsers::qvalue_details::extremum_min_t::v
@ v

The indicator that tells that new qvalue object should have the minimal allowed value.

Definition at line 151 of file basics.hpp.

The documentation for this class was generated from the following file:

- restinio/helpers/http_field_parsers/basics.hpp