-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cpp
94 lines (78 loc) · 1.83 KB
/
Settings.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Settings.h"
#include "Util.h"
//#include <boost/property_tree/ini_parser.hpp>
Settings :: Settings(std::string fn)
{
nullify();
m_FileName = fn;
if(!open(fn))
m_bError = true;
}
Settings :: ~Settings()
{
save();
}
void Settings :: nullify()
{
m_bError = false;
}
void Settings :: update()
{
//foreach(Listener* listener, m_Listeners)
// listener->update();
}
bool Settings :: open(std::string fn)
{
m_FileName = fn;
return m_Properties.open(m_FileName.c_str());
}
bool Settings :: save()
{
if(!m_FileName.empty())
m_Properties.save(m_FileName.c_str());
else
return false;
return true;
}
std::string Settings :: getProperty(std::string c, std::string p, std::string def)
{
std::string v;
if(!m_Properties.getStringValue(c.c_str(), p.c_str(), v))
{
m_Properties.setStringValue(c.c_str(), p.c_str(), def);
return def;
}
return v;
}
int Settings :: getProperty(std::string c, std::string p, int def)
{
int v;
if(!m_Properties.getIntValue(c.c_str(), p.c_str(), v))
{
m_Properties.setIntValue(c.c_str(), p.c_str(), def);
return def;
}
return v;
}
float Settings :: getProperty(std::string c, std::string p, float def)
{
float v;
if(!m_Properties.getFloatValue(c.c_str(), p.c_str(), v))
{
m_Properties.setFloatValue(c.c_str(), p.c_str(), def);
return def;
}
return v;
}
void Settings :: setProperty(std::string c, std::string p, std::string val)
{
m_Properties.setStringValue(c.c_str(), p.c_str(), val);
}
void Settings :: setProperty(std::string c, std::string p, int val)
{
m_Properties.setIntValue(c.c_str(), p.c_str(), val);
}
void Settings :: setProperty(std::string c, std::string p, float val)
{
m_Properties.setFloatValue(c.c_str(), p.c_str(), val);
}