Program listing for file control/src/utils/SensorFactory.hpp#

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