forked from Source-Python-Dev-Team/Source.Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyvalues_wrap.cpp
More file actions
248 lines (210 loc) · 7.31 KB
/
Copy pathkeyvalues_wrap.cpp
File metadata and controls
248 lines (210 loc) · 7.31 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* 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 General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/
//---------------------------------------------------------------------------------
// Includes.
//---------------------------------------------------------------------------------
#include "export_main.h"
#include "modules/memory/memory_tools.h"
#include "tier1/KeyValues.h"
#include "modules/keyvalues/keyvalues.h"
//---------------------------------------------------------------------------------
// Forward declarations.
//---------------------------------------------------------------------------------
void export_keyvalues(scope);
//---------------------------------------------------------------------------------
// Declare the _keyvalues module.
//---------------------------------------------------------------------------------
DECLARE_SP_MODULE(_keyvalues)
{
export_keyvalues(_keyvalues);
}
//---------------------------------------------------------------------------------
// Exports KeyValues.
//---------------------------------------------------------------------------------
void export_keyvalues(scope _keyvalues)
{
class_<KeyValues, boost::shared_ptr<KeyValues>, boost::noncopyable>("_KeyValues", no_init)
.def("__init__", make_constructor(&KeyValuesExt::__init__1))
.def("__init__", make_constructor(&KeyValuesExt::__init__2))
.def("__init__", make_constructor(&KeyValuesExt::__init__3))
.def("__init__", make_constructor(&KeyValuesExt::__init__4))
.def("__init__", make_constructor(&KeyValuesExt::__init__5))
.def("get_name",
&KeyValues::GetName,
"Returns the name of the keyvalues object."
)
.def("set_name",
&KeyValues::SetName,
"Sets the name of the keyvalues object.",
args("name")
)
.def("get_name_symbol",
&KeyValues::GetNameSymbol,
"Gets the name as a unique integer.",
args("key_symbol")
)
.def("uses_escape_sequences",
&KeyValues::UsesEscapeSequences,
"Sets whether or not this keyvalues object uses escape sequences.",
args("uses_escape_sequences")
)
.def("load_from_file",
&KeyValuesExt::LoadFromFile,
"Loads KeyValues data from a file into this KeyValues instance.",
args("file_name")
)
.def("save_to_file",
&KeyValuesExt::SaveToFile,
args("file_name"),
"Saves the data in this KeyValues instance to the given file path."
)
.def("find_key",
GET_METHOD(KeyValues *, KeyValues, FindKey, const char *, bool),
"Finds a KeyValue. Creates it if create_key is set.",
("key_name", arg("create_key")=false),
reference_existing_object_policy()
)
.def("find_key_by_symbol",
GET_CONST_METHOD(KeyValues*, KeyValues, FindKey, int),
"Finds a subkey by an integer identifier.",
args("key"),
reference_existing_object_policy()
)
.def("create_new_key",
&KeyValues::CreateNewKey,
"Creates a new child key with an autogenerated name. The name is guaranteed to be\
an integer, of value 1 higher than the highest other integer key name.",
reference_existing_object_policy()
)
.def("add_sub_key",
&KeyValues::AddSubKey,
"Adds a sub key. Make sure the subkey isn't a child of some other KeyValues.",
args("sub_key")
)
.def("remove_sub_key",
&KeyValues::RemoveSubKey,
"Removes a subkey from the list. DOES NOT DELETE IT!",
args("sub_key")
)
.def("get_first_sub_key",
&KeyValues::GetFirstSubKey,
"Returns the first subkey in the list. Will iterate over the keys AND the\
values.",
reference_existing_object_policy()
)
.def("get_next_key",
&KeyValues::GetNextKey,
"Returns the next subkey. Will iterate the keys AND the values.",
reference_existing_object_policy()
)
.def("get_first_true_sub_key",
&KeyValues::GetFirstTrueSubKey,
"Returns the first subkey (both key and value).",
reference_existing_object_policy()
)
.def("get_next_true_sub_key",
&KeyValues::GetNextTrueSubKey,
"Returns the next subkey (both key and value).",
reference_existing_object_policy()
)
.def("get_first_value",
&KeyValues::GetFirstValue,
"Returns the first value in the tree.",
reference_existing_object_policy()
)
.def("get_next_value",
&KeyValues::GetNextValue,
"Returns the next value in the tree.",
reference_existing_object_policy()
)
.def("get_int",
GET_METHOD(int, KeyValues, GetInt, const char *, int),
"Returns the integer value for the given key name.",
("key_name", arg("default_value")=0)
)
.def("get_uint64",
GET_METHOD(uint64, KeyValues, GetUint64, const char *, uint64),
"Gets the 64-bit integer value for the given key name.",
("key_name", arg("default_value")=0)
)
.def("get_float",
GET_METHOD(float, KeyValues, GetFloat, const char *, float),
"Returns the floating point value for the given key name.",
("key_name", arg("default_value")=0.0f)
)
.def("get_string",
GET_METHOD(const char *, KeyValues, GetString, const char *, const char *),
"Returns the string value for the given key name.",
("key_name", arg("default_value")="")
)
.def("get_color",
&KeyValuesExt::GetColor,
"Returns the color value of the given key name.",
("key_name", arg("default_value")=object())
)
.def("get_bool",
&KeyValuesExt::GetBool,
"Returns the boolean value for the given key name.",
("key_name", arg("default_value")=false)
)
.def("is_empty",
GET_METHOD(bool, KeyValues, IsEmpty, const char *),
"Returns true if this key or the given key is empty.",
(arg("key_name")=object())
)
.def("set_string",
&KeyValues::SetString,
"Sets the given key's string value.",
args("key_name", "value")
)
.def("set_int",
&KeyValues::SetInt,
"Sets the given key's integer value.",
args("key_name", "value")
)
.def("set_uint64",
&KeyValues::SetUint64,
"Sets the given key's 64-bit integer value.",
args("key_name", "value")
)
.def("set_float",
&KeyValues::SetFloat,
"Sets the given key's floating point value.",
args("key_name", "value")
)
.def("set_color",
&KeyValues::SetColor,
"Sets the given key's color value.",
args("key_name", "value")
)
.def("set_bool",
&KeyValuesExt::SetBool,
"Sets the given key's boolean value.",
args("key_name", "value")
)
ADD_MEM_TOOLS(KeyValues)
;
}