ds@1952: /**
ds@1952: * vim: set ts=4 :
ds@1952: * =============================================================================
ds@1952: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
ds@1952: * =============================================================================
ds@1952: *
ds@1952: * This file is part of the SourceMod/SourcePawn SDK.
ds@1952: *
ds@1952: * This program is free software; you can redistribute it and/or modify it under
ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952: * Free Software Foundation.
ds@1952: *
ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1952: * details.
ds@1952: *
ds@1952: * You should have received a copy of the GNU General Public License along with
ds@1952: * this program. If not, see .
ds@1952: *
ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1952: * this exception to all derivative works. AlliedModders LLC defines further
ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952: * or .
ds@1952: *
ds@1952: * Version: $Id$
ds@1952: */
ds@1952:
ds@1952: #if defined _keyvalues_included
ds@1952: #endinput
ds@1952: #endif
ds@1952: #define _keyvalues_included
ds@1952:
ds@1952: /**
ds@1952: * KeyValue data value types
ds@1952: */
ds@1952: enum KvDataTypes
ds@1952: {
ds@1952: KvData_None = 0, /**< Type could not be identified, or no type */
ds@1952: KvData_String, /**< String value */
ds@1952: KvData_Int, /**< Integer value */
ds@1952: KvData_Float, /**< Floating point value */
ds@1952: KvData_Ptr, /**< Pointer value (sometimes called "long") */
ds@1952: KvData_WString, /**< Wide string value */
ds@1952: KvData_Color, /**< Color value */
ds@1952: KvData_UInt64, /**< Large integer value */
ds@1952: /* --- */
ds@1952: KvData_NUMTYPES,
ds@1952: };
ds@1952:
ds@1952: /**
ds@1952: * Creates a new KeyValues structure. The Handle must always be closed.
ds@1952: *
ds@1952: * @param name Name of the root section.
ds@1952: * @param firstKey If non-empty, specifies the first key value.
ds@1952: * @param firstValue If firstKey is non-empty, specifies the first key's value.
ds@1952: * @return A Handle to a new KeyValues structure.
ds@1952: */
ds@1952: native Handle:CreateKeyValues(const String:name[], const String:firstkey[]="", const String:firstValue[]="");
ds@1952:
ds@1952: /**
ds@1952: * Sets a string value of a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param value String value.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetString(Handle:kv, const String:key[], const String:value[]);
ds@1952:
ds@1952: /**
ds@1952: * Sets an integer value of a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param value Value number.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetNum(Handle:kv, const String:key[], value);
ds@1952:
ds@1952: /**
ds@1952: * Sets a large integer value of a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param value Large integer value (0=High bits, 1=Low bits)
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetUInt64(Handle:kv, const String:key[], const value[2]);
ds@1952:
ds@1952: /**
ds@1952: * Sets a floating point value of a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param value Floating point value.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetFloat(Handle:kv, const String:key[], Float:value);
ds@1952:
ds@1952: /**
ds@1952: * Sets a set of color values of a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param r Red value.
ds@1952: * @param g Green value.
ds@1952: * @param b Blue value.
ds@1952: * @param a Alpha value.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetColor(Handle:kv, const String:key[], r, g, b, a=0);
ds@1952:
ds@1952: /**
ds@1952: * Sets a vector value of a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param vec Vector value.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetVector(Handle:kv, const String:key[], const Float:vec[3]);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves a string value from a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param value Buffer to store key value in.
ds@1952: * @param maxlength Maximum length of the value buffer.
ds@1952: * @param defvalue Optional default value to use if the key is not found.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvGetString(Handle:kv, const String:key[], String:value[], maxlength, const String:defvalue[]="");
ds@1952:
ds@1952: /**
ds@1952: * Retrieves an integer value from a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param defvalue Optional default value to use if the key is not found.
ds@1952: * @return Integer value of the key.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvGetNum(Handle:kv, const String:key[], defvalue=0);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves a floating point value from a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param defvalue Optional default value to use if the key is not found.
ds@1952: * @return Floating point value of the key.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native Float:KvGetFloat(Handle:kv, const String:key[], Float:defvalue=0.0);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves a set of color values from a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param r Red value, set by reference.
ds@1952: * @param g Green value, set by reference.
ds@1952: * @param b Blue value, set by reference.
ds@1952: * @param a Alpha value, set by reference.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvGetColor(Handle:kv, const String:key[], &r, &g, &b, &a);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves a large integer value from a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param value Array to represent the large integer.
ds@1952: * @param defvalue Optional default value to use if the key is not found.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvGetUInt64(Handle:kv, const String:key[], value[2], defvalue[2]={0,0});
ds@1952:
ds@1952: /**
ds@1952: * Retrieves a vector value from a KeyValues key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key, or NULL_STRING.
ds@1952: * @param vec Destination vector to store the value in.
ds@1952: * @param defvalue Optional default value to use if the key is not found.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvGetVector(Handle:kv, const String:key[], Float:vec[3], const Float:defvalue[3]={0.0, 0.0, 0.0});
ds@1952:
ds@1952: /**
ds@1952: * Sets the current position in the KeyValues tree to the given key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key.
ds@1952: * @param create If true, and the key does not exist, it will be created.
ds@1952: * @return True if the key exists, false if it does not and was not created.
ds@1952: */
ds@1952: native bool:KvJumpToKey(Handle:kv, const String:key[], bool:create=false);
ds@1952:
ds@1952: /**
ds@1952: * Sets the current position in the KeyValues tree to the given key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param id KeyValues id.
ds@1952: * @return True if the key exists, false if it does not.
ds@1952: */
ds@1952: native bool:KvJumpToKeySymbol(Handle:kv, id);
ds@1952:
ds@1952: /**
ds@1952: * Sets the current position in the KeyValues tree to the first sub key.
ds@1952: * This native adds to the internal traversal stack.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param keyOnly If false, non-keys will be traversed (values).
ds@1952: * @return True on success, false if there was no first sub key.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvGotoFirstSubKey(Handle:kv, bool:keyOnly=true);
ds@1952:
ds@1952: /**
ds@1952: * Sets the current position in the KeyValues tree to the next sub key.
ds@1952: * This native does NOT add to the internal traversal stack, and thus
ds@1952: * KvGoBack() is not needed for each successive call to this function.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param keyOnly If false, non-keys will be traversed (values).
ds@1952: * @return True on success, false if there was no next sub key.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvGotoNextKey(Handle:kv, bool:keyOnly=true);
ds@1952:
ds@1952: /**
ds@1952: * Saves the current position in the traversal stack onto the traversal
ds@1952: * stack. This can be useful if you wish to use KvGotoNextKey() and
ds@1952: * have the previous key saved for backwards traversal.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSavePosition(Handle:kv);
ds@1952:
ds@1952: /**
ds@1952: * Removes the given key from the current position.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Name of the key.
ds@1952: * @return True on success, false if key did not exist.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvDeleteKey(Handle:kv, const String:key[]);
ds@1952:
ds@1952: /**
ds@1952: * Removes the current sub-key and attempts to set the position
ds@1952: * to the sub-key after the removed one. If no such sub-key exists,
ds@1952: * the position will be the parent key in the traversal stack.
ds@1952: * Given the sub-key having position "N" in the traversal stack, the
ds@1952: * removal will always take place from position "N-1."
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @return 1 if removal succeeded and there was another key.
ds@1952: * 0 if the current node was not contained in the
ds@1952: * previous node, or no previous node exists.
ds@1952: * -1 if removal succeeded and there were no more keys,
ds@1952: * thus the state is as if KvGoBack() was called.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvDeleteThis(Handle:kv);
ds@1952:
ds@1952: /**
ds@1952: * Jumps back to the previous position. Returns false if there are no
ds@1952: * previous positions (i.e., at the root node). This should be called
ds@1952: * once for each successful Jump call, in order to return to the top node.
ds@1952: * This function pops one node off the internal traversal stack.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @return True on success, false if there is no higher node.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvGoBack(Handle:kv);
ds@1952:
ds@1952: /**
ds@1952: * Sets the position back to the top node, emptying the entire node
ds@1952: * traversal history. This can be used instead of looping KvGoBack()
ds@1952: * if recursive iteration is not important.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvRewind(Handle:kv);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves the current section name.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param section Buffer to store the section name.
ds@1952: * @param maxlength Maximum length of the name buffer.
ds@1952: * @return True on success, false on failure.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvGetSectionName(Handle:kv, String:section[], maxlength);
ds@1952:
ds@1952: /**
ds@1952: * Sets the current section name.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param section Section name.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetSectionName(Handle:kv, const String:section[]);
ds@1952:
ds@1952: /**
ds@1952: * Returns the data type at a key.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Key name.
ds@1952: * @return KvDataType value of the key.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvDataTypes:KvGetDataType(Handle:kv, const String:key[]);
ds@1952:
ds@1952: /**
ds@1952: * Converts a KeyValues tree to a file. The tree is dumped
ds@1952: * from the current position.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param file File to dump write to.
ds@1952: * @return True on success, false otherwise.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KeyValuesToFile(Handle:kv, const String:file[]);
ds@1952:
ds@1952: /**
ds@1952: * Converts a file to a KeyValues tree. The file is read into
ds@1952: * the current position of the tree.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param file File to read from.
ds@1952: * @return True on success, false otherwise.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:FileToKeyValues(Handle:kv, const String:file[]);
ds@1952:
ds@1952: /**
ds@1952: * Sets whether or not the KeyValues parser will read escape sequences.
ds@1952: * For example, \n would be read as a literal newline. This defaults
ds@1952: * to false for new KeyValues structures.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param useEscapes Whether or not to read escape sequences.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvSetEscapeSequences(Handle:kv, bool:useEscapes);
ds@1952:
ds@1952: /**
ds@1952: * Returns the position in the jump stack; I.e. the number of calls
ds@1952: * required for KvGoBack to return to the root node. If at the root node,
ds@1952: * 0 is returned.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @return Number of non-root nodes in the jump stack.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvNodesInStack(Handle:kv);
ds@1952:
ds@1952: /**
ds@1952: * Makes a new copy of all subkeys in the origin KeyValues to
ds@1952: * the destination KeyValues.
ds@1952: * NOTE: All KeyValues are processed from the current location not the root one.
ds@1952: *
ds@1952: * @param origin Origin KeyValues Handle.
ds@1952: * @param dest Destination KeyValues Handlee.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native KvCopySubkeys(Handle:origin, Handle:dest);
ds@1952:
ds@1952: /**
ds@1952: * Finds a KeyValues name by id.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param id KeyValues id.
ds@1952: * @param name Buffer to store the name.
ds@1952: * @param maxlength Maximum length of the value buffer.
ds@1952: * @return True on success, false if id not found.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvFindKeyById(Handle:kv, id, String:name[], maxlength);
ds@1952:
ds@1952: /**
ds@1952: * Finds a KeyValues id inside a KeyValues tree.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param key Key name.
ds@1952: * @param id Id of the found KeyValue.
ds@1952: * @return True on success, false if key not found.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvGetNameSymbol(Handle:kv, const String:key[], &id);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves the current section id.
ds@1952: *
ds@1952: * @param kv KeyValues Handle.
ds@1952: * @param id Id of the current section.
ds@1952: * @return True on success, false on failure.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:KvGetSectionSymbol(Handle:kv, &id);