-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathComponents.h
49 lines (39 loc) · 973 Bytes
/
Components.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
/*
* Components.h
*
* Created on: 11/lug/2013
* Author: Stefano Ceccherini
*/
#ifndef COMPONENTS_H_
#define COMPONENTS_H_
#include <map>
#include <stdexcept>
#include <string>
#include <vector>
typedef std::map<std::string, std::string> string_map;
class Component {
public:
string_map fields;
void MergeWith(Component& component);
};
class components_map : public std::multimap<std::string, Component> {
public:
void Merge(const std::string& string, Component c) {
components_map::iterator i = find(string);
if (i != end())
(*i).second.MergeWith(c);
else {
insert(std::make_pair(string, c));
}
};
Component& operator[](const std::string& string) {
components_map::iterator i = find(string);
if (i != end())
return (*i).second;
std::string errorString = "operator[]: no element for ";
errorString.append(string);
throw std::runtime_error(errorString);
}
};
extern components_map gComponents;
#endif /* COMPONENTS_H_ */