include/dynamic-graph/factory.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
3 // JRL, CNRS/AIST.
4 //
5 
6 #ifndef DYNAMIC_GRAPH_FACTORY_HH
7 #define DYNAMIC_GRAPH_FACTORY_HH
10 
11 #include <boost/noncopyable.hpp>
12 #include <dynamic-graph/fwd.hh>
13 #include <map>
14 #include <string>
15 #include <vector>
16 
26 #define DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CLASSTYPE, CLASSNAME) \
27  const std::string CLASSTYPE::CLASS_NAME = CLASSNAME; \
28  extern "C" { \
29  ::dynamicgraph::Entity *EntityMaker_##CLASSTYPE( \
30  const std::string &objname) { \
31  return new CLASSTYPE(objname); \
32  } \
33  ::dynamicgraph::EntityRegisterer reg_##CLASSTYPE(CLASSNAME, \
34  &EntityMaker_##CLASSTYPE); \
35  } \
36  struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
37 
38 namespace dynamicgraph {
81 class DYNAMIC_GRAPH_DLLAPI FactoryStorage : private boost::noncopyable {
82  public:
85  typedef Entity *(*EntityConstructor_ptr)(const std::string &);
86 
87  ~FactoryStorage();
88 
90  static FactoryStorage *getInstance();
91 
93  static void destroy();
94 
107  void registerEntity(const std::string &entname, EntityConstructor_ptr ent);
108 
116  void deregisterEntity(const std::string &entname);
117 
136  Entity *newEntity(const std::string &classname,
137  const std::string &objname) const;
138 
144  bool existEntity(const std::string &name) const;
145 
151  void listEntities(std::vector<std::string> &list) const;
152 
153  private:
159  explicit FactoryStorage();
160 
165  typedef std::map<std::string, EntityConstructor_ptr> EntityMap;
166 
170 
173 };
174 
184 class DYNAMIC_GRAPH_DLLAPI EntityRegisterer : private boost::noncopyable {
185  public:
187  explicit EntityRegisterer(const std::string &entityClassName,
189 
191  ~EntityRegisterer();
192 
193  private:
196  const std::string entityName;
197 };
198 } // end of namespace dynamicgraph
199 
200 #endif
201 
202 // LocalWords: unregister
dynamic-graph-api.h
dynamicgraph::FactoryStorage::EntityConstructor_ptr
Entity *(* EntityConstructor_ptr)(const std::string &)
Function pointer providing an entity instance from its name.
Definition: include/dynamic-graph/factory.h:85
dynamicgraph
dynamicgraph::EntityRegisterer
This class automatically register an Entity to the global factory at initialization and unregister it...
Definition: include/dynamic-graph/factory.h:184
dynamicgraph::FactoryStorage::entityMap
EntityMap entityMap
The entity map storing information about how to instantiate an Entity.
Definition: include/dynamic-graph/factory.h:169
dynamicgraph::Entity
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
Definition: include/dynamic-graph/entity.h:52
dynamicgraph::FactoryStorage
Provides a way to create Entity objects from their class name.
Definition: include/dynamic-graph/factory.h:81
fwd.hh
dynamicgraph::FactoryStorage::instance_
static FactoryStorage * instance_
\pointer to the unique object of the class
Definition: include/dynamic-graph/factory.h:172
exception-factory.h
dynamicgraph::FactoryStorage::EntityMap
std::map< std::string, EntityConstructor_ptr > EntityMap
Entity map type.
Definition: include/dynamic-graph/factory.h:165
dynamicgraph::EntityRegisterer::entityName
const std::string entityName
Name of the entity registered when the instance has been initialized.
Definition: include/dynamic-graph/factory.h:196
compile.name
name
Definition: compile.py:23


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38