csutil/refarr.h
00001 /* 00002 Crystal Space Smart Pointers 00003 Copyright (C) 2002 by Jorrit Tyberghein and Matthias Braun 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_REFARR_H__ 00021 #define __CS_REFARR_H__ 00022 00023 #include "ref.h" 00024 #include "array.h" 00025 00026 template <class T> 00027 class csRefArrayElementHandler 00028 { 00029 public: 00030 static void Construct (T* address, T const& src) 00031 { 00032 *address = src; 00033 if (src) src->IncRef (); 00034 } 00035 00036 static void Destroy (T* address) 00037 { 00038 if (*address) (*address)->DecRef (); 00039 } 00040 00041 static void InitRegion (T* address, int count) 00042 { 00043 memset (address, 0, count*sizeof (T)); 00044 } 00045 }; 00046 00050 template <class T> 00051 class csRefArray : public csArray<T*, csRefArrayElementHandler<T*> > 00052 { 00053 public: 00058 csRefArray (int ilimit = 0, int ithreshold = 0) 00059 : csArray<T*, csRefArrayElementHandler<T*> > (ilimit, ithreshold) 00060 { 00061 } 00062 00064 csPtr<T> Pop () 00065 { 00066 CS_ASSERT (Length () > 0); 00067 csRef<T> ret = Get (Length () - 1); 00068 SetLength (Length () - 1); 00069 return csPtr<T> (ret); 00070 } 00071 00072 }; 00073 00074 #endif // __CS_REFARR_H__ 00075
Generated for Crystal Space by doxygen 1.2.18