public/IGameConfigs.h
author David Anderson <dvander@alliedmods.net>
Thu Mar 15 20:44:23 2007 +0000 (2007-03-15)
changeset 619 6934bf39171e
parent 548 21513dce9426
child 620 e329c942cb00
permissions -rw-r--r--
random touchups that might not be so great
     1 /**
     2 * vim: set ts=4 :
     3 * ===============================================================
     4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5 * All rights reserved.
     6 * ===============================================================
     7 *
     8 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
     9 * used or modified under the Terms and Conditions of its License Agreement, 
    10 * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    11 * works must be licensed under the GNU General Public License (version 2 or 
    12 * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    13 * 
    14 * To view the latest information, see: http://www.sourcemod.net/license.php
    15 *
    16 * Version: $Id$
    17 */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    20 #define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    21 
    22 #include <IShareSys.h>
    23 
    24 /**
    25  * @file IGameConfig.h
    26  * @brief Abstracts game private data configuration.
    27  */
    28 
    29 #define SMINTERFACE_GAMECONFIG_NAME			"IGameConfigManager"
    30 #define SMINTERFACE_GAMECONFIG_VERSION		1
    31 
    32 class SendProp;
    33 
    34 namespace SourceMod
    35 {
    36 	/**
    37 	 * @brief Details the property types.
    38 	 */
    39 	enum PropType
    40 	{
    41 		PropType_Unknown = 0,		/**< Property type is not known */
    42 		PropType_Send = 1,			/**< Property type is a networkable property */
    43 		PropType_Data = 2,			/**< Property type is a data/save property */
    44 	};
    45 
    46 	enum PropError
    47 	{
    48 		PropError_Okay = 0,			/**< No error */
    49 		PropError_NotSet,			/**< Property is not set in the config file */
    50 		PropError_NotFound,			/**< Property was not found in the game */
    51 	};
    52 
    53 	#define INVALID_PROPERTY_VALUE		-1		/**< Property value is not valid */
    54 
    55 	/**
    56 	 * @brief Describes a game private data config file
    57 	 */
    58 	class IGameConfig
    59 	{
    60 	public:
    61 		/**
    62 		 * @brief Returns an offset value.
    63 		 *
    64 		 * @param key			Key to retrieve from the offset section.
    65 		 * @param value			Pointer to store the offset value in.
    66 		 * @return				True if found, false otherwise.
    67 		 */
    68 		virtual bool GetOffset(const char *key, int *value) =0;
    69 
    70 		/**
    71 		 * @brief Returns information about a dynamic offset.
    72 		 *
    73 		 * @param key			Key to retrieve from the property section.
    74 		 * @param value			Pointer to store the offset value.  Will be -1 on failure.
    75 		 * @return				A PropError error code.
    76 		 */
    77 		virtual SendProp *GetSendProp(const char *key) =0;
    78 
    79 		/**
    80 		 * @brief Returns the value of a key from the "Keys" section.
    81 		 *
    82 		 * @param key			Key to retrieve from the Keys section.
    83 		 * @return				String containing the value, or NULL if not found.
    84 		 */
    85 		virtual const char *GetKeyValue(const char *key) =0;
    86 	};
    87 
    88 	/**
    89 	 * @brief Manages game config files
    90 	 */
    91 	class IGameConfigManager : public SMInterface
    92 	{
    93 	public:
    94 		const char *GetInterfaceName()
    95 		{
    96 			return SMINTERFACE_GAMECONFIG_NAME;
    97 		}
    98 		unsigned int GetInterfaceVersion()
    99 		{
   100 			return SMINTERFACE_GAMECONFIG_VERSION;
   101 		}
   102 	public:
   103 		/**
   104 		 * @brief Loads or finds an already loaded game config file.  
   105 		 *
   106 		 * @param file		File to load.  The path must be relative to the 'gamedata'
   107 		 *					folder under the config folder, and the extension should be ommitted.
   108 		 * @param pConfig	Pointer to store the game config pointer.  Pointer will be valid even on failure.
   109 		 * @param error		Optional error message buffer.
   110 		 * @param maxlength	Maximum length of the error buffer.
   111 		 * @return			True on success, false if the file failed.
   112 		 */
   113 		virtual bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength) =0;
   114 
   115 		/**
   116 		 * @brief Closes an IGameConfig pointer.  Since a file can be loaded more than once,
   117 		 * the file will not actually be removed from memory until it is closed once for each
   118 		 * call to LoadGameConfigfile().
   119 		 *
   120 		 * @param cfg		Pointer to the IGameConfig to close.
   121 		 */
   122 		virtual void CloseGameConfigFile(IGameConfig *cfg) =0;
   123 	};
   124 }
   125 
   126 #endif //_INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_