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