Computer Assisted Medical Intervention Tool Kit  version 5.2
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-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
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  }
58  else {
59  mapObjectCreator.insert(std::pair<std::string, CreateSimulatorFunctionPointer>(id, &createTheSimulator<C>));
60  mapObjectCreator2.insert(std::pair<std::string, CreateSimulatorFunctionPointer2>(id, &createTheSimulator2<C>));
61  mapInteractive.insert(std::pair<std::string, bool>(id, isInteractive));
62  if (isInteractive) {
63  interactiveSimulators.push_back(id);
64  }
65  else {
66  nonInteractiveSimulators.push_back(id);
67  }
68  return true;
69  }
70  }
71 
73  bool isRegistered(std::string id);
74 
76  Simulator* createSimulator(std::string id, MonitoringManager* monitoringManager);
77 
79  Simulator* createSimulator(std::string id, MonitoringManager* monitoringManager, const char* file);
80 
82  int getNumberOfInteractiveSimulators();
83 
85  int getNumberOfNonInteractiveSimulators();
86 
88  std::string getInteractiveSimulator(const unsigned int index);
89 
91  std::string getNonInteractiveSimulator(const unsigned int index);
92 
94  bool isInteractive(std::string id);
95 
96 private:
97 
98  SimulatorFactory() = default;
99 
100  typedef Simulator* (*CreateSimulatorFunctionPointer)(MonitoringManager* monitoringManager);
101 
102  typedef Simulator* (*CreateSimulatorFunctionPointer2)(MonitoringManager* monitoringManager, const char* file);
103 
105  std::map<std::string, CreateSimulatorFunctionPointer> mapObjectCreator;
106 
108  std::map<std::string, CreateSimulatorFunctionPointer2> mapObjectCreator2;
109 
110 
111 
119  template<typename C>
120  static Simulator* createTheSimulator(MonitoringManager* monitoringManager) {
121  return new C(monitoringManager);
122  }
123 
133  template<typename C>
134  static Simulator* createTheSimulator2(MonitoringManager* monitoringManager, const char* file) {
135  return new C(monitoringManager, file);
136  }
137 
139  std::map<std::string, bool> mapInteractive;
140 
142  std::vector<std::string> interactiveSimulators;
143 
145  std::vector<std::string> nonInteractiveSimulators;
146 
148  static SimulatorFactory* instance;
149 
150 };
151 
152 
153 #endif // SIMULATOR_SIMULATORFACTORY_H
#define MML_API
Definition: MMLAPI.h:43
Manager of the benchmark tests.
Definition: MonitoringManager.h:50
A factory to create Simulator.
Definition: SimulatorFactory.h:40
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
A simulator engine is used to compute the displacements of all atoms of the model.
Definition: Simulator.h:46