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 <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_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,
00046           class ElementHandler = csArrayElementHandler<T>,
00047           class MemoryAllocator = CS::Memory::AllocatorMalloc,
00048           class CapacityHandler = csArrayCapacityDefault>
00049 class csDirtyAccessArray : 
00050   public csArray<T, ElementHandler, MemoryAllocator, CapacityHandler>
00051 {
00052 public:
00059   csDirtyAccessArray (size_t in_capacity = 0,
00060     const CapacityHandler& ch = CapacityHandler())
00061     : csArray<T, ElementHandler, MemoryAllocator, CapacityHandler> (
00062       in_capacity, ch) {}
00063 
00065   T* GetArray ()
00066   {
00067     if (this->GetSize () > 0) // see *1*
00068       return &this->Get (0);
00069     else
00070       return 0;
00071   }
00072 
00074   const T* GetArray () const
00075   {
00076     if (this->GetSize () > 0) // see *1*
00077       return &this->Get (0);
00078     else
00079       return 0;
00080   }
00081 
00087   T* GetArrayCopy ()
00088   {
00089     if (this->Length () > 0) // see *1*
00090     {
00091       T* copy = new T [this->GetSize ()];
00092       memcpy (copy, &this->Get (0), sizeof (T) * this->GetSize ());
00093       return copy;
00094     }
00095     else
00096       return 0;
00097   }
00098 };
00099 
00105 template <class T, class ElementHandler = csArrayElementHandler<T> >
00106 class csDirtyAccessArrayRefCounted : 
00107   public csDirtyAccessArray<T, ElementHandler>
00108 {
00109 private:
00110   int RefCount;
00111 public:
00112   csDirtyAccessArrayRefCounted (int ilimit = 0, int ithreshold = 0) : 
00113     csDirtyAccessArray<T, ElementHandler> (ilimit, ithreshold), RefCount (0)
00114   { }
00115 
00117   void IncRef () { RefCount++; }
00118 
00120   void DecRef ()
00121   {
00122     if (RefCount == 1) { this->DeleteAll (); } // see *1*
00123     RefCount--;
00124   }
00125 
00126 };
00127 
00128 
00129 #endif // __CS_DIRTYACCESSARRAY_H__

Generated for Crystal Space 1.2.1 by doxygen 1.5.3