/
config.h
143 lines (122 loc) · 4.35 KB
/
config.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
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
/*
* The Doomsday Engine Project -- libcore
*
* Copyright © 2009-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBDENG2_CONFIG_H
#define LIBDENG2_CONFIG_H
#include "../Process"
#include "../String"
#include "../Path"
#include "../Version"
#include "../Record"
namespace de {
class ArrayValue;
/**
* Stores the configuration of everything.
*
* The application owns a Config. The default configuration is produced by executing the
* .de scripts in the config directories. The resulting namespace is serialized for
* storage, and is restored from the serialized version directly before the config
* scripts are run.
*
* The version of the engine is stored in the serialized config namespace. This is for
* actions needed when upgrading: the config script can check the previous version and
* apply changes accordingly.
*
* In practice, Config is a specialized script namespace stored in a Record. It gets
* written to the application's persistent data store (persist.pack) using a Refuge. The
* Config is automatically written persistently before being destroyed.
*
* @ingroup core
*/
class DENG2_PUBLIC Config : public RecordAccessor
{
public:
/**
* Constructs a new configuration.
*
* @param path Name of the configuration file to read.
*/
Config(Path const &path);
/// Read configuration from files.
void read();
/// Writes the configuration to /home.
void write() const;
/**
* Sets the value of a variable, creating the variable if needed.
*
* @param name Name of the variable. May contain subrecords using the dot notation.
* @param value Value for the variable.
*
* @return Variable whose value was set.
*/
Variable &set(String const &name, bool value);
/// @copydoc set()
Variable &set(String const &name, Value::Text const &value);
/// @copydoc set()
Variable &set(String const &name, Value::Number const &value);
/// @copydoc set()
Variable &set(String const &name, dint value);
/// @copydoc set()
Variable &set(String const &name, duint value);
/**
* Sets the value of a variable, creating the variable if it doesn't exist.
*
* @param name Name of the variable. May contain subrecords using the dot notation.
* @param value Array to use as the value of the variable. Ownership taken.
*/
Variable &set(String const &name, ArrayValue *value);
/**
* Returns the configuration namespace.
*/
Record &names();
/**
* Returns the configuration namespace (immutable).
*/
Record const &names() const;
/**
* Looks up a variable in the Config. Variables in subrecords can be accessed
* using the member notation: <code>subrecord-name.variable-name</code>
*
* If the variable does not exist, a Record::NotFoundError is thrown.
*
* @param name Variable name.
*
* @return Variable.
*/
Variable &operator [] (String const &name);
/**
* Looks up a variable in the record. Variables in subrecords can be accessed
* using the member notation: <code>subrecord-name.variable-name</code>
*
* If the variable does not exist, an Record::NotFoundError is thrown.
*
* @param name Variable name.
*
* @return Variable (non-modifiable).
*/
Variable const &operator [] (String const &name) const;
/**
* Returns the old version, when a new installed version has been detected.
* If no upgrade has occurred, returns the current version.
*/
Version upgradedFromVersion() const;
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif /* LIBDENG2_CONFIG_H */