TOptPointerVector.h
Go to the documentation of this file.
1 #ifndef istd_TOptPointerVector_included
2 #define istd_TOptPointerVector_included
3 
4 
5 // ACF includes
6 #include <istd/TPointerVector.h>
7 
8 
9 namespace istd
10 {
11 
12 
16 template<typename Pointer>
18 {
19 public:
20  struct ElementType
21  {
22  Pointer* pointer;
24  };
25 
26  static Pointer* GetPtr(const ElementType& element)
27  {
28  return element.pointer;
29  }
30 
31  static Pointer* PopPtr(const ElementType& element)
32  {
33  return GetPtr(element);
34  }
35 
36  static void Delete(const ElementType& element)
37  {
38  if (element.releaseFlag){
39  delete element.pointer;
40  }
41  }
42 };
43 
44 
49 template <typename Pointer>
50 class TOptPointerVector: public TPointerVector<Pointer, TOptDeleteAdapter<Pointer> >
51 {
52 public:
54 
55  void SetAt(int index, Pointer* pointer, bool releaseFlag = false);
56  void PushBack(Pointer* pointer, bool releaseFlag = false);
57  void InsertAt(int index, Pointer* pointer, bool releaseFlag = false);
58 };
59 
60 
61 // public methods
62 
63 template <typename Pointer>
64 void TOptPointerVector<Pointer>::SetAt(int index, Pointer* pointer, bool releaseFlag)
65 {
67  element.pointer = pointer;
68  element.releaseFlag = releaseFlag;
69 
70  BaseClass::SetElementAt(index, element);
71 }
72 
73 
74 template <typename Pointer>
75 void TOptPointerVector<Pointer>::PushBack(Pointer* pointer, bool releaseFlag)
76 {
78  element.pointer = pointer;
79  element.releaseFlag = releaseFlag;
80 
81  BaseClass::PushBack(element);
82 }
83 
84 
85 template <typename Pointer>
86 void TOptPointerVector<Pointer>::InsertAt(int index, Pointer* pointer, bool releaseFlag)
87 {
89  element.pointer = pointer;
90  element.releaseFlag = releaseFlag;
91 
92  BaseClass::InsertElementAt(index, element);
93 }
94 
95 
96 } // namespace istd
97 
98 
99 #endif // !istd_TOptPointerVector_included
100 
static Pointer * GetPtr(const ElementType &element)
void SetAt(int index, Pointer *pointer, bool releaseFlag=false)
void InsertAt(int index, Pointer *pointer, bool releaseFlag=false)
Implementation of a special pointer container, which controls the live cycle of the pointer object...
TPointerVector< Pointer, TOptDeleteAdapter< Pointer > > BaseClass
static Pointer * PopPtr(const ElementType &element)
Optional delete adapter.
Implementation of a pointer container, which controls the live cycle of the pointer object...
static void Delete(const ElementType &element)
void PushBack(Pointer *pointer, bool releaseFlag=false)

© 2007-2017 Witold Gantzke and Kirill Lepskiy