KeosSmartPtrPolicies.h

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
00019  *
00020  */
00021 
00022 #ifndef KEOS_SMARTPTRPOLICIES_H
00023 #define KEOS_SMARTPTRPOLICIES_H
00024 
00025 #include "KeosPrerequisites.h"
00026 
00027 namespace Keos
00028 {
00029   //-----------------------------------------------------------------------
00033   template <class T>
00034   class CRefCount
00035   {
00036   public :
00037 
00041     CRefCount() : m_pCounter(new int(1))
00042     {}
00043 
00047     T* Clone(T* Ptr)
00048     {
00049       ++*m_pCounter;
00050       return Ptr;
00051     }
00052 
00056     void Release(T* pPtr)
00057     {
00058       if (--*m_pCounter == 0)
00059       {
00060         delete m_pCounter;
00061         delete pPtr;
00062       }
00063     }
00064 
00068     void Swap(CRefCount& RefCount)
00069     {
00070       std::swap(RefCount.m_pCounter, m_pCounter);
00071     }
00072 
00073   private :
00074 
00076     int* m_pCounter;
00077   };
00078 
00079 
00080   //-----------------------------------------------------------------------
00084   template <class T>
00085   class CCOMRefCounted
00086   {
00087   public :
00088 
00092     static T* Clone(T* pPtr)
00093     {
00094       if (pPtr)
00095         pPtr->AddRef();
00096       return pPtr;
00097     }
00098 
00102     static void Release(T* pPtr)
00103     {
00104       if (pPtr)
00105         pPtr->Release();
00106     }
00107 
00111     static void Swap(CCOMRefCounted&)
00112   {}
00113   };
00114 
00115 }
00116 ; // namespace Keos
00117 
00118 #endif // KEOS_SMARTPTRPOLICIES_H

Generated on Fri Mar 9 14:29:03 2007 for Keos by  doxygen 1.5.1-p1