forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfg.cpp
More file actions
162 lines (128 loc) · 3.88 KB
/
cfg.cpp
File metadata and controls
162 lines (128 loc) · 3.88 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Aseprite Config Library
// Copyright (c) 2014-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cfg/cfg.h"
#include "base/file_handle.h"
#include "base/log.h"
#include "base/string.h"
#include <cstdlib>
#include <iostream>
#include "SimpleIni.h"
namespace cfg {
class CfgFile::CfgFileImpl {
public:
const std::string& filename() const {
return m_filename;
}
const char* getValue(const char* section, const char* name, const char* defaultValue) const {
return m_ini.GetValue(section, name, defaultValue);
}
bool getBoolValue(const char* section, const char* name, bool defaultValue) const {
return m_ini.GetBoolValue(section, name, defaultValue);
}
int getIntValue(const char* section, const char* name, int defaultValue) const {
return m_ini.GetLongValue(section, name, defaultValue);
}
double getDoubleValue(const char* section, const char* name, double defaultValue) const {
return m_ini.GetDoubleValue(section, name, defaultValue);
}
void setValue(const char* section, const char* name, const char* value) {
m_ini.SetValue(section, name, value);
}
void setBoolValue(const char* section, const char* name, bool value) {
m_ini.SetBoolValue(section, name, value);
}
void setIntValue(const char* section, const char* name, int value) {
m_ini.SetLongValue(section, name, value);
}
void setDoubleValue(const char* section, const char* name, double value) {
m_ini.SetDoubleValue(section, name, value);
}
void deleteValue(const char* section, const char* name) {
m_ini.Delete(section, name, true);
}
void load(const std::string& filename) {
m_filename = filename;
base::FileHandle file(base::open_file(m_filename, "rb"));
if (file) {
SI_Error err = m_ini.LoadFile(file.get());
if (err != SI_OK) {
LOG(ERROR) << "CFG: Error " << err << " loading configuration from " << m_filename << "\n";
}
}
}
void save() {
base::FileHandle file(base::open_file(m_filename, "wb"));
if (file) {
SI_Error err = m_ini.SaveFile(file.get());
if (err != SI_OK) {
LOG(ERROR) << "CFG: Error " << err << " saving configuration into " << m_filename << "\n";
}
}
}
private:
std::string m_filename;
CSimpleIniA m_ini;
};
CfgFile::CfgFile()
: m_impl(new CfgFileImpl)
{
}
CfgFile::~CfgFile()
{
delete m_impl;
}
const std::string& CfgFile::filename() const
{
return m_impl->filename();
}
const char* CfgFile::getValue(const char* section, const char* name, const char* defaultValue) const
{
return m_impl->getValue(section, name, defaultValue);
}
bool CfgFile::getBoolValue(const char* section, const char* name, bool defaultValue)
{
return m_impl->getBoolValue(section, name, defaultValue);
}
int CfgFile::getIntValue(const char* section, const char* name, int defaultValue)
{
return m_impl->getIntValue(section, name, defaultValue);
}
double CfgFile::getDoubleValue(const char* section, const char* name, double defaultValue)
{
return m_impl->getDoubleValue(section, name, defaultValue);
}
void CfgFile::setValue(const char* section, const char* name, const char* value)
{
m_impl->setValue(section, name, value);
}
void CfgFile::setBoolValue(const char* section, const char* name, bool value)
{
m_impl->setBoolValue(section, name, value);
}
void CfgFile::setIntValue(const char* section, const char* name, int value)
{
m_impl->setIntValue(section, name, value);
}
void CfgFile::setDoubleValue(const char* section, const char* name, double value)
{
m_impl->setDoubleValue(section, name, value);
}
void CfgFile::deleteValue(const char* section, const char* name)
{
m_impl->deleteValue(section, name);
}
void CfgFile::load(const std::string& filename)
{
m_impl->load(filename);
}
void CfgFile::save()
{
m_impl->save();
}
} // namespace cfg