csutil/refcount.h
00001 /* 00002 Crystal Space Reference Counting Interface 00003 Copyright (C) 2002 by Jorrit Tyberghein 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_REFCOUNT_H__ 00021 #define __CS_REFCOUNT_H__ 00022 00023 #include "csextern.h" 00024 00032 class csRefCount 00033 { 00034 protected: 00035 int ref_count; 00036 00037 // To avoid a problem with MSVC and multiple DLLs (with separate memory 00038 // space) we have to use a virtual destructor. 00039 // @@@ Another alternative is to force this function to be non-inline, as 00040 // doing so will most likely achieve the same result. 00041 virtual void Delete () 00042 { 00043 delete this; 00044 } 00045 00046 virtual ~csRefCount () {} 00047 00048 public: 00050 csRefCount () : ref_count (1) {} 00051 00053 void IncRef () { ref_count++; } 00055 void DecRef () 00056 { 00057 ref_count--; 00058 if (ref_count <= 0) 00059 Delete (); 00060 } 00062 int GetRefCount () const { return ref_count; } 00063 }; 00064 00065 #endif // __CS_REFCOUNT_H__ 00066
Generated for Crystal Space by doxygen 1.2.18