Alternate e697dbe9c5997e35395fe158628dd8c5209481da
for Visual Studio 2022 and Windows 11.
読み取り中…
検索中…
一致する文字列を見つけられません
DesignPattern.hpp
[詳解]
1
5
6#pragma once
7
8#include "framework.h"
9#include "pch.h"
10
11namespace alt
12{
13 namespace skeleton
14 {
18 template <class T>
20 {
21 public:
24 virtual T get () = 0;
25 };
26
30 template <class T>
32 {
33 public:
36 virtual void accept (T t) = 0;
37 };
38
42 template <class T>
44 {
45 public:
51 virtual bool test (T t) = 0;
52 };
53
57 template <class T, class V>
59 {
60 public:
64 virtual V apply (T t) = 0;
65 };
66
70 template<typename Data>
72 {
73 public:
76 virtual void Update (Data data) = 0;
77 };
78
82 template<typename Data>
84 {
85 public:
88 virtual void Notify (Data data)
89 {
90 for (IObserver<Data>* observer : _observers)
91 {
92 observer->Update (data);
93 }
94 }
95
98 virtual void Add (IObserver<Data>* observer)
99 {
100 _observers.push_back (observer);
101 }
102
105 virtual void Remove (IObserver<Data>* observer)
106 {
107 for (auto item : _observers)
108 {
109 if (item == observer)
110 {
112 }
113 }
114 }
115
116 private:
118 std::vector<IObserver<Data>*> _observers;
119 };
120
124 template<class T, class V>
126 {
127 public:
129 Strategy () {};
130
132 virtual ~Strategy () {};
133
138 virtual V Get (T t)
139 {
140 return _strategy[t];
141 };
142
146 virtual void Set (T t, V v)
147 {
148 _strategy.insert (std::make_pair (t, v));
149 };
150
151 private:
153 std::map<T, V> _strategy;
154 };
155
159 template<class T>
161 {
162 public:
165 static T* Instance ()
166 {
167 if (_instance == nullptr)
168 {
169 _instance = new T ();
170 }
171
172 return _instance;
173 };
174
175 private:
178
180 static T* _instance;
181 };
182
186 template<typename CommandFunction>
188 {
189 public:
191 {
192 _function = nullptr;
193 _waitTime = 0;
194 };
195
196 void SetFunction (CommandFunction function) { _function = function; };
197 virtual bool Execute (size_t count, size_t total) { return _function (count, total); };
198 long GetWaitTime () { return _waitTime; };
199 void SetWaitTime (long time) { _waitTime = time; };
200
201 private:
202 CommandFunction _function;
204 };
205
209 template<typename CommandFunction>
211 {
212 public:
213 void Add (Command<CommandFunction>* command) { _commands.push_back (command); };
214 bool Execute ()
215 {
216 int ret = 0;
217 size_t count = 0;
218 const size_t total = _commands.size ();
219
220 for (auto command : _commands)
221 {
222 ret = command->Execute (++count, total);
223 if (ret == false) break;
224
225 long waitTime = command->GetWaitTime ();
226 Sleep (waitTime);
227 }
228
229 return ret;
230 };
231
232 private:
233 std::vector<Command<CommandFunction>*> _commands;
234 };
235
240 {
241 public:
242 std::wstring GetName () { return _leafName; };
243
244 void SetName (std::wstring& name) { _leafName = name; };
245
246 void Add (std::wstring key, std::wstring value)
247 {
248 _properties.insert (std::make_pair<std::wstring&, std::wstring&> (key, value));
249 }
250
251 std::wstring Get (std::wstring key) { return _properties[key]; };
252
253 private:
254 std::wstring _leafName;
255 std::map<std::wstring, std::wstring> _properties;
256 };
257
262 {
263 public:
264 std::wstring GetName () { return _nodeName; };
265
266 void SetName (std::wstring name) { _nodeName = name; };
267
268 void Add (std::wstring key, CompositeNode& node)
269 {
270 _nodes.insert (std::make_pair<std::wstring&, CompositeNode&> (key, node));
271 };
272
273 CompositeNode& GetNode (std::wstring key) { return _nodes[key]; };
274
275 std::vector<std::wstring> GetNodeKeys ()
276 {
277 std::vector<std::wstring> response;
278
279 for (auto itr = _nodes.begin (); itr != _nodes.end (); ++itr)
280 {
281 response.push_back (itr->first);
282 }
283
284 return response;
285 };
286
287 std::vector<CompositeNode> GetNodeValues ()
288 {
289 std::vector<CompositeNode> response;
290
291 for (auto itr = _nodes.begin (); itr != _nodes.end (); ++itr)
292 {
293 response.push_back (itr->second);
294 }
295
296 return response;
297 }
298
299 void Add (std::wstring key, CompositeLeaf& leaf)
300 {
301 _leafs.insert (std::make_pair<std::wstring&, CompositeLeaf&> (key, leaf));
302 };
303
304 CompositeLeaf& GetLeaf (std::wstring key) { return _leafs[key]; };
305
306 std::vector<std::wstring> GetLeafKeys ()
307 {
308 std::vector<std::wstring> response;
309
310 for (auto itr = _leafs.begin (); itr != _leafs.end (); ++itr)
311 {
312 response.push_back (itr->first);
313 }
314
315 return response;
316 };
317
318 std::vector<CompositeLeaf> GetLeafValues ()
319 {
320 std::vector<CompositeLeaf> response;
321
322 for (auto itr = _leafs.begin (); itr != _leafs.end (); ++itr)
323 {
324 response.push_back (itr->second);
325 }
326
327 return response;
328 }
329
330 private:
331 std::wstring _nodeName;
332 std::map<std::wstring, CompositeNode>_nodes;
333 std::map<std::wstring, CompositeLeaf> _leafs;
334 };
335 }
336}
このプロジェクトのポーティングに関する情報
プリコンパイル済みヘッダー ファイルです。
コマンド テンプレート
virtual bool Execute(size_t count, size_t total)
void SetWaitTime(long time)
void SetFunction(CommandFunction function)
CommandFunction _function
コマンド テンプレート
std::vector< Command< CommandFunction > * > _commands
void Add(Command< CommandFunction > *command)
コンポジット テンプレート
std::map< std::wstring, std::wstring > _properties
void SetName(std::wstring &name)
std::wstring Get(std::wstring key)
void Add(std::wstring key, std::wstring value)
コンポジット テンプレート
CompositeLeaf & GetLeaf(std::wstring key)
std::vector< std::wstring > GetNodeKeys()
void Add(std::wstring key, CompositeNode &node)
std::map< std::wstring, CompositeNode > _nodes
void Add(std::wstring key, CompositeLeaf &leaf)
std::vector< CompositeNode > GetNodeValues()
CompositeNode & GetNode(std::wstring key)
std::map< std::wstring, CompositeLeaf > _leafs
void SetName(std::wstring name)
std::vector< std::wstring > GetLeafKeys()
std::vector< CompositeLeaf > GetLeafValues()
IConsumerインターフェースクラス
virtual void accept(T t)=0
Tを引数とする関数 accept()
IFunctionインターフェースクラス
virtual V apply(T t)=0
Tを引数とする関数 apply()
IObserverインターフェースクラス
virtual void Update(Data data)=0
Dataを引数とする関数 Update()
IPredicateインターフェースクラス
virtual bool test(T t)=0
Tを引数とする関数 test()
ISubscriberインターフェースクラス
virtual void Remove(IObserver< Data > *observer)
IObserver<Data>*を引数とする関数 Remove()
virtual void Add(IObserver< Data > *observer)
IObserver<Data>*を引数とする関数 Add()
std::vector< IObserver< Data > * > _observers
Subscriberが管理するObserverの保存用
virtual void Notify(Data data)
Dataを引数とする関数 Notify()
ISupplierインターフェースクラス
virtual T get()=0
Tを返す関数 get()
シングルトン テンプレート
Singleton()
コンストラクタ(privateで秘匿状態)
static T * Instance()
唯一となるインスタンスを取得します。
static T * _instance
唯一となるインスタンスを管理する変数
virtual void Set(T t, V v)
テンプレートTをキーとしたテンプレートVを設定します。
Strategy()
コンストラクタ
std::map< T, V > _strategy
Set()で登録されたオブジェクトを管理するマップ
virtual V Get(T t)
テンプレート引数Tに応じて、テンプレートVを返却します。
virtual ~Strategy()
デストラクタ
Definition: DBLibrary.h:12