libzypp: zypp-core/base/defaultintegral.h Source File

libzypp 17.38.15

defaultintegral.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_CORE_BASE_DEFAULTINTEGRAL_H
13#define ZYPP_CORE_BASE_DEFAULTINTEGRAL_H
14
15#include <string>
16#include <boost/static_assert.hpp>
17#include <boost/type_traits/is_integral.hpp>
18
20namespace zypp
21{
22
23
25 //
26 // CLASS NAME : DefaultIntegral<Tp,TInitial>
27 //
40 template<class Tp, Tp TInitial>
41 class DefaultIntegral
42 {
43 public:
44 typedef Tp value_type;
45
46 public:
47 DefaultIntegral( Tp val_r = TInitial )
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 constexpr Tp initial() const { return TInitial; }
62
64 DefaultIntegral & reset() { _val = TInitial; return *this; }
65
70 DefaultIntegral & operator=( Tp rhs ) { _val = rhs; return *this; }
71 DefaultIntegral & operator+=( Tp rhs ) { _val += rhs; return *this; }
72 DefaultIntegral & operator-=( Tp rhs ) { _val -= rhs; return *this; }
73 DefaultIntegral & operator*=( Tp rhs ) { _val *= rhs; return *this; }
74 DefaultIntegral & operator/=( Tp rhs ) { _val /= rhs; return *this; }
75
76 DefaultIntegral & operator++(/*prefix*/) { ++_val; return *this; }
77 DefaultIntegral & operator--(/*prefix*/) { --_val; return *this; }
78
79 DefaultIntegral operator++(int/*postfix*/) { return _val++; }
80 DefaultIntegral operator--(int/*postfix*/) { return _val--; }
82
83 private:
84 Tp _val;
85 };
86
88 typedef DefaultIntegral<bool,true> TrueBool;
89
91 typedef DefaultIntegral<bool,false> FalseBool;
92
94 template<typename TIntegral>
95 using ZeroInit = DefaultIntegral<TIntegral,TIntegral(0)>;
96
97 template<class Tp, Tp TInitial>
98 std::string asString( const DefaultIntegral<Tp,TInitial> & obj )
99 { return asString( obj.get() ); }
100
102} // namespace zypp
104#endif // ZYPP_CORE_BASE_DEFAULTINTEGRAL_H
zypp::DefaultIntegral
Integral type with defined initial value when default constructed.
Definition defaultintegral.h:42
zypp::DefaultIntegral::operator++
DefaultIntegral & operator++()
Definition defaultintegral.h:76
zypp::DefaultIntegral::operator=
DefaultIntegral & operator=(Tp rhs)
Definition defaultintegral.h:70
zypp::DefaultIntegral::get
Tp get() const
Definition defaultintegral.h:54
zypp::DefaultIntegral::operator+=
DefaultIntegral & operator+=(Tp rhs)
Definition defaultintegral.h:71
zypp::DefaultIntegral::operator--
DefaultIntegral & operator--()
Definition defaultintegral.h:77
zypp::DefaultIntegral< unsigned int, 0 >::_val
unsigned int _val
Definition defaultintegral.h:84
zypp::DefaultIntegral::operator--
DefaultIntegral operator--(int)
Definition defaultintegral.h:80
zypp::DefaultIntegral::initial
constexpr Tp initial() const
The initial value.
Definition defaultintegral.h:61
zypp::DefaultIntegral< unsigned int, 0 >::value_type
unsigned int value_type
Definition defaultintegral.h:44
zypp::DefaultIntegral::operator-=
DefaultIntegral & operator-=(Tp rhs)
Definition defaultintegral.h:72
zypp::DefaultIntegral::DefaultIntegral
DefaultIntegral(Tp val_r=TInitial)
Definition defaultintegral.h:47
zypp::DefaultIntegral::operator/=
DefaultIntegral & operator/=(Tp rhs)
Definition defaultintegral.h:74
zypp::DefaultIntegral::operator*=
DefaultIntegral & operator*=(Tp rhs)
Definition defaultintegral.h:73
zypp::DefaultIntegral::reset
DefaultIntegral & reset()
Reset to the defined initial value.
Definition defaultintegral.h:64
zypp::DefaultIntegral::get
Tp & get()
Conversion to Tp.
Definition defaultintegral.h:53
zypp::DefaultIntegral::operator++
DefaultIntegral operator++(int)
Definition defaultintegral.h:79
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::FalseBool
DefaultIntegral< bool, false > FalseBool
relates: DefaultIntegral false initialized bool
Definition defaultintegral.h:91
zypp::asString
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition Patch.cc:122
zypp::TrueBool
DefaultIntegral< bool, true > TrueBool
relates: DefaultIntegral true initialized bool
Definition defaultintegral.h:88
zypp::ZeroInit
DefaultIntegral< TIntegral, TIntegral(0)> ZeroInit
relates: DefaultIntegral zero initialized integral
Definition defaultintegral.h:95