1 /*=========================================================================
4 Module: $RCSfile: gdcmRefCounter.h,v $
6 Date: $Date: 2007/10/04 17:50:42 $
7 Version: $Revision: 1.13 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #ifndef _GDCMREFCOUNTER_H_
20 #define _GDCMREFCOUNTER_H_
23 //#include "gdcmDebug.h"
26 namespace GDCM_NAME_SPACE
28 //-----------------------------------------------------------------------------
30 * \brief Integration of reference counting with a destruction of the
31 * object only when the reference is to zero
33 class GDCM_EXPORT RefCounter : public Base
35 gdcmTypeMacro(RefCounter);
38 // Allocator / Unallocator
39 /// \brief Delete the object
40 /// \remarks The object is deleted only if its reference counting is to zero
41 void Delete() { Unregister(); }
44 /// \brief Register the object
45 /// \remarks It increments the reference counting
46 void Register() { RefCount++; }
48 /// \brief Unregister the object
49 /// \remarks It decrements the reference counting
52 //std::cout <<"================Unreg " << typeid(*this).name() << std::endl;
57 /// \brief Get the reference counting
58 /// \return Reference count
59 const unsigned long &GetRefCount() const
66 RefCounter() : RefCount(1) { }
68 virtual ~RefCounter() {}
71 /// \brief Reference count
72 unsigned long RefCount;
74 } // end namespace gdcm
76 //-----------------------------------------------------------------------------