core/GameConfigs.h
author David Anderson <dvander@alliedmods.net>
Fri Jun 01 02:30:29 2007 +0000 (2007-06-01)
changeset 868 bdbf922e246f
parent 616 d5b1dcf38c07
child 947 04dcaa8312e7
permissions -rw-r--r--
-initial import of database natives + config
-initial import of completed database layer
-CreateIdentity now requires a non-optional second pointer. This breaks backwards compatibility for CreateIdentity(), however, this is not a function extension authors are supposed to be calling
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_CGAMECONFIGS_H_
    16 #define _INCLUDE_SOURCEMOD_CGAMECONFIGS_H_
    17 
    18 #include <IGameConfigs.h>
    19 #include <ITextParsers.h>
    20 #include <sh_list.h>
    21 #include "sm_trie.h"
    22 #include "sm_globals.h"
    23 #include "sm_memtable.h"
    24 
    25 using namespace SourceMod;
    26 using namespace SourceHook;
    27 
    28 class SendProp;
    29 
    30 class CGameConfig : 
    31 	public ITextListener_SMC,
    32 	public IGameConfig
    33 {
    34 public:
    35 	CGameConfig(const char *file);
    36 	~CGameConfig();
    37 public:
    38 	bool Reparse(char *error, size_t maxlength);
    39 public: //ITextListener_SMC
    40 	SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
    41 	SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
    42 	SMCParseResult ReadSMC_LeavingSection();
    43 public: //IGameConfig
    44 	const char *GetKeyValue(const char *key);
    45 	bool GetOffset(const char *key, int *value);
    46 	SendProp *GetSendProp(const char *key);
    47 public:
    48 	void IncRefCount();
    49 	unsigned int DecRefCount();
    50 private:
    51 	BaseStringTable *m_pStrings;
    52 	char *m_pFile;
    53 	Trie *m_pOffsets;
    54 	Trie *m_pProps;
    55 	Trie *m_pKeys;
    56 	unsigned int m_RefCount;
    57 	/* Parse states */
    58 	int m_ParseState;
    59 	unsigned int m_IgnoreLevel;
    60 	char m_class[64];
    61 	char m_prop[64];
    62 	char m_offset[64];
    63 	char m_mod[255];
    64 };
    65 
    66 class GameConfigManager : 
    67 	public IGameConfigManager,
    68 	public SMGlobalClass
    69 {
    70 public:
    71 	GameConfigManager();
    72 	~GameConfigManager();
    73 public: //IGameConfigManager
    74 	bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength);
    75 	void CloseGameConfigFile(IGameConfig *cfg);
    76 public: //SMGlobalClass
    77 	void OnSourceModStartup(bool late);
    78 	void OnSourceModAllInitialized();
    79 	void OnSourceModAllShutdown();
    80 private:
    81 	List<CGameConfig *> m_cfgs;
    82 	Trie *m_pLookup;
    83 };
    84 
    85 extern GameConfigManager g_GameConfigs;
    86 extern IGameConfig *g_pGameConf;
    87 
    88 #endif //_INCLUDE_SOURCEMOD_CGAMECONFIGS_H_