core/PluginInfoDatabase.h
changeset 2415 9ac720a36ce4
parent 2411 8dfaa3d730b5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/PluginInfoDatabase.h	Wed Nov 19 02:16:45 2008 -0600
     1.3 @@ -0,0 +1,106 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod
     1.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     1.9 + * =============================================================================
    1.10 + *
    1.11 + * This program is free software; you can redistribute it and/or modify it under
    1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 + * Free Software Foundation.
    1.14 + * 
    1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 + * details.
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License along with
    1.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 + *
    1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 + * or <http://www.sourcemod.net/license.php>.
    1.31 + *
    1.32 + * Version: $Id$
    1.33 + */
    1.34 +
    1.35 +#ifndef _INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
    1.36 +#define _INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
    1.37 +
    1.38 +/**
    1.39 + * This file parses plugin_settings.cfg and stores the information in cached memory.
    1.40 + * It provides simplistic abstraction to retrieving the info.
    1.41 + * :TODO: currently untested
    1.42 + */
    1.43 +
    1.44 +#include "sm_memtable.h"
    1.45 +#include "ITextParsers.h"
    1.46 +#include "IPluginSys.h"
    1.47 +#include "sm_globals.h"
    1.48 +
    1.49 +struct PluginOpts
    1.50 +{
    1.51 +	int key;
    1.52 +	int val;
    1.53 +};
    1.54 +
    1.55 +struct PluginSettings
    1.56 +{
    1.57 +	void Init();
    1.58 +	int name;
    1.59 +	bool pause_val;
    1.60 +	PluginType type_val;
    1.61 +	int optarray;
    1.62 +	size_t opts_num;
    1.63 +	size_t opts_size;
    1.64 +	bool blockload_val;
    1.65 +};
    1.66 +
    1.67 +class CPluginInfoDatabase : public ITextListener_SMC
    1.68 +{
    1.69 +public:
    1.70 +	CPluginInfoDatabase();
    1.71 +	~CPluginInfoDatabase();
    1.72 +public: //ITextListener_SMC
    1.73 +	void ReadSMC_ParseStart();
    1.74 +	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
    1.75 +	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
    1.76 +	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
    1.77 +public:
    1.78 +	/**
    1.79 +	 * Returns the number of plugin settings available.
    1.80 +	 */
    1.81 +	unsigned int GetSettingsNum();
    1.82 +
    1.83 +	/** 
    1.84 +	 * Given an index, returns the plugin settings block if the filename matches.
    1.85 +	 * Otherwise, returns NULL.
    1.86 +	 */
    1.87 +	PluginSettings *GetSettingsIfMatch(unsigned int index, const char *filename);
    1.88 +
    1.89 +	/** 
    1.90 +	 *  Given a plugin settings struct and an index,
    1.91 +	 * returns the given JIT key/value option pair at that index.
    1.92 +	 * If the input is invalid, key and val will be set to NULL.
    1.93 +	 */
    1.94 +	void GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val);
    1.95 +private:
    1.96 +	SMCResult MakeError(const char *fmt, ...);
    1.97 +private:
    1.98 +	BaseStringTable *m_strtab;
    1.99 +	int m_errmsg;
   1.100 +	bool in_plugins;
   1.101 +	bool in_options;
   1.102 +	int m_infodb;
   1.103 +	size_t m_infodb_count;
   1.104 +	size_t m_infodb_size;
   1.105 +	int cur_plugin;
   1.106 +};
   1.107 +
   1.108 +
   1.109 +#endif //_INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_