-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLifecycle.h
More file actions
252 lines (203 loc) · 4.04 KB
/
Copy pathLifecycle.h
File metadata and controls
252 lines (203 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#ifndef BaseLib_Templates_Lifecycle_h_Included
#define BaseLib_Templates_Lifecycle_h_Included
namespace BaseLib { namespace Templates
{
/*
* IDEAS:
* - Automatically release this from parent when this goes out of scope. Use Finalize()
*
* this->Finalize() -> parent->Release(this);
*
* - use cache instead and observer pattern?
*
* this->Finalize() -> cache()->SetExpired(this) -> notify parent through OnObjectDeleted(this).
*/
// --------------------------------------------
// Lifecycle methods
// --------------------------------------------
/**
* @brief The InitMethod class
*/
class InitializeMethod
{
public:
virtual ~InitializeMethod() {}
virtual bool Initialize() = 0;
};
class IsInitializedMethod
{
public:
virtual ~IsInitializedMethod() {}
virtual bool IsInitialized() const = 0;
};
/**
* @brief The InitTypeMethod class
*/
template <typename T, typename Return = bool>
class InitTypeMethod
{
public:
virtual ~InitTypeMethod() {}
virtual Return Init(T&) = 0;
};
/**
* @brief The PassivateMethod class
*/
class PassivateMethod
{
public:
virtual ~PassivateMethod() {}
virtual bool Passivate() = 0;
};
class IsPassivatedMethod
{
public:
virtual ~IsPassivatedMethod() {}
virtual bool IsPassivated() = 0;
};
/**
* @brief The ActivateMethod class
*/
class ActivateMethod
{
public:
virtual ~ActivateMethod() {}
virtual bool Activate() = 0;
};
class IsActivatedMethod
{
public:
virtual ~IsActivatedMethod() {}
virtual bool IsActivated() const = 0;
};
class DeactivateMethod
{
public:
virtual ~DeactivateMethod() {}
virtual bool Deactivate() = 0;
};
/**
* @brief The ActivateMethod class
*/
class ActiveMethod
{
public:
virtual ~ActiveMethod() {}
virtual void Active() = 0;
};
class IsActiveMethod
{
public:
virtual ~IsActiveMethod() {}
virtual bool IsActive() const = 0;
};
/**
* @brief The ShutdownMethod class
*/
class ShutdownMethod
{
public:
virtual ~ShutdownMethod() {}
virtual bool Shutdown() = 0;
};
/**
* @brief The FinalizeMethod class
*/
class FinalizeMethod
{
public:
virtual ~FinalizeMethod() {}
virtual bool Finalize() = 0;
};
class IsFinalizedMethod
{
public:
virtual ~IsFinalizedMethod() {}
virtual bool IsFinalized() const = 0;
};
template <typename Return>
class RefreshMethod
{
public:
virtual ~RefreshMethod() {}
virtual Return Refresh() = 0;
};
class IsRefreshedMethod
{
public:
virtual ~IsRefreshedMethod() {}
virtual bool IsRefreshed() const = 0;
};
template <typename Return>
class ReloadMethod
{
public:
virtual ~ReloadMethod() {}
virtual Return Reload() = 0;
};
class IsReloadedMethod
{
public:
virtual ~IsReloadedMethod() {}
virtual bool IsReloaded() const = 0;
};
/**
* @brief The DisposeMethod class
*
* TODO: Alternative name: Destroy(), Delete(), Invalidate()
*/
class DisposeMethod
{
public:
virtual bool Dispose() = 0;
};
class IsDisposedMethod
{
public:
virtual bool IsDisposed() const = 0;
};
//template <typename T>
//class ObjectLifecycle : public FactoryMethod<T>
// , public InitMethod
// , public DisposeMethod
// , public PassivateMethod
// , public ActivateMethod
// , public FinalizeMethod
//{
//};
class InitializeMethods
: public InitializeMethod
, public IsInitializedMethod
{
public:
virtual ~InitializeMethods() {}
};
class FinalizeMethods
: public FinalizeMethod
, public IsFinalizedMethod
{
public:
virtual ~FinalizeMethods() {}
};
class ActivationMethods
: public Templates::IsActiveMethod
, public Templates::ActivateMethod
, public Templates::DeactivateMethod
{
public:
virtual ~ActivationMethods()
{ }
};
class ObjectLifecycle : public InitializeMethods
, public ActivationMethods
, public FinalizeMethods
//, public DisposeMethod
{ };
class Lifecycle : public ObjectLifecycle
{
public:
virtual ~Lifecycle()
{ }
};
}}
#endif