Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

RestrictedInt.hh

Go to the documentation of this file.
00001 // $Id: RestrictedInt.hh 1784 2011-04-19 11:41:35Z tho $
00002 //
00003 // Copyright (C) 2010
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_senf_Utils_RestrictedInt_
00027 #define HH_SENF_senf_Utils_RestrictedInt_ 1
00028 
00029 // Custom includes
00030 #include <iostream>
00031 #include <boost/operators.hpp>
00032 #include <senf/Utils/safe_bool.hh>
00033 
00034 //#include "RestrictedInt.mpp"
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 namespace senf {
00038 
00039     // Really ... the correct spelling is 'euclidean' as in the current boost
00040     // Versions but older versions only have this spelling so we can' t use
00041     // the correct class name ...
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 //#include "RestrictedInt.cci"
00118 //#include "RestrictedInt.ct"
00119 //#include "RestrictedInt.cti"
00120 #endif
00121 
00122 
00123 // Local Variables:
00124 // mode: c++
00125 // fill-column: 100
00126 // comment-column: 40
00127 // c-file-style: "senf"
00128 // indent-tabs-mode: nil
00129 // ispell-local-dictionary: "american"
00130 // compile-command: "scons -u test"
00131 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research