39 #ifndef OME_XML_MODEL_PRIMITIVES_CONSTRAINEDNUMERIC_H 40 #define OME_XML_MODEL_PRIMITIVES_CONSTRAINEDNUMERIC_H 47 #include <boost/format.hpp> 48 #include <boost/operators.hpp> 78 const std::string& typestr)
80 boost::format fmt(
"‘%1%’ not a supported value of %2%");
81 fmt % value % typestr;
82 throw std::invalid_argument(fmt.str());
119 boost::partially_ordered<ConstrainedNumeric<N, C, E>,
120 boost::equality_comparable2<ConstrainedNumeric<N, C, E>, N,
121 boost::equality_comparable<ConstrainedNumeric<N, C, E>,
122 boost::addable2<ConstrainedNumeric<N, C, E>, N,
123 boost::addable<ConstrainedNumeric<N, C, E>,
124 boost::subtractable2<ConstrainedNumeric<N, C, E>, N,
125 boost::subtractable<ConstrainedNumeric<N, C, E>,
126 boost::dividable2<ConstrainedNumeric<N, C, E>, N,
127 boost::dividable<ConstrainedNumeric<N, C, E>,
128 boost::multipliable2<ConstrainedNumeric<N, C, E>, N,
129 boost::multipliable<ConstrainedNumeric<N, C, E>,
130 boost::incrementable<ConstrainedNumeric<N, C, E>,
131 boost::decrementable<ConstrainedNumeric<N, C, E>>>>>>>>>>>>>>>
181 std::istringstream is(value);
182 is.imbue(std::locale::classic());
187 error_policy_type error;
188 error(value, this->typestr);
211 operator value_type ()
const 228 this->value = value.
value;
242 operator= (
const value_type& value)
260 this->value += value.
value;
276 this->value -= value.
value;
292 this->value *= value.
value;
308 this->value /= value.
value;
324 this->value %= value.
value;
338 operator+= (
const value_type& value)
340 this->value += value;
354 operator-= (
const value_type& value)
356 this->value -= value;
370 operator*= (
const value_type& value)
372 this->value *= value;
386 operator/= (
const value_type& value)
388 this->value /= value;
402 operator%= (
const value_type& value)
404 this->value %= value;
447 return this->value < value.
value;
458 operator< (
const value_type& value)
const 460 return this->value < value;
474 operator> (
const value_type& value)
const 476 return this->value > value;
489 return this->value == value.
value;
502 return this->value == value;
515 constraint_type constraint;
516 if (!constraint(this->value))
518 error_policy_type error;
519 error(this->value, this->typestr);
535 template<
class _charT,
541 std::basic_istream<_charT,_traits>&
542 operator>> (std::basic_istream<_charT,_traits>& is,
553 template<
class charT,
558 inline std::basic_istream<charT,traits>&
566 boost::format fmt(
"Failed to parse invalid input for %1%");
568 throw std::invalid_argument(fmt.str());
583 template<
class charT,
588 inline std::basic_ostream<charT,traits>&
589 operator<< (std::basic_ostream<charT,traits>& os,
592 return os << static_cast<typename ConstrainedNumeric<N, C, E>::value_type>(value);
600 #endif // OME_XML_MODEL_PRIMITIVES_CONSTRAINEDNUMERIC_H C constraint_type
The constraint to impose.
Definition: ConstrainedNumeric.h:137
value_type value
The value being constrained.
Definition: ConstrainedNumeric.h:524
ConstrainedNumeric(const ConstrainedNumeric &value)
Copy constructor.
Definition: ConstrainedNumeric.h:199
static const value_type default_value
Default value for default construction.
Definition: ConstrainedNumeric.h:142
Open Microscopy Environment C++ implementation.
E error_policy_type
The error policy to apply on constraint violation.
Definition: ConstrainedNumeric.h:139
bool operator==(const Color &lhs, const Color &rhs)
Compare two Color objects for equality.
Definition: Color.h:322
ConstrainedNumeric(value_type value)
Construct a ConstrainedNumeric from an unconstrained value.
Definition: ConstrainedNumeric.h:166
void check()
Check that the set value meets the required constraints, and if it does not, handle this according to...
Definition: ConstrainedNumeric.h:513
static const std::string typestr
The name of the type. Used for diagnostics only.
Definition: ConstrainedNumeric.h:526
Default error handler for ConstrainedNumeric.
Definition: ConstrainedNumeric.h:66
void operator()(const T &value, const std::string &typestr)
Throw an exception.
Definition: ConstrainedNumeric.h:77
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &is, Color &color)
Set Color from input stream.
Definition: Color.h:478
N value_type
The type to constrain.
Definition: ConstrainedNumeric.h:135
ConstrainedNumeric()
Construct a ConstrainedNumeric.
Definition: ConstrainedNumeric.h:153
ConstrainedNumeric(const std::string &value)
Construct a ConstrainedNumeric a string value.
Definition: ConstrainedNumeric.h:179
A numeric type constrained to a subrange (or subranges) of its range limits.
Definition: ConstrainedNumeric.h:118