Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_DIRTYACCESSARRAY_H__
00021 #define __CS_DIRTYACCESSARRAY_H__
00022
00028
00029
00030
00031
00032
00033
00034 #include "array.h"
00035
00045 template <class T,
00046 class ElementHandler = csArrayElementHandler<T>,
00047 class MemoryAllocator = CS::Container::ArrayAllocDefault,
00048 class CapacityHandler = CS::Container::ArrayCapacityDefault>
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)
00068 return &this->Get (0);
00069 else
00070 return 0;
00071 }
00072
00074 const T* GetArray () const
00075 {
00076 if (this->GetSize () > 0)
00077 return &this->Get (0);
00078 else
00079 return 0;
00080 }
00081
00087 T* GetArrayCopy ()
00088 {
00089 if (this->GetSize () > 0)
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
00105 T* Detach ()
00106 {
00107 T* ptr = GetArray ();
00108 this->SetDataVeryUnsafe (nullptr);
00109 this->SetSizeVeryUnsafe (0);
00110 this->SetCapacityVeryUnsafe (0);
00111 return ptr;
00112 }
00113 };
00114
00120 template <class T, class ElementHandler = csArrayElementHandler<T>,
00121 class MemoryAllocator = CS::Container::ArrayAllocDefault,
00122 class CapacityHandler = CS::Container::ArrayCapacityDefault>
00123 class csDirtyAccessArrayRefCounted :
00124 public csDirtyAccessArray<T, ElementHandler, MemoryAllocator,
00125 CapacityHandler>
00126 {
00127 private:
00128 int RefCount;
00129 public:
00130 csDirtyAccessArrayRefCounted (int ilimit = 0,
00131 const CapacityHandler& ch = CapacityHandler())
00132 : csDirtyAccessArray<T, ElementHandler, MemoryAllocator,
00133 CapacityHandler> (ilimit, ch), RefCount (0)
00134 { }
00135
00137 void IncRef () { RefCount++; }
00138
00140 void DecRef ()
00141 {
00142 if (RefCount == 1) { this->DeleteAll (); }
00143 RefCount--;
00144 }
00145
00146 };
00147
00148
00149 #endif // __CS_DIRTYACCESSARRAY_H__