ICF 3.1.1.10
Technical documentation of ICF Libraries
TOptPointerVector.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// ICF includes
10#include <istd/TPointerVector.h>
11
12
13namespace istd
14{
15
16
20template<typename Pointer>
22{
23public:
25 {
26 Pointer* pointer;
28 };
29
30 static Pointer* GetPtr(const ElementType& element)
31 {
32 return element.pointer;
33 }
34
35 static Pointer* release(const ElementType& element)
36 {
37 return GetPtr(element);
38 }
39
40 static void Delete(const ElementType& element)
41 {
42 if (element.releaseFlag){
43 delete element.pointer;
44 }
45 }
46};
47
48
53template <typename Pointer>
54class TOptPointerVector: public TPointerVector<Pointer, TOptDeleteAdapter<Pointer> >
55{
56public:
58
59 void SetAt(int index, Pointer* pointer, bool releaseFlag = false);
60 void PushBack(Pointer* pointer, bool releaseFlag = false);
61 void InsertAt(int index, Pointer* pointer, bool releaseFlag = false);
62};
63
64
65// public methods
66
67template <typename Pointer>
68void TOptPointerVector<Pointer>::SetAt(int index, Pointer* pointer, bool releaseFlag)
69{
71 element.pointer = pointer;
72 element.releaseFlag = releaseFlag;
73
74 BaseClass::SetElementAt(index, element);
75}
76
77
78template <typename Pointer>
79void TOptPointerVector<Pointer>::PushBack(Pointer* pointer, bool releaseFlag)
80{
82 element.pointer = pointer;
83 element.releaseFlag = releaseFlag;
84
85 BaseClass::PushBack(element);
86}
87
88
89template <typename Pointer>
90void TOptPointerVector<Pointer>::InsertAt(int index, Pointer* pointer, bool releaseFlag)
91{
93 element.pointer = pointer;
94 element.releaseFlag = releaseFlag;
95
96 BaseClass::InsertElementAt(index, element);
97}
98
99
100} // namespace istd
101
102
Optional delete adapter.
static void Delete(const ElementType &element)
static Pointer * release(const ElementType &element)
static Pointer * GetPtr(const ElementType &element)
Implementation of a special pointer container, which controls the live cycle of the pointer object,...
void InsertAt(int index, Pointer *pointer, bool releaseFlag=false)
void SetAt(int index, Pointer *pointer, bool releaseFlag=false)
TPointerVector< Pointer, TOptDeleteAdapter< Pointer > > BaseClass
void PushBack(Pointer *pointer, bool releaseFlag=false)
Implementation of a pointer container, which controls the live cycle of the pointer object.
Standard library.
Definition IComponent.h:17

© Witold Gantzke and Kirill Lepskiy