libzypp  10.5.0
ProvideNumericId.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_BASE_PROVIDENUMERICID_H
00013 #define ZYPP_BASE_PROVIDENUMERICID_H
00014 
00016 namespace zypp
00017 { 
00018 
00019   namespace base
00020   { 
00021 
00023     //
00024     //  CLASS NAME : ProvideNumericId
00025     //
00044     template<class _Derived, class _NumericIdType>
00045       struct ProvideNumericId
00046       {
00047       public:
00049         _NumericIdType numericId() const
00050         { return _numericId; }
00051 
00052       protected:
00054         ProvideNumericId()
00055         : _numericId( nextId() )
00056         {}
00058         ProvideNumericId( const ProvideNumericId & /*rhs*/ )
00059         : _numericId( nextId() )
00060         {}
00062         ProvideNumericId & operator=( const ProvideNumericId & /*rhs*/ )
00063         { return *this; }
00065         ~ProvideNumericId()
00066         {}
00067       protected:
00071         ProvideNumericId( const void *const )
00072         : _numericId( 0 )
00073         {}
00074       private:
00076         static _NumericIdType nextId()
00077         {
00078           static _NumericIdType _staticCounter = 0;
00079           // Assert not returning 0
00080           return ++_staticCounter;
00081         }
00083         const _NumericIdType _numericId;
00084       };
00086 
00088   } // namespace base
00091 } // namespace zypp
00093 #endif // ZYPP_BASE_PROVIDENUMERICID_H