RESTinio
|
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. More... | |
using | trusted = qvalue_details::trusted |
The type that doesn't check a value to be used for qvalue. More... | |
using | untrusted = qvalue_details::untrusted |
The type that checks a value to be used for qvalue. More... | |
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. More... | |
static constexpr qvalue_details::extremum_min_t | zero |
The indicator that tells that new qvalue object should have the minimal allowed value. More... | |
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) |
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:
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:
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:
In the case of trusted
the value is not checked in qvalue_t's constructor. Therefore that way should be used with additional care.
Definition at line 135 of file basics.hpp.
The type that doesn't check a value to be used for qvalue.
Definition at line 141 of file basics.hpp.
|
private |
Definition at line 156 of file basics.hpp.
The type of underlying small integer.
Definition at line 139 of file basics.hpp.
The type that checks a value to be used for qvalue.
Definition at line 143 of file basics.hpp.
|
constexprdefault |
|
inlinenoexcept |
Definition at line 188 of file basics.hpp.
|
inlineconstexprnoexcept |
Definition at line 192 of file basics.hpp.
|
inlineconstexprnoexcept |
Definition at line 196 of file basics.hpp.
|
inlineconstexprnoexcept |
Definition at line 200 of file basics.hpp.
|
inline |
Definition at line 206 of file basics.hpp.
|
inlineconstexprnoexcept |
Definition at line 204 of file basics.hpp.
|
inlineprivatenoexcept |
Definition at line 161 of file basics.hpp.
Definition at line 211 of file basics.hpp.
|
private |
Definition at line 158 of file basics.hpp.
|
staticconstexpr |
The indicator that tells that new qvalue object should have the maximal allowed value.
Definition at line 147 of file basics.hpp.
|
staticconstexpr |
The indicator that tells that new qvalue object should have the minimal allowed value.
Definition at line 151 of file basics.hpp.