gdcmRefCounter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmRefCounter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/22 16:14:04 $
00007   Version:   $Revision: 1.12 $
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 //#include "gdcmDebug.h"
00024 #include <typeinfo>
00025 
00026 namespace GDCM_NAME_SPACE 
00027 {
00028 //-----------------------------------------------------------------------------
00033 class GDCM_EXPORT RefCounter : public Base
00034 {
00035    gdcmTypeMacro(RefCounter);
00036 
00037 public:
00038 // Allocator / Unallocator
00041    void Delete() { Unregister(); }
00042 
00043 // Reference count
00046    void Register() { RefCount++; }
00047 
00050    void Unregister()
00051    {
00052 //std::cout <<"================Unreg " << typeid(*this).name() << std::endl;
00053       RefCount--;
00054       if(RefCount<=0)
00055         delete this;
00056    }
00059    const unsigned long &GetRefCount() const
00060    {
00061       return RefCount;
00062    }
00063 
00064 protected:
00066    RefCounter() { RefCount = 1; }
00068    virtual ~RefCounter() {}
00069 
00070 private:
00072    unsigned long RefCount;
00073 };
00074 } // end namespace gdcm
00075 
00076 //-----------------------------------------------------------------------------
00077 #endif

Generated on Fri Aug 24 12:59:31 2007 for gdcm by  doxygen 1.4.6