csutil/weakrefarr.h
Go to the documentation of this file.00001 /* 00002 Crystal Space Weak Reference array 00003 Copyright (C) 2004 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_WEAKREFARR_H__ 00021 #define __CS_WEAKREFARR_H__ 00022 00027 //----------------------------------------------------------------------------- 00028 // Note *1*: The explicit "this->" is needed by modern compilers (such as gcc 00029 // 3.4.x) which distinguish between dependent and non-dependent names in 00030 // templates. See: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html 00031 //----------------------------------------------------------------------------- 00032 00033 #include "csextern.h" 00034 #include "csutil/array.h" 00035 #include "csutil/weakref.h" 00036 00040 template <class T, 00041 class Allocator = CS::Memory::AllocatorMalloc, 00042 class CapacityHandler = CS::Container::ArrayCapacityDefault> 00043 class csWeakRefArray : 00044 public csSafeCopyArray<csWeakRef<T>, Allocator, CapacityHandler> 00045 { 00046 public: 00051 csWeakRefArray (int ilimit = 0, 00052 const CapacityHandler& ch = CapacityHandler()) 00053 : csSafeCopyArray<csWeakRef<T>, Allocator, CapacityHandler> (ilimit, ch) 00054 { 00055 } 00056 00061 void Compact () 00062 { 00063 size_t i = this->GetSize (); // see *1* 00064 while (i > 0) 00065 { 00066 i--; 00067 if (this->Get (i) == 0) // see *1* 00068 this->DeleteIndex (i); 00069 } 00070 } 00071 }; 00072 00073 #endif // __CS_WEAKREFARR_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1