mycpu/cdat.h

00001 
00008 #ifndef CDAT_H
00009 #define CDAT_H 1
00010 
00011 #include <boost/operators.hpp>
00012 #include <iostream>
00013 
00019 template <class T>
00020 class CDat
00021   : public boost::operators<CDat<T> >
00022 {
00023   public:
00034     CDat()
00035     {}
00036 
00047     virtual ~CDat()
00048     {}
00049 
00060     CDat(const CDat& other)
00061       : m_value(other.m_value)
00062     {}
00063 
00074     CDat(const T newval)
00075       : m_value(newval)
00076     {}
00077 
00088     T getValue() const
00089     {
00090       return m_value;
00091     }
00092 
00103     operator T()
00104     {
00105       return m_value;
00106     }
00107 
00118     bool operator<(const CDat& x) const
00119     {
00120       return m_value < x.m_value;
00121     }
00122 
00133     bool operator==(const CDat& x) const
00134     {
00135       return m_value == x.m_value;
00136     }
00137 
00148     CDat& operator+=(const CDat& x)
00149     {
00150       m_value += x.m_value;
00151       return *this;
00152     }
00153 
00164     CDat& operator-=(const CDat& x)
00165     {
00166       m_value -= x.m_value;
00167       return *this;
00168     }
00169 
00180     CDat& operator*=(const CDat& x)
00181     {
00182       m_value *= x.m_value;
00183       return *this;
00184     }
00185 
00196     CDat& operator/=(const CDat& x)
00197     {
00198       m_value /= x.m_value;
00199       return *this;
00200     }
00201 
00212     CDat& operator%=(const CDat& x)
00213     {
00214       m_value %= x.m_value;
00215       return *this;
00216     }
00217 
00228     CDat& operator|=(const CDat& x)
00229     {
00230       m_value |= x.m_value;
00231       return *this;
00232     }
00233 
00244     CDat& operator&=(const CDat& x)
00245     {
00246       m_value &= x.m_value;
00247       return *this;
00248     }
00249 
00260     CDat& operator^=(const CDat& x)
00261     {
00262       m_value ^= x.m_value;
00263       return *this;
00264     }
00265 
00276     CDat& operator++()
00277     {
00278       m_value++;
00279       return *this;
00280     }
00281 
00292     CDat& operator--()
00293     {
00294       m_value--;
00295       return *this;
00296     }
00297 
00309     friend std::ostream& operator<<(std::ostream& stream, CDat cdat)
00310     {
00311       stream << cdat.m_value;
00312       return stream;
00313     }
00314 
00326     friend std::istream& operator>>(std::istream & stream, CDat& cdat)
00327     {
00328       stream >> cdat.m_value;
00329       return stream;
00330     }
00331 
00332   protected:
00333     /* members */
00335     T m_value;
00336 };
00337 
00338 #endif
00339 
00340 /* vim: set et sw=2 ts=2: */

Generated on Sat May 30 16:32:35 2009 for mycpu by  doxygen 1.5.3