39 #ifndef OME_XML_MODEL_PRIMITIVES_CONSTRAINEDNUMERIC_H 40 #define OME_XML_MODEL_PRIMITIVES_CONSTRAINEDNUMERIC_H 46 #include <boost/format.hpp> 47 #include <boost/operators.hpp> 79 const std::string& typestr)
81 boost::format fmt(
"‘%1%’ not a supported value of %2%");
82 fmt % value % typestr;
83 throw std::invalid_argument(fmt.str());
120 boost::partially_ordered<ConstrainedNumeric<N, C, E>,
121 boost::equality_comparable2<ConstrainedNumeric<N, C, E>, N,
122 boost::equality_comparable<ConstrainedNumeric<N, C, E>,
123 boost::addable2<ConstrainedNumeric<N, C, E>, N,
124 boost::addable<ConstrainedNumeric<N, C, E>,
125 boost::subtractable2<ConstrainedNumeric<N, C, E>, N,
126 boost::subtractable<ConstrainedNumeric<N, C, E>,
127 boost::dividable2<ConstrainedNumeric<N, C, E>, N,
128 boost::dividable<ConstrainedNumeric<N, C, E>,
129 boost::multipliable2<ConstrainedNumeric<N, C, E>, N,
130 boost::multipliable<ConstrainedNumeric<N, C, E>,
131 boost::incrementable<ConstrainedNumeric<N, C, E>,
132 boost::decrementable<ConstrainedNumeric<N, C, E> > > > > > > > > > > > > > >
182 std::istringstream is(value);
183 is.imbue(std::locale::classic());
188 error_policy_type error;
189 error(value, this->typestr);
212 operator value_type ()
const 229 this->value = value.
value;
243 operator= (
const value_type& value)
261 this->value += value.
value;
277 this->value -= value.
value;
293 this->value *= value.
value;
309 this->value /= value.
value;
325 this->value %= value.
value;
339 operator+= (
const value_type& value)
341 this->value += value;
355 operator-= (
const value_type& value)
357 this->value -= value;
371 operator*= (
const value_type& value)
373 this->value *= value;
387 operator/= (
const value_type& value)
389 this->value /= value;
403 operator%= (
const value_type& value)
405 this->value %= value;
448 return this->value < value.
value;
459 operator< (
const value_type& value)
const 461 return this->value < value;
475 operator> (
const value_type& value)
const 477 return this->value > value;
490 return this->value == value.
value;
503 return this->value == value;
516 constraint_type constraint;
517 if (!constraint(this->value))
519 error_policy_type error;
520 error(this->value, this->typestr);
536 template<
class _charT,
542 std::basic_istream<_charT,_traits>&
543 operator>> (std::basic_istream<_charT,_traits>& is,
554 template<
class charT,
559 inline std::basic_istream<charT,traits>&
567 boost::format fmt(
"Failed to parse invalid input for %1%");
569 throw std::invalid_argument(fmt.str());
584 template<
class charT,
589 inline std::basic_ostream<charT,traits>&
590 operator<< (std::basic_ostream<charT,traits>& os,
593 return os << static_cast<typename ConstrainedNumeric<N, C, E>::value_type>(value);
601 #endif // OME_XML_MODEL_PRIMITIVES_CONSTRAINEDNUMERIC_H C constraint_type
The constraint to impose.
Definition: ConstrainedNumeric.h:138
value_type value
The value being constrained.
Definition: ConstrainedNumeric.h:525
ConstrainedNumeric(const ConstrainedNumeric &value)
Copy constructor.
Definition: ConstrainedNumeric.h:200
static const value_type default_value
Default value for default construction.
Definition: ConstrainedNumeric.h:143
Open Microscopy Environment C++ implementation.
E error_policy_type
The error policy to apply on constraint violation.
Definition: ConstrainedNumeric.h:140
bool operator==(const Color &lhs, const Color &rhs)
Compare two Color objects for equality.
Definition: Color.h:316
ConstrainedNumeric(value_type value)
Construct a ConstrainedNumeric from an unconstrained value.
Definition: ConstrainedNumeric.h:167
void check()
Check that the set value meets the required constraints, and if it does not, handle this according to...
Definition: ConstrainedNumeric.h:514
static const std::string typestr
The name of the type. Used for diagnostics only.
Definition: ConstrainedNumeric.h:527
Default error handler for ConstrainedNumeric.
Definition: ConstrainedNumeric.h:67
void operator()(const T &value, const std::string &typestr)
Throw an exception.
Definition: ConstrainedNumeric.h:78
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &is, Color &color)
Set Color from input stream.
Definition: Color.h:472
N value_type
The type to constrain.
Definition: ConstrainedNumeric.h:136
ConstrainedNumeric()
Construct a ConstrainedNumeric.
Definition: ConstrainedNumeric.h:154
ConstrainedNumeric(const std::string &value)
Construct a ConstrainedNumeric a string value.
Definition: ConstrainedNumeric.h:180
A numeric type constrained to a subrange (or subranges) of its range limits.
Definition: ConstrainedNumeric.h:119