4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
27 // Philipp Batroff <philipp.batroff@fokus.fraunhofer.de>
30 \brief RestrictedInt public header */
32 #ifndef HH_SENF_senf_Utils_RestrictedInt_
33 #define HH_SENF_senf_Utils_RestrictedInt_ 1
37 #include <boost/operators.hpp>
38 #include <senf/Utils/safe_bool.hh>
40 //#include "RestrictedInt.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 // Really ... the correct spelling is 'euclidean' as in the current boost
46 // Versions but older versions only have this spelling so we can' t use
47 // the correct class name ...
49 template <class Base, class Tag>
51 : public boost::ordered_euclidian_ring_operators< RestrictedInt<Base,Tag>,
52 boost::unit_steppable< RestrictedInt<Base,Tag>,
53 boost::shiftable< RestrictedInt<Base,Tag>,
54 boost::bitwise1< RestrictedInt<Base,Tag>,
55 senf::comparable_safe_bool< RestrictedInt<Base,Tag> > > > > >
58 typedef Base base_type;
61 explicit RestrictedInt(Base value) : value_ (value) {}
62 RestrictedInt() : value_ () {}
64 # define BinaryOp(op) \
65 RestrictedInt & operator op ## = (RestrictedInt other) \
66 { value_ op ## = other.value_; return *this; }
67 # define IncDecOp(op) \
68 RestrictedInt & operator op () \
69 { op value_; return *this; }
70 # define PrefixOp(op) \
71 RestrictedInt const operator op () const \
72 { return RestrictedInt(op value_); }
73 # define CompareOp(op) \
74 bool operator op (RestrictedInt other) const \
75 { return value_ op other.value_; }
105 bool boolean_test() const
108 RestrictedInt<Base, Tag> operator*(int i) const
109 { return RestrictedInt<Base, Tag>(value_ * i); }
111 RestrictedInt<Base, Tag> operator/(int i) const
112 { return RestrictedInt<Base, Tag>(value_ / i); }
114 bool operator>(int i) const
115 { return value_ > i; }
117 bool operator>=(int i) const
118 { return value_ >= i; }
120 bool operator<(int i) const
121 { return value_ < i; }
123 bool operator<=(int i) const
124 { return value_ <= i; }
126 bool operator==(int i) const
127 { return value_ == i; }
129 bool operator!=(int i) const
130 { return value_ != i; }
136 template <class Base, class Tag>
137 std::ostream & operator<<(std::ostream & os, RestrictedInt<Base, Tag> value)
138 { os << value.value(); return os; }
140 template <class Base, class Tag>
141 std::istream & operator>>(std::istream & is, RestrictedInt<Base, Tag> & value)
142 { Base v; is >> v; value = RestrictedInt<Base,Tag>(v); return is; }
146 //-/////////////////////////////////////////////////////////////////////////////////////////////////
147 //#include "RestrictedInt.cci"
148 //#include "RestrictedInt.ct"
149 //#include "RestrictedInt.cti"
156 // comment-column: 40
157 // c-file-style: "senf"
158 // indent-tabs-mode: nil
159 // ispell-local-dictionary: "american"
160 // compile-command: "scons -u test"