Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2014 UJF-Grenoble 1, 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 
30 #include "simulator/Simulator.h"
31 
32 #include "MMLAPI.h"
41 {
42  public:
43 
45  static SimulatorFactory* getInstance();
46 
54  template<typename C>
55  bool registerClass(std::string id, bool isInteractive) {
56  if (mapObjectCreator.find(id) != mapObjectCreator.end()){
57  return false;
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  else
65  nonInteractiveSimulators.push_back(id);
66  return true;
67  }
68 }
69 
71  bool isRegistered(std::string id);
72 
74  Simulator* createSimulator(std::string id,MonitoringManager* monitoringManager);
75 
77  Simulator* createSimulator(std::string id,MonitoringManager* monitoringManager,const char* file);
78 
80  int getNumberOfInteractiveSimulators();
81 
83  int getNumberOfNonInteractiveSimulators();
84 
86  std::string getInteractiveSimulator(const unsigned int index);
87 
89  std::string getNonInteractiveSimulator(const unsigned int index);
90 
92  bool isInteractive(std::string id);
93 
94  private:
95 
97 
98  typedef Simulator* (*CreateSimulatorFunctionPointer)(MonitoringManager* monitoringManager);
99 
100  typedef Simulator* (*CreateSimulatorFunctionPointer2)(MonitoringManager* monitoringManager,const char* file);
101 
103  std::map<std::string, CreateSimulatorFunctionPointer> mapObjectCreator;
104 
106  std::map<std::string, CreateSimulatorFunctionPointer2> mapObjectCreator2;
107 
108 
109 
117  template<typename C>
118  static Simulator* createTheSimulator(MonitoringManager* monitoringManager){
119  return new C(monitoringManager);
120  }
121 
131 template<typename C>
132  static Simulator* createTheSimulator2(MonitoringManager* monitoringManager,const char* file){
133  return new C(monitoringManager,file);
134  }
135 
137  std::map<std::string, bool> mapInteractive;
138 
140  std::vector<std::string> interactiveSimulators;
141 
143  std::vector<std::string> nonInteractiveSimulators;
144 
147 
148 };
149 
150 
151 #endif // SIMULATOR_SIMULATORFACTORY_H
std::map< std::string, bool > mapInteractive
map between Simulator name as string to booleen, true if interactive
Definition: SimulatorFactory.h:137
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:106
A factory to create Simulator.
Definition: SimulatorFactory.h:40
std::vector< std::string > interactiveSimulators
list of interactive simulators
Definition: SimulatorFactory.h:140
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:132
A simulator engine is used to compute the displacements of all atoms of the model.
Definition: Simulator.h:44
bool registerClass(std::string id, bool isInteractive)
Register a class into the map A registered class can be created using createMonitorDisplay() ...
Definition: SimulatorFactory.h:55
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:103
static SimulatorFactory * instance
unique instance of the factory
Definition: SimulatorFactory.h:146
std::vector< std::string > nonInteractiveSimulators
list of non interactive simulators
Definition: SimulatorFactory.h:143
static Simulator * createTheSimulator(MonitoringManager *monitoringManager)
map the simulator name with the 1 parameter constructor.
Definition: SimulatorFactory.h:118
#define MML_API
Definition: MMLAPI.h:43