plugins/include/keyvalues.inc
author David Anderson <dvander@alliedmods.net>
Wed May 16 01:17:14 2007 +0000 (2007-05-16)
changeset 800 432f5aed9b1e
parent 753 41f5156d0e63
child 816 f5551f32680b
permissions -rw-r--r--
fixed a bug where the JIT initiated the optimized stack top boundary check with a doubly relocated address, causing a rare bug with stack operations
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.
dvander@753
   179
 * This native adds to the internal traversal stack.
faluco@654
   180
 *
faluco@654
   181
 * @param kv			KeyValues Handle.
dvander@753
   182
 * @param keyOnly		If false, non-keys will be traversed (values).
faluco@654
   183
 * @return				True on success, false if there was no first sub key.
faluco@654
   184
 * @error				Invalid Handle.
faluco@654
   185
 */
dvander@753
   186
native bool:KvGotoFirstSubKey(Handle:kv, bool:keyOnly=true);
faluco@654
   187
faluco@654
   188
/**
faluco@654
   189
 * Sets the current position in the KeyValues tree to the next sub key.
dvander@753
   190
 * This native does NOT add to the internal traversal stack, and thus
dvander@753
   191
 * KvGoBack() is not needed for each successive call to this function.
faluco@654
   192
 *
faluco@654
   193
 * @param kv			KeyValues Handle.
dvander@753
   194
 * @param keyOnly		If false, non-keys will be traversed (values).
faluco@654
   195
 * @return				True on success, false if there was no next sub key.
faluco@654
   196
 * @error				Invalid Handle.
faluco@654
   197
 */
dvander@753
   198
native bool:KvGotoNextKey(Handle:kv, bool:keyOnly=true);
dvander@753
   199
dvander@753
   200
/**
dvander@753
   201
 * Saves the current position in the traversal stack onto the traversal
dvander@753
   202
 * stack.  This can be useful if you wish to use KvGotoNextKey() and 
dvander@753
   203
 * have the previous key saved for backwards traversal.
dvander@753
   204
 *
dvander@753
   205
 * @param kv			KeyValues Handle.
dvander@753
   206
 * @noreturn
dvander@753
   207
 * @error				Invalid Handle.
dvander@753
   208
 */
dvander@753
   209
native KvSavePosition(Handle:kv);
faluco@654
   210
faluco@654
   211
/**
dvander@743
   212
 * Removes the given key from the current position.
dvander@743
   213
 *
dvander@743
   214
 * @param kv			KeyValues Handle.
dvander@743
   215
 * @param key			Name of the key.
dvander@743
   216
 * @return				True on success, false if key did not exist.
dvander@743
   217
 * @error				Invalid Handle.
dvander@743
   218
 */
dvander@743
   219
native bool:KvDeleteKey(Handle:kv, const String:key[]);
dvander@743
   220
dvander@743
   221
/**
dvander@753
   222
 * Removes the current sub-key and attempts to set the position
dvander@753
   223
 * to the sub-key after the removed one.  If no such sub-key exists,
dvander@753
   224
 * the position will be the parent key in the traversal stack.
dvander@753
   225
 * Given the sub-key having position "N" in the traversal stack, the 
dvander@753
   226
 * removal will always take place from position "N-1."
dvander@743
   227
 *
dvander@743
   228
 * @param kv			KeyValues Handle.
dvander@753
   229
 * @return				1 if removal succeeded and there was another key.
dvander@753
   230
 *						0 if the current node was not contained in the
dvander@753
   231
 *						  previous node, or no previous node exists.
dvander@753
   232
 *						-1 if removal succeeded and there were no more keys,
dvander@753
   233
 *						  thus the state is as if KvGoBack() was called.
dvander@743
   234
 * @error				Invalid Handle.
dvander@743
   235
 */
dvander@753
   236
native KvDeleteThis(Handle:kv);
dvander@743
   237
dvander@743
   238
/**
faluco@654
   239
 * Jumps back to the previous position.  Returns false if there are no
faluco@654
   240
 * previous positions (i.e., at the root node).  This should be called
faluco@654
   241
 * once for each successful Jump call, in order to return to the top node.
dvander@753
   242
 * This function pops one node off the internal traversal stack.
faluco@654
   243
 *
faluco@654
   244
 * @param kv			KeyValues Handle.
faluco@654
   245
 * @return				True on success, false if there is no higher node.
faluco@654
   246
 * @error				Invalid Handle.
faluco@654
   247
 */
faluco@654
   248
native bool:KvGoBack(Handle:kv);
faluco@654
   249
