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 //----------------------------------------------------------------------------- 00024 // Note *1*: The explicit "this->" is needed by modern compilers (such as gcc 00025 // 3.4.x) which distinguish between dependent and non-dependent names in 00026 // templates. See: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html 00027 //----------------------------------------------------------------------------- 00028 00029 #include "array.h" 00030 00045 template <class T> 00046 class csDirtyAccessArray : public csArray<T> 00047 { 00048 private: 00049 int RefCount; 00050 00051 public: 00056 csDirtyAccessArray (int ilimit = 0, int ithreshold = 0) 00057 : csArray<T> (ilimit, ithreshold) 00058 { 00059 RefCount = 0; 00060 } 00061 00062 // Reference counting. 00063 void IncRef () { RefCount++; } 00064 00065 // Reference counting. Delete array when reference reaches 0. 00066 void DecRef () 00067 { 00068 if (RefCount == 1) { this->DeleteAll (); } // see *1* 00069 RefCount--; 00070 } 00071 00073 T* GetArray () 00074 { 00075 if (this->Length () > 0) // see *1* 00076 return &this->Get (0); 00077 else 00078 return 0; 00079 } 00080 00082 const T* GetArray () const 00083 { 00084 if (this->Length () > 0) // see *1* 00085 return &this->Get (0); 00086 else 00087 return 0; 00088 } 00089 00095 T* GetArrayCopy () 00096 { 00097 if (this->Length () > 0) // see *1* 00098 { 00099 T* copy = new T [this->Length ()]; 00100 memcpy (copy, &this->Get (0), sizeof (T) * this->Length ()); 00101 return copy; 00102 } 00103 else 00104 return 0; 00105 } 00106 }; 00107 00108 #endif // __CS_GARRAY_H__
Generated for Crystal Space by doxygen 1.2.18