gatelib  2.1
g_cont_private_data_pointer.h
1 #pragma once
2 
3 #include "g_cont_common.h"
4 #include "g_cont_AllocationPolicyAbstract.h"
5 #include "g_cont_HeapAbstract.h"
6 
7 namespace g
8 {
9 namespace cont
10 {
11 namespace priv
12 {
13 
14 template <class T> class data_pointer
15 {
16 private:
17  data_pointer ( const data_pointer& ):mAllocPolicyP(NULL),mResizableDataMarkerP(NULL){}
18 public:
19  data_pointer ( AllocationPolicyAbstract* d_alloc_policy ) :
20  mResizableDataMarkerP(NULL),mAllocPolicyP(d_alloc_policy) { }
21 
22  ~data_pointer ( )
23  {
24  free ( );
25  }
26 
27  //HeapAbstract* getHeapP ( ) const { return mAllocPolicyP->getHeapP ( ); }
28  AllocationPolicyAbstract* getAllocPolicy ( ) const { return mAllocPolicyP; }
29 
30  void allocate ( size_t cardinality , size_t old_cardinality )
31  {
32  if ( cardinality != old_cardinality )
33  {
34  if ( mResizableDataMarkerP == NULL )
35  {
36  mResizableDataMarkerP = mAllocPolicyP->reserveResizableDataT<T>(cardinality);
37  }
38  else
39  {
40  mResizableDataMarkerP = mAllocPolicyP->resizeResizableDataT<T>(mResizableDataMarkerP,old_cardinality,cardinality );
41  }
42  }
43  }
44 
45  void free ( )
46  {
47  if ( mResizableDataMarkerP != NULL )
48  {
49  mAllocPolicyP->freeResizableData ( mResizableDataMarkerP );
50  mResizableDataMarkerP = NULL;
51  }
52  }
53 
54  inline operator T* ( ) { if( mResizableDataMarkerP ) { return reinterpret_cast<T*>(mAllocPolicyP->getResizableDataLocation ( mResizableDataMarkerP )); }else { return NULL; } }
55  inline operator const T* ( ) const { if( mResizableDataMarkerP ) { return reinterpret_cast<T*>(mAllocPolicyP->getResizableDataLocation ( mResizableDataMarkerP )); }else { return NULL; } }
56 
57 private:
58  MemMarker* mResizableDataMarkerP;
59  AllocationPolicyAbstract* mAllocPolicyP;
60 };
61 
62 
63 }//namespace priv
64 }//namespace cont
65 }//namespace g
66 
Definition: g_cont_AllocationPolicyAbstract.h:16
Definition: g.mthread.ThreadSimpleEvent.h:5
Definition: g_cont_AllocationPolicyAbstract.h:13
Definition: g_cont_private_data_pointer.h:14