Properties.hh
1.38 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Properties.hh
*
* Created on: 12 oct. 2012
* Author: casimir
*/
#ifndef PROPERTIES_HH_
#define PROPERTIES_HH_
#include <iostream>
#include <map>
#include <string>
#include <fstream>
using namespace std;
namespace AMDA
{
namespace helpers
{
/**
* @brief properties file parser
*/
class Properties
{
public:
/**
* @brief constructor
* @param pFilename name of file to be parsed
*
*/
Properties(const char* pFilename)
{
fstream filestr(pFilename, fstream::in);
string s = "";
while (getline(filestr, s))
{
if (s[0] != '#')
{
_data[s.substr(0, s.find('='))] = s.substr(s.find('=') + 1);
}
}
}
/**
* @brief constructor by copy
*/
Properties(const Properties& pProperties) : _data( pProperties._data)
{
}
/**
* @brief overload operator[] to get the property pKey
* @param pKey name of property
*/
const string&
operator[](const string& pKey)
{
return _data[pKey.c_str()];
}
private:
/**
* @brief Type of map to stored properties
*/
typedef map<const string, string> DataType;
/**
* @brief Map to stored properties
*/
DataType _data;
};
}
}
#endif /* PROPERTIES_HH_ */