csutil/garray.h
Go to the documentation of this file.00001 /* 00002 Crystal Space utility library: vector class interface 00003 Copyright (C) 1998,1999,2000 by Andrew Zabolotny <bit@eltech.ru> 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_GARRAY_H__ 00021 #define __CS_GARRAY_H__ 00022 00023 #include "array.h" 00024 00039 template <class T> 00040 class csDirtyAccessArray : public csArray<T> 00041 { 00042 private: 00043 int RefCount; 00044 00045 public: 00050 csDirtyAccessArray (int ilimit = 0, int ithreshold = 0) 00051 : csArray<T> (ilimit, ithreshold) 00052 { 00053 RefCount = 0; 00054 } 00055 00056 // Reference counting. 00057 void IncRef () { RefCount++; } 00058 00059 // Reference counting. Delete array when reference reaches 0. 00060 void DecRef () 00061 { 00062 if (RefCount == 1) { DeleteAll (); } 00063 RefCount--; 00064 } 00065 00067 T* GetArray () 00068 { 00069 if (Length () > 0) 00070 return &Get (0); 00071 else 00072 return 0; 00073 } 00074 00076 const T* GetArray () const 00077 { 00078 if (Length () > 0) 00079 return &Get (0); 00080 else 00081 return 0; 00082 } 00083 00089 T* GetArrayCopy () 00090 { 00091 if (Length () > 0) 00092 { 00093 T* copy = new T [Length ()]; 00094 memcpy (copy, &Get (0), sizeof (T) * Length ()); 00095 return copy; 00096 } 00097 else 00098 return 0; 00099 } 00100 }; 00101 00102 #endif // __CS_GARRAY_H__ 00103
Generated for Crystal Space by doxygen 1.2.18