MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
GelFactory.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #if !defined(MGINCLUDEGUARD_GELFACTORY__)
6 #define MGINCLUDEGUARD_GELFACTORY__
7 #include <map>
8 #include "mg/MGCL.h"
9 
10 class MGGel;
11 
14 {
17  virtual MGGel* create_gel() const = 0;
18 };
19 
21 template <typename T>
23 {
25  virtual T* create_gel() const
26  {
27  return new T;
28  }
29 };
30 
32 
40 class MG_DLL_DECLR MGGelFactoryRegistry
41 {
42 public:
43  typedef long KeyType;
44  typedef std::map<KeyType, MGGelFactoryBase*> TypeMap;
45 
50 
55  static MGGelFactoryRegistry* get_instance();
56 
60  static bool is_valid();
61 
67  MGGel* create_gel(const KeyType& name) const;
68 
73  void register_factory(
74  const KeyType& name,
75  MGGelFactoryBase* factory);
76 
81  void unregister_factory(const KeyType& name);
82 
87  void unregister_factory(MGGelFactoryBase* factory);
88 
89 private:
92 
94  MGGelFactoryRegistry& operator=(const MGGelFactoryRegistry& other);
95 
96  TypeMap m_map;
97 };
98 
99 
101 
102 template <typename T>
104 {
105  MGGelFactoryRegistry* m_pRegistry;
106  MGGelFactoryT<T> m_factory;
107 
108 public:
112  : m_pRegistry(MGGelFactoryRegistry::get_instance())
113  {
114  m_pRegistry->register_factory(name, &m_factory);
115  }
116 
119  {
121  m_pRegistry->unregister_factory(&m_factory);
122  }
123  }
124 };
125 
127 #define GEL_REG_JOIN( s1, s2 ) GEL_REG_JOIN__( s1, s2 )
128 #define GEL_REG_JOIN__( s1, s2 ) s1##s2
130 #define GEL_REG_MAKE_UNIQUE_NAME( prefix ) GEL_REG_JOIN( prefix, __LINE__ )
132 
146 #define AUTO_GEL_REGISTER(classname, gelname) \
147  static MGAutoGelRegister<classname> \
148  GEL_REG_MAKE_UNIQUE_NAME( glreg__ ) (gelname);
149 
150 #endif // defined(MGINCLUDEGUARD_GELFACTORY__)
ファクトリーレジストリーにエントリーする便利クラス.
Definition: GelFactory.h:103
virtual MGGel * create_gel() const =0
Factory Method 用のインターフェイス(MGGelFactoryTのために定義).
Definition: GelFactory.h:13
MGGel is an abstract class which represents a group element.
Definition: Gel.h:53
オブジェクトファクトリークラス用テンプレートクラス.
Definition: GelFactory.h:22
void unregister_factory(const KeyType &name)
std::map< KeyType, MGGelFactoryBase * > TypeMap
Definition: GelFactory.h:44
void register_factory(const KeyType &name, MGGelFactoryBase *factory)
MGAutoGelRegister(const MGGelFactoryRegistry::KeyType &name)
T オブジェクトのためのファクトリー
Definition: GelFactory.h:111
オブジェクトファクトリークラス.
Definition: GelFactory.h:40
long KeyType
Definition: GelFactory.h:43
~MGAutoGelRegister()
デストラクター
Definition: GelFactory.h:118
static bool is_valid()
virtual T * create_gel() const
Definition: GelFactory.h:25