libzypp  13.10.6
DefaultIntegral.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_DEFAULTINTEGRAL_H
13 #define ZYPP_BASE_DEFAULTINTEGRAL_H
14 
15 #include <iosfwd>
16 #include <boost/static_assert.hpp>
17 #include <boost/type_traits/is_integral.hpp>
18 
20 namespace zypp
21 {
22 
23 
25  //
26  // CLASS NAME : DefaultIntegral<_Tp,_Initial>
27  //
40  template<class _Tp, _Tp _Initial>
42  {
43  public:
44  typedef _Tp value_type;
45 
46  public:
47  DefaultIntegral( _Tp val_r = _Initial )
48  : _val( val_r )
49  { BOOST_STATIC_ASSERT(boost::is_integral<_Tp>::value); }
50 
53  _Tp & get() { return _val; }
54  _Tp get() const { return _val; }
55 
56  operator _Tp &() { return get(); }
57  operator _Tp () const { return get(); }
59 
61  DefaultIntegral & reset() { _val = _Initial; return *this; }
62 
67  DefaultIntegral & operator=( _Tp rhs ) { _val = rhs; return *this; }
68  DefaultIntegral & operator+=( _Tp rhs ) { _val += rhs; return *this; }
69  DefaultIntegral & operator-=( _Tp rhs ) { _val -= rhs; return *this; }
70  DefaultIntegral & operator*=( _Tp rhs ) { _val *= rhs; return *this; }
71  DefaultIntegral & operator/=( _Tp rhs ) { _val /= rhs; return *this; }
72 
73  DefaultIntegral & operator++(/*prefix*/) { ++_val; return *this; }
74  DefaultIntegral & operator--(/*prefix*/) { --_val; return *this; }
75 
76  DefaultIntegral operator++(int/*postfix*/) { return _val++; }
77  DefaultIntegral operator--(int/*postfix*/) { return _val--; }
79 
80  private:
81  _Tp _val;
82  };
83 
85 } // namespace zypp
87 #endif // ZYPP_BASE_DEFAULTINTEGRAL_H
DefaultIntegral(_Tp val_r=_Initial)
DefaultIntegral & operator+=(_Tp rhs)
DefaultIntegral & operator-=(_Tp rhs)
DefaultIntegral operator--(int)
DefaultIntegral operator++(int)
DefaultIntegral & operator*=(_Tp rhs)
Integral type with defined initial value when default constructed.
DefaultIntegral & operator=(_Tp rhs)
DefaultIntegral & operator/=(_Tp rhs)
DefaultIntegral & operator--()
DefaultIntegral & reset()
Reset to the defined initial value.
DefaultIntegral & operator++()