-
Notifications
You must be signed in to change notification settings - Fork 1
/
SingletonHandler.h
49 lines (34 loc) · 1.17 KB
/
SingletonHandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <exception>
using namespace std;
#ifndef __SingletonHandler_h__
#define __SingletonHandler_h__
#include <iostream>
#include <map>
#include "EtatRobot.h"
class SingletonHandler
{
public:
typedef map<string, EtatRobot*> MapSingleton;
static MapSingleton _singletons;
// static void ajouterSingleton(string nom, EtatRobot instance);
//
// static bool existe(string nom);
//
// static EtatRobot recupererInstance(string nom);
static void ajouterSingleton(string nom, EtatRobot* instance) {
SingletonHandler::_singletons.insert(pair<string,EtatRobot*>(nom, instance));
}
static bool existe(string nom) {
return SingletonHandler::_singletons.count(nom) != 0;
}
static EtatRobot* recupererInstance(string nom) {
return SingletonHandler::_singletons.at(nom);
}
static void dump_map(const map<string, EtatRobot*>& map) {
for ( std::map<string,EtatRobot*>::const_iterator it = map.begin(); it != map.end(); it++) {
cout << "Key: " << it->first << endl;
cout << "Values" << it->second << endl;
}
}
};
#endif