libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_BASE_DEFAULTINTEGRAL_H 00013 #define ZYPP_BASE_DEFAULTINTEGRAL_H 00014 00015 #include <iosfwd> 00016 #include <boost/static_assert.hpp> 00017 #include <boost/type_traits/is_integral.hpp> 00018 00020 namespace zypp 00021 { 00022 00023 00025 // 00026 // CLASS NAME : DefaultIntegral<_Tp,_Initial> 00027 // 00040 template<class _Tp, _Tp _Initial> 00041 class DefaultIntegral 00042 { 00043 public: 00044 typedef _Tp value_type; 00045 00046 public: 00047 DefaultIntegral( _Tp val_r = _Initial ) 00048 : _val( val_r ) 00049 { BOOST_STATIC_ASSERT(boost::is_integral<_Tp>::value); } 00050 00053 _Tp & get() { return _val; } 00054 _Tp get() const { return _val; } 00055 00056 operator _Tp &() { return get(); } 00057 operator _Tp () const { return get(); } 00059 00061 DefaultIntegral & reset() { _val = _Initial; return *this; } 00062 00067 DefaultIntegral & operator=( _Tp rhs ) { _val = rhs; return *this; } 00068 DefaultIntegral & operator+=( _Tp rhs ) { _val += rhs; return *this; } 00069 DefaultIntegral & operator-=( _Tp rhs ) { _val -= rhs; return *this; } 00070 DefaultIntegral & operator*=( _Tp rhs ) { _val *= rhs; return *this; } 00071 DefaultIntegral & operator/=( _Tp rhs ) { _val /= rhs; return *this; } 00072 00073 DefaultIntegral & operator++(/*prefix*/) { ++_val; return *this; } 00074 DefaultIntegral & operator--(/*prefix*/) { ++_val; return *this; } 00075 00076 DefaultIntegral operator++(int/*postfix*/) { return _val++; } 00077 DefaultIntegral operator--(int/*postfix*/) { return _val--; } 00079 00080 private: 00081 _Tp _val; 00082 }; 00083 00085 } // namespace zypp 00087 #endif // ZYPP_BASE_DEFAULTINTEGRAL_H