ome-xml
5.6.0
|
A numeric type constrained to a subrange (or subranges) of its range limits. More...
#include <ome/xml/model/primitives/ConstrainedNumeric.h>
Public Types | |
typedef N | value_type |
The type to constrain. | |
typedef C | constraint_type |
The constraint to impose. | |
typedef E | error_policy_type |
The error policy to apply on constraint violation. | |
Public Member Functions | |
ConstrainedNumeric () | |
Construct a ConstrainedNumeric. More... | |
ConstrainedNumeric (value_type value) | |
Construct a ConstrainedNumeric from an unconstrained value. More... | |
ConstrainedNumeric (const std::string &value) | |
Construct a ConstrainedNumeric a string value. More... | |
ConstrainedNumeric (const ConstrainedNumeric &value) | |
Copy constructor. More... | |
operator value_type () const | |
Obtain the constrained value as the unconstrained type. More... | |
ConstrainedNumeric & | operator= (const ConstrainedNumeric &value) |
Assign the constrained value from a constrained value. More... | |
ConstrainedNumeric & | operator= (const value_type &value) |
Assign the constrained value from an unconstrained value. More... | |
ConstrainedNumeric & | operator+= (const ConstrainedNumeric &value) |
Add a constrained value to the constrained value. More... | |
ConstrainedNumeric & | operator-= (const ConstrainedNumeric &value) |
Subtract a constrained value from the constrained value. More... | |
ConstrainedNumeric & | operator*= (const ConstrainedNumeric &value) |
Multiply the constrained value by a constrained value. More... | |
ConstrainedNumeric & | operator/= (const ConstrainedNumeric &value) |
Divide the constrained value by a constrained value. More... | |
ConstrainedNumeric & | operator%= (const ConstrainedNumeric &value) |
Modulo of the constrained value by a constrained value. More... | |
ConstrainedNumeric & | operator+= (const value_type &value) |
Add an unconstrained value to the constrained value. More... | |
ConstrainedNumeric & | operator-= (const value_type &value) |
Subtract an unconstrained value from the constrained value. More... | |
ConstrainedNumeric & | operator*= (const value_type &value) |
Multiply the constrained value by an unconstrained value. More... | |
ConstrainedNumeric & | operator/= (const value_type &value) |
Divide the constrained value by an constrained value. More... | |
ConstrainedNumeric & | operator%= (const value_type &value) |
Modulo of the constrained value by an unconstrained value. More... | |
ConstrainedNumeric & | operator++ () |
Increment the constrained value by one. More... | |
ConstrainedNumeric & | operator-- () |
Decrement the constrained value by one. More... | |
bool | operator< (const ConstrainedNumeric &value) const |
Check if the constrained value is less than a constrained value. More... | |
bool | operator< (const value_type &value) const |
Check if the constrained value is less than an unconstrained value. More... | |
bool | operator> (const value_type &value) const |
Check if the constrained value is greater than an unconstrained value. More... | |
bool | operator== (const ConstrainedNumeric &value) const |
Check if the constrained value is equal to a constrained value. More... | |
bool | operator== (const value_type &value) const |
Check if the constrained value is equal to an unconstrained value. More... | |
Static Public Attributes | |
static const value_type | default_value |
Default value for default construction. | |
Private Member Functions | |
void | check () |
Check that the set value meets the required constraints, and if it does not, handle this according to the configured error policy (defaulting to throwing a std::illegal_argument exception). | |
Private Attributes | |
value_type | value |
The value being constrained. | |
Static Private Attributes | |
static const std::string | typestr |
The name of the type. Used for diagnostics only. | |
Friends | |
template<class _charT , class _traits , typename _N , typename _C , typename _E > | |
std::basic_istream< _charT, _traits > & | operator>> (std::basic_istream< _charT, _traits > &is, ConstrainedNumeric< _N, _C, _E > &value) |
Set constrained value from input stream. More... | |
A numeric type constrained to a subrange (or subranges) of its range limits.
This templated class is specialised using a numeric (value) type to specify the type to be constrained, a constraint type to provide a constraint check (a function object) and an error policy type to handle errors when the constraint check fails (a function object). The default error policy is to throw an std::invalid_argument exception.
A ConstrainedNumeric instance should behave almost identically to and be directly subsitutable for the constrained value type. It is constructable using the value type and implicitly castable to the value type. It is also constructable from the string representation of the value type, and may be serialised to and from any stream. It also implements the standard numeric operators, so may be used as though it were the value type.
The default value for most template specialisations is 0
for integer types or 0.0
for floating point types. For types whose constraint would not allow zero as the default value, the default value is 1
for integer types or 1.0
for floating point types.
N | the type to constrain. |
C | the constraint to impose. |
E | the error policy to apply on constraint violation. |
|
inline |
Construct a ConstrainedNumeric.
Note that the ConstrainedNumeric value will be set to the default constructed value of the constrained value type. If this value fails the constraint check, an an error will be triggered according to the error policy, so not all ConstrainedNumeric types are safely default constructable.
|
inline |
Construct a ConstrainedNumeric from an unconstrained value.
An exception may be thrown if the value does not meet the constraints.
value | the unconstrained value to set. |
|
inline |
Construct a ConstrainedNumeric a string value.
An exception may be thrown if the value does not meet the constraints.
value | the string value to set. |
|
inline |
Copy constructor.
value | the constrained value to copy. |
|
inline |
Obtain the constrained value as the unconstrained type.
|
inline |
Modulo of the constrained value by a constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to compute the modulus with. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Modulo of the constrained value by an unconstrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to compute the modulus with. |
|
inline |
Multiply the constrained value by a constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to multiply. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Multiply the constrained value by an unconstrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to multiply. |
|
inline |
Increment the constrained value by one.
If the new value fails the constraint check, this will cause an error.
|
inline |
Add a constrained value to the constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to add. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Add an unconstrained value to the constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to add. |
|
inline |
Decrement the constrained value by one.
If the new value fails the constraint check, this will cause an error.
|
inline |
Subtract a constrained value from the constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to subtract. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Subtract an unconstrained value from the constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to subtract. |
|
inline |
Divide the constrained value by a constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to divide. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Divide the constrained value by an constrained value.
If the new value fails the constraint check, this will cause an error.
value | the value to divide. |
|
inline |
Check if the constrained value is less than a constrained value.
value | the value to compare with. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Check if the constrained value is less than an unconstrained value.
value | the value to compare with. |
|
inline |
Assign the constrained value from a constrained value.
While constraint checks are enforced, this should never cause an error due to the value having been previously checked.
value | the value to assign. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Assign the constrained value from an unconstrained value.
If the value fails the constraint check, this will cause an error.
value | the value to assign. |
|
inline |
Check if the constrained value is equal to a constrained value.
value | the value to compare with. |
References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.
|
inline |
Check if the constrained value is equal to an unconstrained value.
value | the value to compare with. |
|
inline |
Check if the constrained value is greater than an unconstrained value.
value | the value to compare with. |
|
friend |
Set constrained value from input stream.
is | the input stream. |
value | the value to set. |