Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Utils / RestrictedInt.hh
1 // $Id$
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief RestrictedInt public header */
25
26 #ifndef HH_SENF_senf_Utils_RestrictedInt_
27 #define HH_SENF_senf_Utils_RestrictedInt_ 1
28
29 // Custom includes
30 #include <iostream>
31 #include <boost/operators.hpp>
32 #include <senf/Utils/safe_bool.hh>
33
34 //#include "RestrictedInt.mpp"
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36
37 namespace senf {
38
39     // Really ... the correct spelling is 'euclidean' as in the current boost
40     // Versions but older versions only have this spelling so we can' t use
41     // the correct class name ...
42
43     template <class Base, class Tag>
44     class RestrictedInt
45         : public boost::ordered_euclidian_ring_operators< RestrictedInt<Base,Tag>,
46                  boost::unit_steppable< RestrictedInt<Base,Tag>,
47                  boost::shiftable< RestrictedInt<Base,Tag>,
48                  boost::bitwise1< RestrictedInt<Base,Tag>,
49                  senf::comparable_safe_bool< RestrictedInt<Base,Tag> > > > > >
50     {
51     public:
52         explicit RestrictedInt(Base value) : value_ (value) {}
53         RestrictedInt() : value_ () {}
54
55 #       define BinaryOp(op)                                             \
56             RestrictedInt & operator op ## = (RestrictedInt other)      \
57                 { value_ op ## = other.value_; return *this; }
58 #       define IncDecOp(op)                                             \
59             RestrictedInt & operator op ()                              \
60                 { op value_; return *this; }
61 #       define PrefixOp(op)                                             \
62             RestrictedInt const operator op () const                    \
63                 { return RestrictedInt(op value_); }
64 #       define CompareOp(op)                                            \
65             bool operator op (RestrictedInt other) const                \
66                 { return value_ op other.value_; }
67
68         BinaryOp(+)
69         BinaryOp(-)
70         BinaryOp(*)
71         BinaryOp(/)
72         BinaryOp(%)
73         BinaryOp(>>)
74         BinaryOp(<<)
75         BinaryOp(&)
76         BinaryOp(|)
77         BinaryOp(^)
78
79         IncDecOp(++)
80         IncDecOp(--)
81
82         PrefixOp(~)
83         PrefixOp(-)
84
85         CompareOp(<)
86         CompareOp(==)
87
88 #       undef CompareOp
89 #       undef PrefixOp
90 #       undef PostfixOp
91 #       undef BinaryOp
92
93         Base value() const
94             { return value_; }
95
96         bool boolean_test() const
97             { return value_; }
98
99     private:
100         Base value_;
101     };
102
103     template <class Base, class Tag>
104     std::ostream & operator<<(std::ostream & os, RestrictedInt<Base, Tag> value)
105         { os << value.value(); return os; }
106
107     template <class Base, class Tag>
108     std::istream & operator>>(std::istream & is, RestrictedInt<Base, Tag> & value)
109         { Base v; is >> v; value = RestrictedInt<Base,Tag>(v); return is; }
110
111 }
112
113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
114 //#include "RestrictedInt.cci"
115 //#include "RestrictedInt.ct"
116 //#include "RestrictedInt.cti"
117 #endif
118
119 \f
120 // Local Variables:
121 // mode: c++
122 // fill-column: 100
123 // comment-column: 40
124 // c-file-style: "senf"
125 // indent-tabs-mode: nil
126 // ispell-local-dictionary: "american"
127 // compile-command: "scons -u test"
128 // End: