00001 /*========================================================================= 00002 00003 Program: gdcm 00004 Module: $RCSfile: gdcmRefCounter.h,v $ 00005 Language: C++ 00006 Date: $Date: 2005/11/28 15:20:34 $ 00007 Version: $Revision: 1.9 $ 00008 00009 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00010 l'Image). All rights reserved. See Doc/License.txt or 00011 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. 00012 00013 This software is distributed WITHOUT ANY WARRANTY; without even 00014 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 PURPOSE. See the above copyright notices for more information. 00016 00017 =========================================================================*/ 00018 00019 #ifndef GDCMREFCOUNTER_H 00020 #define GDCMREFCOUNTER_H 00021 00022 #include "gdcmBase.h" 00023 00024 namespace gdcm 00025 { 00026 //----------------------------------------------------------------------------- 00031 class GDCM_EXPORT RefCounter : public Base 00032 { 00033 gdcmTypeMacro(RefCounter); 00034 00035 public: 00036 // Allocator / Unallocator 00039 void Delete() { Unregister(); } 00040 00041 // Reference count 00044 void Register() { RefCount++; } 00045 00048 void Unregister() 00049 { 00050 RefCount--; 00051 if(RefCount<=0) 00052 delete this; 00053 } 00056 const unsigned long &GetRefCount() const 00057 { 00058 return RefCount; 00059 } 00060 00061 protected: 00063 RefCounter() { RefCount = 1; } 00065 virtual ~RefCounter() {} 00066 00067 private: 00069 unsigned long RefCount; 00070 }; 00071 } // end namespace gdcm 00072 00073 //----------------------------------------------------------------------------- 00074 #endif