Program listing for file kernel/src/modelingTools/RelationFactory.hpp

Program listing for file kernel/src/modelingTools/RelationFactory.hpp#

 1#ifndef RelationFactory_H
 2#define RelationFactory_H
 3
 4#include "SiconosPointers.hpp"
 5#include "Relation.hpp"
 6#include <string>
 7#include <map>
 8
 9
10namespace RelationFactory
11{
12
13
14typedef SP::Relation(*object_creator)(int) ;
15
16
17typedef std::map<int, object_creator> MapFactory;
18
19
20typedef MapFactory::iterator MapFactoryIt;
21
22
23template<class SubType> SP::Relation factory(int name)
24{
25  SP::Relation res(new SubType(name));
26  return res;
27}
28
29
30class Registry
31{
32
33private :
34
35
36  MapFactory factory_map;
37
38public :
39
40
41  static Registry& get() ;
42
43
44  void add(int name, object_creator obj);
45
46
47  SP::Relation instantiate(int name);
48} ;
49
50
51class Registration
52{
53
54public :
55
56
57  Registration(int name, object_creator obj) ;
58} ;
59
60#define AUTO_REGISTER_RELATION(class_name,class_type) Registration _registration_## class_type(class_name,&factory<class_type>);
61}
62
63
64#endif