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

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

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