|
faluco@654
|
1 |
/** |
|
faluco@654
|
2 |
* vim: set ts=4 : |
|
faluco@654
|
3 |
* =============================================================== |
|
faluco@654
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
faluco@654
|
5 |
* =============================================================== |
|
faluco@654
|
6 |
* |
|
faluco@654
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. This file may only be used |
|
faluco@654
|
8 |
* or modified under the Terms and Conditions of its License Agreement, which is found |
|
faluco@654
|
9 |
* in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins |
|
faluco@654
|
10 |
* may change at any time. To view the latest information, see: |
|
faluco@654
|
11 |
* http://www.sourcemod.net/license.php |
|
faluco@654
|
12 |
* |
|
faluco@654
|
13 |
* Version: $Id$ |
|
faluco@654
|
14 |
*/ |
|
faluco@654
|
15 |
|
|
faluco@654
|
16 |
#if defined _keyvalues_included |
|
faluco@654
|
17 |
#endinput |
|
faluco@654
|
18 |
#endif |
|
faluco@654
|
19 |
#define _keyvalues_included |
|
faluco@654
|
20 |
|
|
faluco@654
|
21 |
/** |
|
faluco@654
|
22 |
* KeyValue data value types |
|
faluco@654
|
23 |
*/ |
|
faluco@654
|
24 |
enum KvDataTypes |
|
faluco@654
|
25 |
{ |
|
faluco@654
|
26 |
KvData_None = 0, /**< Type could not be identified, or no type */ |
|
faluco@654
|
27 |
KvData_String, /**< String value */ |
|
faluco@654
|
28 |
KvData_Int, /**< Integer value */ |
|
faluco@654
|
29 |
KvData_Float, /**< Floating point value */ |
|
faluco@654
|
30 |
KvData_Ptr, /**< Pointer value (sometimes called "long") */ |
|
faluco@654
|
31 |
KvData_WString, /**< Wide string value */ |
|
faluco@654
|
32 |
KvData_Color, /**< Color value */ |
|
faluco@654
|
33 |
KvData_UInt64, /**< Large integer value */ |
|
faluco@654
|
34 |
/* --- */ |
|
faluco@654
|
35 |
KvData_NUMTYPES, |
|
faluco@654
|
36 |
}; |
|
faluco@654
|
37 |
|
|
faluco@654
|
38 |
/** |
|
faluco@654
|
39 |
* Creates a new KeyValues structure. The Handle must always be closed. |
|
faluco@654
|
40 |
* |
|
faluco@654
|
41 |
* @param name Name of the root section. |
|
faluco@654
|
42 |
* @param firstKey If non-empty, specifies the first key value. |
|
faluco@654
|
43 |
* @param firstValue If firstKey is non-empty, specifies the first key's value. |
|
faluco@654
|
44 |
* @return A Handle to a new KeyValues structure. |
|
faluco@654
|
45 |
*/ |
|
dvander@725
|
46 |
native Handle:CreateKeyValues(const String:name[], const String:firstkey[]="", const String:firstValue[]=""); |
|
faluco@654
|
47 |
|
|
faluco@654
|
48 |
/** |
|
faluco@654
|
49 |
* Sets a string value of a KeyValues key. |
|
faluco@654
|
50 |
* |
|
faluco@654
|
51 |
* @param kv KeyValues Handle. |
|
faluco@654
|
52 |
* @param key Name of the key. |
|
faluco@654
|
53 |
* @param value String value. |
|
faluco@654
|
54 |
* @noreturn |
|
faluco@654
|
55 |
* @error Invalid Handle. |
|
faluco@654
|
56 |
*/ |
|
faluco@654
|
57 |
native KvSetString(Handle:kv, const String:key[], const String:value[]); |
|
faluco@654
|
58 |
|
|
faluco@654
|
59 |
/** |
|
faluco@654
|
60 |
* Sets an integer value of a KeyValues key. |
|
faluco@654
|
61 |
* |
|
faluco@654
|
62 |
* @param kv KeyValues Handle. |
|
faluco@654
|
63 |
* @param key Name of the key. |
|
faluco@654
|
64 |
* @param value Value number. |
|
faluco@654
|
65 |
* @noreturn |
|
faluco@654
|
66 |
* @error Invalid Handle. |
|
faluco@654
|
67 |
*/ |
|
faluco@654
|
68 |
native KvSetNum(Handle:kv, const String:key[], value); |
|
faluco@654
|
69 |
|
|
faluco@654
|
70 |
/** |
|
faluco@654
|
71 |
* Sets a large integer value of a KeyValues key. |
|
faluco@654
|
72 |
* |
|
faluco@654
|
73 |
* @param kv KeyValues Handle. |
|
faluco@654
|
74 |
* @param key Name of the key. |
|
faluco@654
|
75 |
* @param value Large integer value (0=High bits, 1=Low bits) |
|
faluco@654
|
76 |
* @noreturn |
|
faluco@654
|
77 |
* @error Invalid Handle. |
|
faluco@654
|
78 |
*/ |
|
faluco@654
|
79 |
native KvSetUint64(Handle:kv, const String:key[], const value[2]); |
|
faluco@654
|
80 |
|
|
faluco@654
|
81 |
/** |
|
faluco@654
|
82 |
* Sets a floating point value of a KeyValues key. |
|
faluco@654
|
83 |
* |
|
faluco@654
|
84 |
* @param kv KeyValues Handle. |
|
faluco@654
|
85 |
* @param key Name of the key. |
|
faluco@654
|
86 |
* @param value Floating point value. |
|
faluco@654
|
87 |
* @noreturn |
|
faluco@654
|
88 |
* @error Invalid Handle. |
|
faluco@654
|
89 |
*/ |
|
faluco@654
|
90 |
native KvSetFloat(Handle:kv, const String:key[], Float:value); |
|
faluco@654
|
91 |
|
|
faluco@654
|
92 |
/** |
|
faluco@654
|
93 |
* Sets a set of color values of a KeyValues key. |
|
faluco@654
|
94 |
* |
|
faluco@654
|
95 |
* @param kv KeyValues Handle. |
|
faluco@654
|
96 |
* @param key Name of the key. |
|
faluco@654
|
97 |
* @param r Red value. |
|
faluco@654
|
98 |
* @param g Green value. |
|
faluco@654
|
99 |
* @param b Blue value. |
|
faluco@654
|
100 |
* @param a Alpha value. |
|
faluco@654
|
101 |
* @noreturn |
|
faluco@654
|
102 |
* @error Invalid Handle. |
|
faluco@654
|
103 |
*/ |
|
faluco@654
|
104 |
native KvSetColor(Handle:kv, const String:key[], r, g, b, a=0); |
|
faluco@654
|
105 |
|
|
faluco@654
|
106 |
/** |
|
faluco@654
|
107 |
* Retrieves a string value from a KeyValues key. |
|
faluco@654
|
108 |
* |
|
faluco@654
|
109 |
* @param kv KeyValues Handle. |
|
faluco@654
|
110 |
* @param key Name of the key. |
|
faluco@654
|
111 |
* @param value Buffer to store key value in. |
|
faluco@654
|
112 |
* @param maxlength Maximum length of the value buffer. |
|
faluco@654
|
113 |
* @param defvalue Optional default value to use if the key is not found. |
|
faluco@654
|
114 |
* @noreturn |
|
faluco@654
|
115 |
* @error Invalid Handle. |
|
faluco@654
|
116 |
*/ |
|
faluco@654
|
117 |
native KvGetString(Handle:kv, const String:key[], String:value[], maxlength, const String:defvalue[]=""); |
|
faluco@654
|
118 |
|
|
faluco@654
|
119 |
/** |
|
faluco@654
|
120 |
* Retrieves an integer value from a KeyValues key. |
|
faluco@654
|
121 |
* |
|
faluco@654
|
122 |
* @param kv KeyValues Handle. |
|
faluco@654
|
123 |
* @param key Name of the key. |
|
faluco@654
|
124 |
* @param defvalue Optional default value to use if the key is not found. |
|
faluco@654
|
125 |
* @return Integer value of the key. |
|
faluco@654
|
126 |
* @error Invalid Handle. |
|
faluco@654
|
127 |
*/ |
|
faluco@654
|
128 |
native KvGetNum(Handle:kv, const String:key[], defvalue=0); |
|
faluco@654
|
129 |
|
|
faluco@654
|
130 |
/** |
|
faluco@654
|
131 |
* Retrieves a floating point value from a KeyValues key. |
|
faluco@654
|
132 |
* |
|
faluco@654
|
133 |
* @param kv KeyValues Handle. |
|
faluco@654
|
134 |
* @param key Name of the key. |
|
faluco@654
|
135 |
* @param defvalue Optional default value to use if the key is not found. |
|
faluco@654
|
136 |
* @return Floating point value of the key. |
|
faluco@654
|
137 |
* @error Invalid Handle. |
|
faluco@654
|
138 |
*/ |
|
faluco@654
|
139 |
native Float:KvGetFloat(Handle:kv, const String:key[], Float:defvalue=0.0); |
|
faluco@654
|
140 |
|
|
faluco@654
|
141 |
/** |
|
faluco@654
|
142 |
* Retrieves a set of color values from a KeyValues key. |
|
faluco@654
|
143 |
* |
|
faluco@654
|
144 |
* @param kv KeyValues Handle. |
|
faluco@654
|
145 |
* @param key Name of the key. |
|
faluco@654
|
146 |
* @param r Red value, set by reference. |
|
faluco@654
|
147 |
* @param g Green value, set by reference. |
|
faluco@654
|
148 |
* @param b Blue value, set by reference. |
|
faluco@654
|
149 |
* @param a Alpha value, set by reference. |
|
faluco@654
|
150 |
* @noreturn |
|
faluco@654
|
151 |
* @error Invalid Handle. |
|
faluco@654
|
152 |
*/ |
|
faluco@654
|
153 |
native KvGetColor(Handle:kv, const String:key[], &r, &g, &b, &a); |
|
faluco@654
|
154 |
|
|
faluco@654
|
155 |
/** |
|
faluco@654
|
156 |
* Retrieves a large integer value from a KeyValues key. |
|
faluco@654
|
157 |
* |
|
faluco@654
|
158 |
* @param kv KeyValues Handle. |
|
faluco@654
|
159 |
* @param key Name of the key. |
|
faluco@654
|
160 |
* @param value Array to represent the large integer. |
|
faluco@654
|
161 |
* @param defvalue Optional default value to use if the key is not found. |
|
faluco@654
|
162 |
* @noreturn |
|
faluco@654
|
163 |
* @error Invalid Handle. |
|
faluco@654
|
164 |
*/ |
|
faluco@654
|
165 |
native KvGetUint64(Handle:kv, const String:key[], value[2], defvalue[2]={0,0}); |
|
faluco@654
|
166 |
|
|
faluco@654
|
167 |
/** |
|
faluco@654
|
168 |
* Sets the current position in the KeyValues tree to the given key. |
|
faluco@654
|
169 |
* |
|
faluco@654
|
170 |
* @param kv KeyValues Handle. |
|
faluco@654
|
171 |
* @param key Name of the key. |
|
faluco@654
|
172 |
* @param create If true, and the key does not exist, it will be created. |
|
faluco@654
|
173 |
* @return True if the key exists, false if it does not and was not created. |
|
faluco@654
|
174 |
*/ |
|
faluco@654
|
175 |
native bool:KvJumpToKey(Handle:kv, const String:key[], bool:create=false); |
|
faluco@654
|
176 |
|
|
faluco@654
|
177 |
/** |
|
faluco@654
|
178 |
* Sets the current position in the KeyValues tree to the first sub key. |
|
faluco@654
|
179 |
* |
|
faluco@654
|
180 |
* @param kv KeyValues Handle. |
|
faluco@654
|
181 |
* @return True on success, false if there was no first sub key. |
|
faluco@654
|
182 |
* @error Invalid Handle. |
|
faluco@654
|
183 |
*/ |
|
faluco@654
|
184 |
native bool:KvJumpFirstSubKey(Handle:kv); |
|
faluco@654
|
185 |
|
|
faluco@654
|
186 |
/** |
|
faluco@654
|
187 |
* Sets the current position in the KeyValues tree to the next sub key. |
|
faluco@654
|
188 |
* |
|
faluco@654
|
189 |
* @param kv KeyValues Handle. |
|
faluco@654
|
190 |
* @return True on success, false if there was no next sub key. |
|
faluco@654
|
191 |
* @error Invalid Handle. |
|
faluco@654
|
192 |
*/ |
|
faluco@654
|
193 |
native bool:KvJumpNextSubKey(Handle:kv); |
|
faluco@654
|
194 |
|
|
faluco@654
|
195 |
/** |
|
dvander@743
|
196 |
* Removes the given key from the current position. |
|
dvander@743
|
197 |
* |
|
dvander@743
|
198 |
* @param kv KeyValues Handle. |
|
dvander@743
|
199 |
* @param key Name of the key. |
|
dvander@743
|
200 |
* @return True on success, false if key did not exist. |
|
dvander@743
|
201 |
* @error Invalid Handle. |
|
dvander@743
|
202 |
*/ |
|
dvander@743
|
203 |
native bool:KvDeleteKey(Handle:kv, const String:key[]); |
|
dvander@743
|
204 |
|
|
dvander@743
|
205 |
/** |
|
dvander@743
|
206 |
* Removes the current sub-key and jumps back one position, using the previous |
|
dvander@743
|
207 |
* position as the search point. This will not work if used on the root node. |
|
dvander@743
|
208 |
* |
|
dvander@743
|
209 |
* @param kv KeyValues Handle. |
|
dvander@743
|
210 |
* @return True on success, false if there was no sub key. |
|
dvander@743
|
211 |
* @error Invalid Handle. |
|
dvander@743
|
212 |
*/ |
|
dvander@743
|
213 |
native bool:KvDeleteThis(Handle:kv); |
|
dvander@743
|
214 |
|
|
dvander@743
|
215 |
/** |
|
faluco@654
|
216 |
* Jumps back to the previous position. Returns false if there are no |
|
faluco@654
|
217 |
* previous positions (i.e., at the root node). This should be called |
|
faluco@654
|
218 |
* once for each successful Jump call, in order to return to the top node. |
|
faluco@654
|
219 |
* |
|
faluco@654
|
220 |
* @param kv KeyValues Handle. |
|
faluco@654
|
221 |
* @return True on success, false if there is no higher node. |
|
faluco@654
|
222 |
* @error Invalid Handle. |
|
faluco@654
|
223 |
*/ |
|
faluco@654
|
224 |
native bool:KvGoBack(Handle:kv); |
|
faluco@654
|
225 |
|
|
faluco@654
|
226 |
/** |
|
faluco@654
|
227 |
* Sets the position back to the top node, emptying the entire node |
|
faluco@654
|
228 |
* traversal history. This can be used instead of looping KvGoBack() |
|
faluco@654
|
229 |
* if recursive iteration is not important. |
|
faluco@654
|
230 |
* |
|
faluco@654
|
231 |
* @param kv KeyValues Handle. |
|
faluco@654
|
232 |
* @noreturn |
|
faluco@654
|
233 |
* @error Invalid Handle. |
|
faluco@654
|
234 |
*/ |
|
faluco@654
|
235 |
native KvRewind(Handle:kv); |
|
faluco@654
|
236 |
|
|
faluco@654
|
237 |
/** |
|
faluco@654
|
238 |
* Retrieves the current section name. |
|
faluco@654
|
239 |
* |
|
faluco@654
|
240 |
* @param kv KeyValues Handle. |
|
faluco@654
|
241 |
* @param section Buffer to store the section name. |
|
faluco@654
|
242 |
* @param maxlength Maximum length of the name buffer. |
|
faluco@654
|
243 |
* @return True on success, false on failure. |
|
faluco@654
|
244 |
* @error Invalid Handle. |
|
faluco@654
|
245 |
*/ |
|
faluco@654
|
246 |
native bool:KvGetSectionName(Handle:kv, String:section[], maxlength); |
|
faluco@654
|
247 |
|
|
faluco@654
|
248 |
/** |
|
faluco@654
|
249 |
* Sets the current section name. |
|
faluco@654
|
250 |
* |
|
faluco@654
|
251 |
* @param kv KeyValues Handle. |
|
faluco@654
|
252 |
* @param section Section name. |
|
faluco@654
|
253 |
* @noreturn |
|
faluco@654
|
254 |
* @error Invalid Handle. |
|
faluco@654
|
255 |
*/ |
|
faluco@654
|
256 |
native KvSetSectionName(Handle:kv, const String:section[]); |
|
faluco@654
|
257 |
|
|
faluco@654
|
258 |
/** |
|
faluco@654
|
259 |
* Returns the data type at a key. |
|
faluco@654
|
260 |
* |
|
faluco@654
|
261 |
* @param kv KeyValues Handle. |
|
faluco@654
|
262 |
* @param key Key name. |
|
faluco@654
|
263 |
* @return KvDataType value of the key. |
|
faluco@654
|
264 |
* @error Invalid Handle. |
|
faluco@654
|
265 |
*/ |
|
faluco@654
|
266 |
native KvDataTypes:KvGetDataType(Handle:kv, const String:key[]); |
|
faluco@654
|
267 |
|
|
faluco@654
|
268 |
/** |
|
faluco@654
|
269 |
* Converts a KeyValues tree to a file. The tree is dumped |
|
faluco@654
|
270 |
* from the current position. |
|
faluco@654
|
271 |
* |
|
faluco@654
|
272 |
* @param kv KeyValues Handle. |
|
faluco@654
|
273 |
* @param file File to dump write to. |
|
faluco@654
|
274 |
* @return True on success, false otherwise. |
|
faluco@654
|
275 |
* @error Invalid Handle. |
|
faluco@654
|
276 |
*/ |
|
faluco@654
|
277 |
native bool:KeyValuesToFile(Handle:kv, const String:file[]); |
|
faluco@654
|
278 |
|
|
faluco@654
|
279 |
/** |
|
faluco@654
|
280 |
* Converts a file to a KeyValues tree. The file is read into |
|
faluco@654
|
281 |
* the current position of the tree. |
|
faluco@654
|
282 |
* |
|
faluco@654
|
283 |
* @param kv KeyValues Handle. |
|
faluco@654
|
284 |
* @param file File to read from. |
|
faluco@654
|
285 |
* @return True on success, false otherwise. |
|
faluco@654
|
286 |
* @error Invalid Handle. |
|
faluco@654
|
287 |
*/ |
|
faluco@654
|
288 |
native bool:FileToKeyValues(Handle:kv, const String:file[]); |
|
faluco@654
|
289 |
|
|
faluco@654
|
290 |
/** |
|
faluco@654
|
291 |
* Sets whether or not the KeyValues parser will read escape sequences. |
|
faluco@654
|
292 |
* For example, \n would be read as a literal newline. This defaults |
|
faluco@654
|
293 |
* to false for new KeyValues structures. |
|
faluco@654
|
294 |
* |
|
faluco@654
|
295 |
* @param kv KeyValues Handle. |
|
faluco@654
|
296 |
* @param useEscapes Whether or not to read escape sequences. |
|
faluco@654
|
297 |
* @noreturn |
|
faluco@654
|
298 |
* @error Invalid Handle. |
|
faluco@654
|
299 |
*/ |
|
faluco@654
|
300 |
native KvSetEscapeSequences(Handle:kv, bool:useEscapes); |