Computer Assited Medical Intervention Tool Kit  version 5.0
MMLMonitorDisplayFactory.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 #ifndef MMLMonitorDisplayFactory_H
27 #define MMLMonitorDisplayFactory_H
28 
29 #include <map>
30 #include <vector>
31 #include <string>
32 
33 // Monitor includes
34 #include "Monitor.h"
35 #include "MMLComponentAPI.h"
36 
37 class MMLMonitorDisplay;
38 class MMLComponent;
48 
49 public:
50 
52  static MMLMonitorDisplayFactory* getInstance();
53 
63  template<typename C>
64  bool registerClass(std::string id, Monitor::type type) {
65  if (mapObjectCreator.find(id) != mapObjectCreator.end()) {
66  return false;
67  }
68  else {
69  mapObjectCreator.insert(std::pair<std::string, CreateMonitorDisplayFunctionPointer>(id, &createTheMonitorDisplay<C>));
70  displaysByType[type].push_back(id);
71  return true;
72  }
73  }
74 
82  template<typename C>
83  bool registerClass(std::string id) {
84  if (mapObjectCreator.find(id) != mapObjectCreator.end()) {
85  return false;
86  }
87  else {
88  mapObjectCreator.insert(std::pair<std::string, CreateMonitorDisplayFunctionPointer>(id, &createTheMonitorDisplay<C>));
89  for (unsigned int i = 0; i < Monitor::typeCount; i++) {
90  displaysByType[i].push_back(id);
91  }
92 
93  return true;
94  }
95  }
96 
98  bool isRegistered(std::string id);
99 
101  MMLMonitorDisplay* createMonitorDisplay(std::string id, Monitor* monitor, MMLComponent* manager);
102 
104  unsigned int getNumberOfDisplaysByType(Monitor::type type);
105 
107  std::string getDisplayByType(Monitor::type type, const unsigned int i);
108 
109 private:
110 
111  MMLMonitorDisplayFactory() = default;
112 
114 
116  std::map<std::string, CreateMonitorDisplayFunctionPointer> mapObjectCreator;
117 
122  template<typename C>
124  return new C(monitor, manager);
125  }
126 
128  std::vector<std::string> displaysByType[Monitor::typeCount];
129 
132 };
133 
134 
135 #endif // MMLMonitorDisplayFactory_H
MMLComponentAPI.h
MMLMonitorDisplayFactory
A Factory for creating MMLMonitorDiplay.
Definition: MMLMonitorDisplayFactory.h:47
MMLMonitorDisplayFactory::CreateMonitorDisplayFunctionPointer
MMLMonitorDisplay *(*)(Monitor *monitor, MMLComponent *manager) CreateMonitorDisplayFunctionPointer
Definition: MMLMonitorDisplayFactory.h:113
MMLMonitorDisplayFactory::getNumberOfDisplaysByType
unsigned int getNumberOfDisplaysByType(Monitor::type type)
give the number of displays registered for a specified type
Definition: MMLMonitorDisplayFactory.cpp:55
MMLMonitorDisplayFactory::getInstance
static MMLMonitorDisplayFactory * getInstance()
return the unique instance of the factory
Definition: MMLMonitorDisplayFactory.cpp:60
MMLMonitorDisplayFactory::isRegistered
bool isRegistered(std::string id)
Returns true if id is in the map.
Definition: MMLMonitorDisplayFactory.cpp:31
MMLMonitorDisplayFactory::mapObjectCreator
std::map< std::string, CreateMonitorDisplayFunctionPointer > mapObjectCreator
A map between MonitorDisplay name as string to functions (CreateMonitorDisplayFunctionPointer)
Definition: MMLMonitorDisplayFactory.h:116
MMLMonitorDisplay
Generic class for MML Monitor 3D/Graphical representation.
Definition: MMLMonitorDisplay.h:45
MMLComponent
This class manage an MML monitoring document ".mml".
Definition: MMLComponent.h:48
MMLMonitorDisplayFactory::registerClass
bool registerClass(std::string id, Monitor::type type)
Register a class into the map A registered class can be created using createMonitorDisplay().
Definition: MMLMonitorDisplayFactory.h:64
MMLMonitorDisplayFactory.h
Monitor::type
type
type of the values stored (please update typeCount and doc if you update the enum) SCALAR: the monito...
Definition: Monitor.h:83
MMLMonitorDisplayFactory::instance
static MMLMonitorDisplayFactory * instance
unique instance of the factory
Definition: MMLMonitorDisplayFactory.h:131
Monitor::typeCount
static const unsigned int typeCount
number of possible types (siez of the previous enum). Please always update if the enum is updated.
Definition: Monitor.h:90
MMLCOMPONENT_API
#define MMLCOMPONENT_API
Definition: MMLComponentAPI.h:54
MMLMonitorDisplayFactory::getDisplayByType
std::string getDisplayByType(Monitor::type type, const unsigned int i)
get a display name by its type and index
Definition: MMLMonitorDisplayFactory.cpp:45
MMLMonitorDisplayFactory::createTheMonitorDisplay
static MMLMonitorDisplay * createTheMonitorDisplay(Monitor *monitor, MMLComponent *manager)
function whose pointers are inserted into the map.
Definition: MMLMonitorDisplayFactory.h:123
MMLMonitorDisplayFactory::MMLMonitorDisplayFactory
MMLMonitorDisplayFactory()=default
Monitor
A monitor calculate and store followed data (ex:calculation between current position and references) ...
Definition: Monitor.h:49
MMLMonitorDisplayFactory::displaysByType
std::vector< std::string > displaysByType[Monitor::typeCount]
list of displays by type
Definition: MMLMonitorDisplayFactory.h:128
Monitor.h
MMLMonitorDisplayFactory::createMonitorDisplay
MMLMonitorDisplay * createMonitorDisplay(std::string id, Monitor *monitor, MMLComponent *manager)
Creates an MMLMonitorDisplay based on its string id or return null if there is no id in the map.
Definition: MMLMonitorDisplayFactory.cpp:36
MMLMonitorDisplayFactory::registerClass
bool registerClass(std::string id)
Register a class into the map for classes wich can display every types of monitors.
Definition: MMLMonitorDisplayFactory.h:83