ome-xml 5.2.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
ome::xml::model::primitives::ConstrainedNumeric< N, C, E > Class Template Reference

A numeric type constrained to a subrange (or subranges) of its range limits. More...

`#include <ome/xml/model/primitives/ConstrainedNumeric.h>`

Inheritance diagram for ome::xml::model::primitives::ConstrainedNumeric< N, C, E >:
[legend]
Collaboration diagram for ome::xml::model::primitives::ConstrainedNumeric< N, C, E >:
[legend]

## 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...

## Detailed Description

### template<typename N, typename C, typename E = ConstrainedNumericError>
class ome::xml::model::primitives::ConstrainedNumeric< N, C, E >

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.

Template Parameters

  N | the type to constrain.
  C | the constraint to impose.
  E | the error policy to apply on constraint violation.

## Constructor & Destructor Documentation

template<typename N, typename C, typename E = ConstrainedNumericError>

ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::ConstrainedNumeric | ( |  | ) |
| 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.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check().

template<typename N, typename C, typename E = ConstrainedNumericError>

ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::ConstrainedNumeric | ( | value_type | value | ) |
| inline

Construct a ConstrainedNumeric from an unconstrained value.

An exception may be thrown if the value does not meet the constraints.

Parameters

  value | the unconstrained value to set.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check().

template<typename N, typename C, typename E = ConstrainedNumericError>

ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::ConstrainedNumeric | ( | const std::string & | value | ) |
| inline

Construct a ConstrainedNumeric a string value.

An exception may be thrown if the value does not meet the constraints.

Parameters

  value | the string value to set.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::typestr.

template<typename N, typename C, typename E = ConstrainedNumericError>

ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::ConstrainedNumeric | ( | const ConstrainedNumeric< N, C, E > & | value | ) |
| inline

Copy constructor.

Parameters

  value | the constrained value to copy.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check().

## Member Function Documentation

template<typename N, typename C, typename E = ConstrainedNumericError>

ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator value_type | ( |  | ) | const
| inline

Obtain the constrained value as the unconstrained type.

Returns
  the constrained value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator%= | ( | const ConstrainedNumeric< N, C, E > & | value | ) |
| inline

Modulo of the constrained value by a constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to compute the modulus with.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator%= | ( | const value_type & | value | ) |
| inline

Modulo of the constrained value by an unconstrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to compute the modulus with.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator*= | ( | const ConstrainedNumeric< N, C, E > & | value | ) |
| inline

Multiply the constrained value by a constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to multiply.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator*= | ( | const value_type & | value | ) |
| inline

Multiply the constrained value by an unconstrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to multiply.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator++ | ( |  | ) |
| inline

Increment the constrained value by one.

If the new value fails the constraint check, this will cause an error.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator+= | ( | const ConstrainedNumeric< N, C, E > & | value | ) |
| inline

Add a constrained value to the constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to add.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator+= | ( | const value_type & | value | ) |
| inline

Add an unconstrained value to the constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to add.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator-- | ( |  | ) |
| inline

Decrement the constrained value by one.

If the new value fails the constraint check, this will cause an error.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator-= | ( | const ConstrainedNumeric< N, C, E > & | value | ) |
| inline

Subtract a constrained value from the constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to subtract.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator-= | ( | const value_type & | value | ) |
| inline

Subtract an unconstrained value from the constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to subtract.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator/= | ( | const ConstrainedNumeric< N, C, E > & | value | ) |
| inline

Divide the constrained value by a constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to divide.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator/= | ( | const value_type & | value | ) |
| inline

Divide the constrained value by an constrained value.

If the new value fails the constraint check, this will cause an error.

Parameters

  value | the value to divide.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

bool ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator< | ( | const ConstrainedNumeric< N, C, E > & | value | ) | const
| inline

Check if the constrained value is less than a constrained value.

Parameters

  value | the value to compare with.

Returns
  true if the condition is true, else false.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

bool ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator< | ( | const value_type & | value | ) | const
| inline

Check if the constrained value is less than an unconstrained value.

Parameters

  value | the value to compare with.

Returns
  true if the condition is true, else false.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator= | ( | const ConstrainedNumeric< N, C, E > & | value | ) |
| 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.

Parameters

  value | the value to assign.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

ConstrainedNumeric& ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator= | ( | const value_type & | value | ) |
| inline

Assign the constrained value from an unconstrained value.

If the value fails the constraint check, this will cause an error.

Parameters

  value | the value to assign.

Returns
  the new value.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::check(), and ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

bool ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator== | ( | const ConstrainedNumeric< N, C, E > & | value | ) | const
| inline

Check if the constrained value is equal to a constrained value.

Parameters

  value | the value to compare with.

Returns
  true if the condition is true, else false.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

bool ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator== | ( | const value_type & | value | ) | const
| inline

Check if the constrained value is equal to an unconstrained value.

Parameters

  value | the value to compare with.

Returns
  true if the condition is true, else false.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

template<typename N, typename C, typename E = ConstrainedNumericError>

bool ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::operator> | ( | const value_type & | value | ) | const
| inline

Check if the constrained value is greater than an unconstrained value.

Parameters

  value | the value to compare with.

Returns
  true if the condition is true, else false.

References ome::xml::model::primitives::ConstrainedNumeric< N, C, E >::value.

## Friends And Related Function Documentation

template<typename N, typename C, typename E = ConstrainedNumericError>
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
| ) |  |
| friend

Set constrained value from input stream.

Parameters

  is | the input stream.
  value | the value to set.

Returns
  the input stream.

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

- ome/xml/model/primitives/ConstrainedNumeric.h
- ome/xml/model/primitives/NonNegativeFloat.cpp
- ome/xml/model/primitives/NonNegativeInteger.cpp
- ome/xml/model/primitives/NonNegativeLong.cpp
- ome/xml/model/primitives/PercentFraction.cpp
- ome/xml/model/primitives/PositiveFloat.cpp
- ome/xml/model/primitives/PositiveInteger.cpp
- ome/xml/model/primitives/PositiveLong.cpp