00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_senf_Utils_RestrictedInt_
00027 #define HH_SENF_senf_Utils_RestrictedInt_ 1
00028
00029
00030 #include <iostream>
00031 #include <boost/operators.hpp>
00032 #include <senf/Utils/safe_bool.hh>
00033
00034
00035
00036
00037 namespace senf {
00038
00039
00040
00041
00042
00043 template <class Base, class Tag>
00044 class RestrictedInt
00045 : public boost::ordered_euclidian_ring_operators< RestrictedInt<Base,Tag>,
00046 boost::unit_steppable< RestrictedInt<Base,Tag>,
00047 boost::shiftable< RestrictedInt<Base,Tag>,
00048 boost::bitwise1< RestrictedInt<Base,Tag>,
00049 senf::comparable_safe_bool< RestrictedInt<Base,Tag> > > > > >
00050 {
00051 public:
00052 typedef Base base_type;
00053 typedef Tag tag_type;
00054
00055 explicit RestrictedInt(Base value) : value_ (value) {}
00056 RestrictedInt() : value_ () {}
00057
00058 # define BinaryOp(op) \
00059 RestrictedInt & operator op ## = (RestrictedInt other) \
00060 { value_ op ## = other.value_; return *this; }
00061 # define IncDecOp(op) \
00062 RestrictedInt & operator op () \
00063 { op value_; return *this; }
00064 # define PrefixOp(op) \
00065 RestrictedInt const operator op () const \
00066 { return RestrictedInt(op value_); }
00067 # define CompareOp(op) \
00068 bool operator op (RestrictedInt other) const \
00069 { return value_ op other.value_; }
00070
00071 BinaryOp(+)
00072 BinaryOp(-)
00073 BinaryOp(*)
00074 BinaryOp(/)
00075 BinaryOp(%)
00076 BinaryOp(>>)
00077 BinaryOp(<<)
00078 BinaryOp(&)
00079 BinaryOp(|)
00080 BinaryOp(^)
00081
00082 IncDecOp(++)
00083 IncDecOp(--)
00084
00085 PrefixOp(~)
00086 PrefixOp(-)
00087
00088 CompareOp(<)
00089 CompareOp(==)
00090
00091 # undef CompareOp
00092 # undef PrefixOp
00093 # undef PostfixOp
00094 # undef BinaryOp
00095
00096 Base value() const
00097 { return value_; }
00098
00099 bool boolean_test() const
00100 { return value_; }
00101
00102 private:
00103 Base value_;
00104 };
00105
00106 template <class Base, class Tag>
00107 std::ostream & operator<<(std::ostream & os, RestrictedInt<Base, Tag> value)
00108 { os << value.value(); return os; }
00109
00110 template <class Base, class Tag>
00111 std::istream & operator>>(std::istream & is, RestrictedInt<Base, Tag> & value)
00112 { Base v; is >> v; value = RestrictedInt<Base,Tag>(v); return is; }
00113
00114 }
00115
00116
00117
00118
00119
00120 #endif
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131