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

libzypp 17.38.6

providenumericid.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_CORE_BASE_PROVIDENUMERICID_H
13#define ZYPP_CORE_BASE_PROVIDENUMERICID_H
14
16namespace zypp
17{
19 namespace base
20 {
21
23 //
24 // CLASS NAME : ProvideNumericId
25 //
44 template<class TDerived, class TNumericIdType>
45 struct ProvideNumericId
46 {
47 public:
49 TNumericIdType numericId() const
50 { return _numericId; }
51
52 protected:
54 ProvideNumericId()
55 : _numericId( nextId() )
56 {}
57
58 ProvideNumericId( const ProvideNumericId & /*rhs*/ )
59 : _numericId( nextId() )
60 {}
61
62 ProvideNumericId & operator=( const ProvideNumericId & /*rhs*/ )
63 { return *this; }
64
65 ProvideNumericId( ProvideNumericId && rhs ) noexcept
66 : _numericId( rhs._numericId )
67 { /*rhs._numericId = 0;*/ }
68
69 ProvideNumericId & operator=( ProvideNumericId && rhs ) noexcept
70 { if ( &rhs != this ) { _numericId = rhs._numericId; /*rhs._numericId = 0;*/ } return *this; }
71
72 ~ProvideNumericId()
73 {}
74 protected:
78 ProvideNumericId( const void *const )
79 : _numericId( 0 )
80 {}
81 private:
83 static TNumericIdType nextId()
84 {
85 static TNumericIdType _staticCounter = 0;
86 // Assert not returning 0
87 return ++_staticCounter;
88 }
89
90 const TNumericIdType _numericId;
91 };
92
93
95 } // namespace base
98} // namespace zypp
100#endif // ZYPP_CORE_BASE_PROVIDENUMERICID_H
zypp::base
Definition Random.cc:7
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::base::ProvideNumericId::_numericId
const TNumericIdType _numericId
Definition providenumericid.h:90
zypp::base::ProvideNumericId::nextId
static TNumericIdType nextId()
Provide the next Id to use.
Definition providenumericid.h:83
zypp::base::ProvideNumericId::~ProvideNumericId
~ProvideNumericId()
Dtor.
Definition providenumericid.h:72
zypp::base::ProvideNumericId::ProvideNumericId
ProvideNumericId(const void *const)
No-Id ctor (0).
Definition providenumericid.h:78
zypp::base::ProvideNumericId::operator=
ProvideNumericId & operator=(ProvideNumericId &&rhs) noexcept
Move Assign.
Definition providenumericid.h:69
zypp::base::ProvideNumericId::numericId
TNumericIdType numericId() const
Definition providenumericid.h:49
zypp::base::ProvideNumericId::ProvideNumericId
ProvideNumericId(const ProvideNumericId &)
Copy ctor.
Definition providenumericid.h:58
zypp::base::ProvideNumericId::ProvideNumericId
ProvideNumericId(ProvideNumericId &&rhs) noexcept
Move ctor.
Definition providenumericid.h:65
zypp::base::ProvideNumericId::ProvideNumericId
ProvideNumericId()
Default ctor.
Definition providenumericid.h:54
zypp::base::ProvideNumericId::operator=
ProvideNumericId & operator=(const ProvideNumericId &)
Assign.
Definition providenumericid.h:62