Computer Assited Medical Intervention Tool Kit  version 4.0
SimulatorFactory.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2016 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 
27 #ifndef SIMULATOR_SIMULATORFACTORY_H
28 #define SIMULATOR_SIMULATORFACTORY_H
29 // Simulator includes
30 #include "Simulator.h"
31 
32 #include "MMLAPI.h"
41 public:
42 
44  static SimulatorFactory* getInstance();
45 
53  template<typename C>
54  bool registerClass(std::string id, bool isInteractive) {
55  if (mapObjectCreator.find(id) != mapObjectCreator.end()) {
56  return false;
57  } else {
58  mapObjectCreator.insert( std::pair<std::string,CreateSimulatorFunctionPointer>(id, &createTheSimulator<C> ) );
59  mapObjectCreator2.insert( std::pair<std::string,CreateSimulatorFunctionPointer2>(id, &createTheSimulator2<C> ) );
60  mapInteractive.insert(std::pair<std::string,bool>(id,isInteractive));
61  if (isInteractive)
62  interactiveSimulators.push_back(id);
63  else
64  nonInteractiveSimulators.push_back(id);
65  return true;
66  }
67  }
68 
70  bool isRegistered(std::string id);
71 
73  Simulator* createSimulator(std::string id,MonitoringManager* monitoringManager);
74 
76  Simulator* createSimulator(std::string id,MonitoringManager* monitoringManager,const char* file);
77 
79  int getNumberOfInteractiveSimulators();
80 
82  int getNumberOfNonInteractiveSimulators();
83 
85  std::string getInteractiveSimulator(const unsigned int index);
86 
88  std::string getNonInteractiveSimulator(const unsigned int index);
89 
91  bool isInteractive(std::string id);
92 
93 private:
94 
96 
97  typedef Simulator* (*CreateSimulatorFunctionPointer)(MonitoringManager* monitoringManager);
98 
99  typedef Simulator* (*CreateSimulatorFunctionPointer2)(MonitoringManager* monitoringManager,const char* file);
100 
102  std::map<std::string, CreateSimulatorFunctionPointer> mapObjectCreator;
103 
105  std::map<std::string, CreateSimulatorFunctionPointer2> mapObjectCreator2;
106 
107 
108 
116  template<typename C>
117  static Simulator* createTheSimulator(MonitoringManager* monitoringManager) {
118  return new C(monitoringManager);
119  }
120 
130  template<typename C>
131  static Simulator* createTheSimulator2(MonitoringManager* monitoringManager,const char* file) {
132  return new C(monitoringManager,file);
133  }
134 
136  std::map<std::string, bool> mapInteractive;
137 
139  std::vector<std::string> interactiveSimulators;
140 
142  std::vector<std::string> nonInteractiveSimulators;
143 
146 
147 };
148 
149 
150 #endif // SIMULATOR_SIMULATORFACTORY_H
std::map< std::string, bool > mapInteractive
map between Simulator name as string to booleen, true if interactive
Definition: SimulatorFactory.h:136
std::map< std::string, CreateSimulatorFunctionPointer2 > mapObjectCreator2
A map between Simulator name as string to functions (for the 2nd constructor that uses a simulator fi...
Definition: SimulatorFactory.h:105
A factory to create Simulator.
Definition: SimulatorFactory.h:40
std::vector< std::string > interactiveSimulators
list of interactive simulators
Definition: SimulatorFactory.h:139
static Simulator * createTheSimulator2(MonitoringManager *monitoringManager, const char *file)
map the simulator name with the 2 parameters constructor (using the given specific simulator file) ...
Definition: SimulatorFactory.h:131
A simulator engine is used to compute the displacements of all atoms of the model.
Definition: Simulator.h:46
bool registerClass(std::string id, bool isInteractive)
Register a class into the map A registered class can be created using createMonitorDisplay() ...
Definition: SimulatorFactory.h:54
Manager of the benchmark tests.
Definition: MonitoringManager.h:50
std::map< std::string, CreateSimulatorFunctionPointer > mapObjectCreator
A map between Simulator name as string to functions.
Definition: SimulatorFactory.h:102
static SimulatorFactory * instance
unique instance of the factory
Definition: SimulatorFactory.h:145
std::vector< std::string > nonInteractiveSimulators
list of non interactive simulators
Definition: SimulatorFactory.h:142
static Simulator * createTheSimulator(MonitoringManager *monitoringManager)
map the simulator name with the 1 parameter constructor.
Definition: SimulatorFactory.h:117
#define MML_API
Definition: MMLAPI.h:43