-
Notifications
You must be signed in to change notification settings - Fork 0
/
ascnconfig.h
80 lines (64 loc) · 1.58 KB
/
ascnconfig.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
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
#ifndef ASCNCONFIG_H
#define ASCNCONFIG_H
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include "ascnpaths.h"
namespace config {
enum configError_t {
kNone,
kKeyNotFound,
kInvalidKey,
kUnknownKeyError,
kFileNotFound
};
union configItem_u {
std::string s;
int i;
double r;
bool b;
};
class ConfigItem {
public:
ConfigItem();
ConfigItem(std::string contents);
ConfigItem(int contents);
ConfigItem(double contents);
ConfigItem(bool contents);
~ConfigItem();
std::string getString();
int getInt();
double getReal();
bool getBool();
private:
configItem_u m_content;
};
class ascnconfig {
public:
ascnconfig(std::string appName, bool importFromFile=false);
ascnconfig(std::string orgName, std::string appName, bool importFromFile=false);
~ascnconfig();
/** CONFIG LOAD/SAVE **/
bool loadConfig();
bool loadConfig(std::string filename);
bool saveConfig();
bool saveConfig(std::string filename);
/** CONFIG API **/
ConfigItem getValue(std::string key);
bool setValue(std::string key, std::string value);
bool setValue(std::string key, int value);
bool setValue(std::string key, bool value);
/** CONFIGURE CONFIGURATION OBJECT (hehe) **/
void setAppName(std::string appName);
void setOrgName(std::string orgName);
void setAppQualified(std::string orgName, std::string appName);
private:
bool importSettings(std::string fname);
bool exportSettings(std::string fname);
std::map<std::string,ConfigItem*> m_settings;
std::string m_org, m_app;
configError_t m_error;
};
}
#endif //ASCNCONFIG_H