CrystalSpace

Public API Reference

csutil/dirtyaccessarray.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 <[email protected]>
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_DIRTYACCESSARRAY_H__
00021 #define __CS_DIRTYACCESSARRAY_H__
00022 
00028 //-----------------------------------------------------------------------------
00029 // Note *1*: The explicit "this->" is needed by modern compilers (such as gcc
00030 // 3.4.x) which distinguish between dependent and non-dependent names in
00031 // templates.  See: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
00032 //-----------------------------------------------------------------------------
00033 
00034 #include "array.h"
00035 
00045 template <class T, class ElementHandler = csArrayElementHandler<T> >
00046 class csDirtyAccessArray : public csArray<T, ElementHandler>
00047 {
00048 public:
00053   csDirtyAccessArray (int ilimit = 0, int ithreshold = 0)
00054         : csArray<T, ElementHandler> (ilimit, ithreshold) {}
00055 
00057   T* GetArray ()
00058   {
00059     if (this->Length () > 0) // see *1*
00060       return &this->Get (0);
00061     else
00062       return 0;
00063   }
00064 
00066   const T* GetArray () const
00067   {
00068     if (this->Length () > 0) // see *1*
00069       return &this->Get (0);
00070     else
00071       return 0;
00072   }
00073 
00079   T* GetArrayCopy ()
00080   {
00081     if (this->Length () > 0) // see *1*
00082     {
00083       T* copy = new T [this->Length ()];
00084       memcpy (copy, &this->Get (0), sizeof (T) * this->Length ());
00085       return copy;
00086     }
00087     else
00088       return 0;
00089   }
00090 };
00091 
00097 template <class T, class ElementHandler = csArrayElementHandler<T> >
00098 class csDirtyAccessArrayRefCounted : 
00099   public csDirtyAccessArray<T, ElementHandler>
00100 {
00101 private:
00102   int RefCount;
00103 public:
00104   csDirtyAccessArrayRefCounted (int ilimit = 0, int ithreshold = 0) : 
00105     csDirtyAccessArray<T, ElementHandler> (ilimit, ithreshold), RefCount (0)
00106   { }
00107 
00109   void IncRef () { RefCount++; }
00110 
00112   void DecRef ()
00113   {
00114     if (RefCount == 1) { this->DeleteAll (); } // see *1*
00115     RefCount--;
00116   }
00117 
00118 };
00119 
00120 
00121 #endif // __CS_DIRTYACCESSARRAY_H__

Generated for Crystal Space by doxygen 1.4.7