faluco@654
   250
/**
faluco@654
   251
 * Sets the position back to the top node, emptying the entire node 
faluco@654
   252
 * traversal history.  This can be used instead of looping KvGoBack()
faluco@654
   253
 * if recursive iteration is not important.
faluco@654
   254
 *
faluco@654
   255
 * @param kv			KeyValues Handle.
faluco@654
   256
 * @noreturn
faluco@654
   257
 * @error				Invalid Handle.
faluco@654
   258
 */
faluco@654
   259
native KvRewind(Handle:kv);
faluco@654
   260
faluco@654
   261
/**
faluco@654
   262
 * Retrieves the current section name.
faluco@654
   263
 * 
faluco@654
   264
 * @param kv			KeyValues Handle.
faluco@654
   265
 * @param section		Buffer to store the section name.
faluco@654
   266
 * @param maxlength		Maximum length of the name buffer.
faluco@654
   267
 * @return				True on success, false on failure.
faluco@654
   268
 * @error				Invalid Handle.
faluco@654
   269
 */
faluco@654
   270
native bool:KvGetSectionName(Handle:kv, String:section[], maxlength);
faluco@654
   271
faluco@654
   272
/**
faluco@654
   273
 * Sets the current section name.
faluco@654
   274
 * 
faluco@654
   275
 * @param kv			KeyValues Handle.
faluco@654
   276
 * @param section		Section name.
faluco@654
   277
 * @noreturn
faluco@654
   278
 * @error				Invalid Handle.
faluco@654
   279
 */
faluco@654
   280
native KvSetSectionName(Handle:kv, const String:section[]);
faluco@654
   281
faluco@654
   282
/**
faluco@654
   283
 * Returns the data type at a key.
faluco@654
   284
 *
faluco@654
   285
 * @param kv			KeyValues Handle.
faluco@654
   286
 * @param key			Key name.
faluco@654
   287
 * @return				KvDataType value of the key.
faluco@654
   288
 * @error				Invalid Handle.
faluco@654
   289
 */
faluco@654
   290
native KvDataTypes:KvGetDataType(Handle:kv, const String:key[]);
faluco@654
   291
faluco@654
   292
/**
faluco@654
   293
 * Converts a KeyValues tree to a file.  The tree is dumped
faluco@654
   294
 * from the current position.
faluco@654
   295
 *
faluco@654
   296
 * @param kv			KeyValues Handle.
faluco@654
   297
 * @param file			File to dump write to.
faluco@654
   298
 * @return				True on success, false otherwise.
faluco@654
   299
 * @error				Invalid Handle.
faluco@654
   300
 */
faluco@654
   301
native bool:KeyValuesToFile(Handle:kv, const String:file[]);
faluco@654
   302
faluco@654
   303
/**
faluco@654
   304
 * Converts a file to a KeyValues tree.  The file is read into
faluco@654
   305
 * the current position of the tree.
faluco@654
   306
 *
faluco@654
   307
 * @param kv			KeyValues Handle.
faluco@654
   308
 * @param file			File to read from.
faluco@654
   309
 * @return				True on success, false otherwise.
faluco@654
   310
 * @error				Invalid Handle.
faluco@654
   311
 */
faluco@654
   312
native bool:FileToKeyValues(Handle:kv, const String:file[]);
faluco@654
   313
faluco@654
   314
/**
faluco@654
   315
 * Sets whether or not the KeyValues parser will read escape sequences.
faluco@654
   316
 * For example, \n would be read as a literal newline.  This defaults
faluco@654
   317
 * to false for new KeyValues structures.
faluco@654
   318
 *
faluco@654
   319
 * @param kv			KeyValues Handle.
faluco@654
   320
 * @param useEscapes	Whether or not to read escape sequences.
faluco@654
   321
 * @noreturn
faluco@654
   322
 * @error				Invalid Handle.
faluco@654
   323
 */
faluco@654
   324
native KvSetEscapeSequences(Handle:kv, bool:useEscapes);
dvander@750
   325
dvander@750
   326
/**
dvander@750
   327
 * Returns the position in the jump stack; I.e. the number of calls
dvander@750
   328
 * required for KvGoBack to return to the root node.  If at the root node,
dvander@750
   329
 * 0 is returned.
dvander@750
   330
 *
dvander@750
   331
 * @param kv			KeyValues Handle.
dvander@750
   332
 * @return				Number of non-root nodes in the jump stack.
dvander@750
   333
 * @error				Invalid Handle.
dvander@750
   334
 */
dvander@750
   335
native KvNodesInStack(Handle:kv);