-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.cpp
More file actions
98 lines (85 loc) · 1.92 KB
/
settings.cpp
File metadata and controls
98 lines (85 loc) · 1.92 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "stdafx.h"
#include "settings.h"
#include "util.h"
namespace Vars
{
using namespace FileSystem;
Settings::Settings()
{
parser = nullptr;
}
Settings::Settings(IniParser* parser_, const char* activeSystem_)
{
parser = nullptr;
attachParser(parser_, activeSystem_);
}
bool Settings::convert(int& out, const std::string& in)
{
out = atoi(in.c_str());
return true;
}
bool Settings::convert(unsigned& out, const std::string& in)
{
out = (unsigned)strtoul(in.c_str(), NULL, 0);
return true;
}
bool Settings::convert(long& out, const std::string& in)
{
out = atol(in.c_str());
return true;
}
bool Settings::convert(long long& out, const std::string& in)
{
out = atoll(in.c_str());
return true;
}
bool Settings::convert(unsigned long long& out, const std::string& in)
{
out = strtoull(in.c_str(), NULL, 0);
return true;
}
bool Settings::convert(float& out, const std::string& in)
{
out = strtof(in.c_str(), NULL);
return true;
}
bool Settings::convert(double& out, const std::string& in)
{
out = strtod(in.c_str(), NULL);
return true;
}
bool Settings::convert(bool& out, std::string in)
{
toLowerCase(in);
if (in == "true" || in == "1")
{
out = true;
return true;
}
else if (in == "false" || in == "0")
{
out = false;
return true;
}
//If not a proper boolean value
return false;
}
bool Settings::attachParser(IniParser* parser_, string activeSystem_)
{
//Check parser integrity:
if (parser_ == nullptr || !parser_->initialised())
{
Warning("Could not prepare Settings: Ini parser not initialised!");
return false;
}
toUpperCase(activeSystem_);
//Connect with the appropriate System:
SystemList::const_iterator newSystemLoc = parser_->find(activeSystem_);
if (newSystemLoc == parser_->end()) //If System not found
return false;
parser = parser_;
activeSystem = activeSystem_;
systemLoc = newSystemLoc;
return true;
}
}