plugins/include/keyvalues.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Apr 05 10:55:40 2007 +0000 (2007-04-05)
changeset 669 ce01c2eb020c
parent 654 e00dd6df311e
child 725 1bf5d68415d5
permissions -rw-r--r--
Various things:
- Fixed inline translations when using %T
- "Improved" caching of server language
- Renamed Translator::GetServerLanguageCode() to GetServerLanguage()
- Added some more comments to sm_globals.h
- Natives folder in project file mysteriously was moved inside Interfaces, so moved it back o_O
- DS hates empty if statements :o
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
 */
faluco@654
    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
/**
faluco@654
   196
 * Jumps back to the previous position.  Returns false if there are no
faluco@654
   197
 * previous positions (i.e., at the root node).  This should be called
faluco@654
   198
 * once for each successful Jump call, in order to return to the top node.
faluco@654
   199
 *
faluco@654
   200
 * @param kv			KeyValues Handle.
faluco@654
   201
 * @return				True on success, false if there is no higher node.
faluco@654
   202
 * @error				Invalid Handle.
faluco@654
   203
 */
faluco@654
   204
native bool:KvGoBack(Handle:kv);
faluco@654
   205
faluco@654
   206
/**
faluco@654
   207
 * Sets the position back to the top node, emptying the entire node 
faluco@654
   208
 * traversal history.  This can be used instead of looping KvGoBack()
faluco@654
   209
 * if recursive iteration is not important.
faluco@654
   210
 *
faluco@654
   211
 * @param kv			KeyValues Handle.
faluco@654
   212
 * @noreturn
faluco@654
   213
 * @error				Invalid Handle.
faluco@654
   214
 */
faluco@654
   215
native KvRewind(Handle:kv);
faluco@654
   216
faluco@654
   217
/**
faluco@654
   218
 * Retrieves the current section name.
faluco@654
   219
 * 
faluco@654
   220
 * @param kv			KeyValues Handle.
faluco@654
   221
 * @param section		Buffer to store the section name.
faluco@654
   222
 * @param maxlength		Maximum length of the name buffer.
faluco@654
   223
 * @return				True on success, false on failure.
faluco@654
   224
 * @error				Invalid Handle.
faluco@654
   225
 */
faluco@654
   226
native bool:KvGetSectionName(Handle:kv, String:section[], maxlength);
faluco@654
   227
faluco@654
   228
/**
faluco@654
   229
 * Sets the current section name.
faluco@654
   230
 * 
faluco@654
   231
 * @param kv			KeyValues Handle.
faluco@654
   232
 * @param section		Section name.
faluco@654
   233
 * @noreturn
faluco@654
   234
 * @error				Invalid Handle.
faluco@654
   235
 */
faluco@654
   236
native KvSetSectionName(Handle:kv, const String:section[]);
faluco@654
   237
faluco@654
   238
/**
faluco@654
   239
 * Returns the data type at a key.
faluco@654
   240
 *
faluco@654
   241
 * @param kv			KeyValues Handle.
faluco@654
   242
 * @param key			Key name.
faluco@654
   243
 * @return				KvDataType value of the key.
faluco@654
   244
 * @error				Invalid Handle.
faluco@654
   245
 */
faluco@654
   246
native KvDataTypes:KvGetDataType(Handle:kv, const String:key[]);
faluco@654
   247
faluco@654
   248
/**
faluco@654
   249
 * Converts a KeyValues tree to a file.  The tree is dumped
faluco@654
   250
 * from the current position.
faluco@654
   251
 *
faluco@654
   252
 * @param kv			KeyValues Handle.
faluco@654
   253
 * @param file			File to dump write to.
faluco@654
   254
 * @return				True on success, false otherwise.
faluco@654
   255
 * @error				Invalid Handle.
faluco@654
   256
 */
faluco@654
   257
native bool:KeyValuesToFile(Handle:kv, const String:file[]);
faluco@654
   258
faluco@654
   259
/**
faluco@654
   260
 * Converts a file to a KeyValues tree.  The file is read into
faluco@654
   261
 * the current position of the tree.
faluco@654
   262
 *
faluco@654
   263
 * @param kv			KeyValues Handle.
faluco@654
   264
 * @param file			File to read from.
faluco@654
   265
 * @return				True on success, false otherwise.
faluco@654
   266
 * @error				Invalid Handle.
faluco@654
   267
 */
faluco@654
   268
native bool:FileToKeyValues(Handle:kv, const String:file[]);
faluco@654
   269
faluco@654
   270
/**
faluco@654
   271
 * Sets whether or not the KeyValues parser will read escape sequences.
faluco@654
   272
 * For example, \n would be read as a literal newline.  This defaults
faluco@654
   273
 * to false for new KeyValues structures.
faluco@654
   274
 *
faluco@654
   275
 * @param kv			KeyValues Handle.
faluco@654
   276
 * @param useEscapes	Whether or not to read escape sequences.
faluco@654
   277
 * @noreturn
faluco@654
   278
 * @error				Invalid Handle.
faluco@654
   279
 */
faluco@654
   280
native KvSetEscapeSequences(Handle:kv, bool:useEscapes);