Computer Assited Medical Intervention Tool Kit  version 5.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-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, 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
SimulatorFactory
A factory to create Simulator.
Definition: SimulatorFactory.h:40
SimulatorFactory::mapObjectCreator
std::map< std::string, CreateSimulatorFunctionPointer > mapObjectCreator
A map between Simulator name as string to functions.
Definition: SimulatorFactory.h:128
SimulatorFactory::instance
static SimulatorFactory * instance
unique instance of the factory
Definition: SimulatorFactory.h:171
MML_API
#define MML_API
Definition: MMLAPI.h:43
SimulatorFactory::getInstance
static SimulatorFactory * getInstance()
return the unique instance of the factory
Definition: SimulatorFactory.cpp:56
SimulatorFactory::getNonInteractiveSimulator
std::string getNonInteractiveSimulator(const unsigned int index)
get a non interactive simulator name by its index
Definition: SimulatorFactory.cpp:74
Simulator
A simulator engine is used to compute the displacements of all atoms of the model.
Definition: Simulator.h:46
SimulatorFactory::isInteractive
bool isInteractive(std::string id)
return true if the registered simulator id is interactive
Definition: SimulatorFactory.cpp:94
SimulatorFactory::mapInteractive
std::map< std::string, bool > mapInteractive
map between Simulator name as string to booleen, true if interactive
Definition: SimulatorFactory.h:162
SimulatorFactory::isRegistered
bool isRegistered(std::string id)
Returns true if id is in the map.
Definition: SimulatorFactory.cpp:32
SimulatorFactory::nonInteractiveSimulators
std::vector< std::string > nonInteractiveSimulators
list of non interactive simulators
Definition: SimulatorFactory.h:168
SimulatorFactory::getNumberOfInteractiveSimulators
int getNumberOfInteractiveSimulators()
give the number of interactive simulators registered
Definition: SimulatorFactory.cpp:84
SimulatorFactory::getNumberOfNonInteractiveSimulators
int getNumberOfNonInteractiveSimulators()
give the number of interactive simulators registered
Definition: SimulatorFactory.cpp:89
InitSimulators.h
SimulatorFactory::SimulatorFactory
SimulatorFactory()=default
SimulatorFactory.h
SimulatorFactory::getInteractiveSimulator
std::string getInteractiveSimulator(const unsigned int index)
get a interactive simulator name by its index
Definition: SimulatorFactory.cpp:64
SimulatorFactory::mapObjectCreator2
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:131
MMLAPI.h
MonitoringManager
Manager of the benchmark tests. Do simulation loop and tests.
Definition: MonitoringManager.h:50
SimulatorFactory::createSimulator
Simulator * createSimulator(std::string id, MonitoringManager *monitoringManager)
Creates a Simulator based on its string id or return nullptr if there is no id in the map.
Definition: SimulatorFactory.cpp:37
SimulatorFactory::interactiveSimulators
std::vector< std::string > interactiveSimulators
list of interactive simulators
Definition: SimulatorFactory.h:165
Simulator.h