Program listing for file kernel/src/simulationTools/EventFactory.hpp

Program listing for file kernel/src/simulationTools/EventFactory.hpp#

 1#ifndef EventFactory_H
 2#define EventFactory_H
 3
 4# include "Event.hpp"
 5# include <map>
 6
 7
 8
 9namespace EventFactory
10{
11
12
13typedef SP::Event(*object_creator)(double, int);
14
15
16typedef std::map<int, object_creator> MapFactory;
17
18
19typedef MapFactory::iterator MapFactoryIt;
20
21
22template<class SubType> SP::Event factory(double time, int type)
23{
24  SP::Event e(new SubType(time, type));
25  return e;
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::Event instantiate(double time, int type);
47
48} ;
49
50
51class Registration
52{
53
54public :
55
56
57  Registration(int type, object_creator creator);
58} ;
59
60}
61
62
63#define AUTO_REGISTER_EVENT(class_name,class_type) EventFactory::Registration _registration_## class_type(class_name,&EventFactory::factory<class_type>);
64#endif