Planeshift

psoptions.h

Go to the documentation of this file.
00001 /*
00002  * Author: Andrew Robberts
00003  *
00004  * Copyright (C) 2007 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef PS_OPTIONS_H
00021 #define PS_OPTIONS_H
00022 
00023 #include <csutil/hash.h>
00024 #include <csgeom/vector2.h>
00025 #include <csgeom/vector3.h>
00026 #include <iutil/cfgfile.h>
00027 #include <csutil/csstring.h>
00028 
00029 #include "paws/pawsmanager.h"
00030 #include "util/scriptvar.h"
00031 
00032 struct iOptionsClass
00033 {
00034     virtual ~iOptionsClass() {}
00035 
00041     virtual void LoadOptions() = 0;
00042 
00048     virtual void SaveOptions() = 0;
00049 };
00050 
00051 class psOptions : public iPAWSSubscriber, public iScriptableVar
00052 {
00053 private:
00054     csHash<iOptionsClass *> optionsClasses;
00055     csRef<iConfigFile> configFile;
00056     csHash<csString, csString> subscriptions;
00057     csString filename;
00058 
00059     void BuildKey(csString & result, const char * className, const char * optionName) const;
00060     void EnsureSubscription(const char * name);
00061 
00062 public:
00063     psOptions(const char * filename, iVFS* vfs);
00064     ~psOptions();
00065 
00066     // inherited from iPAWSSubscriber
00067     void OnUpdateData(const char *name, PAWSData& data);
00068     void NewSubscription(const char *name);
00069 
00070     // inherited from iScriptableVar
00071     double GetProperty(MathEnvironment* env, const char* ptr);
00072     double CalcFunction(MathEnvironment* env, const char* functionName, const double* params);
00073     const char * ToString() { return "options"; }
00074 
00078     void RegisterOptionsClass(const char * className, iOptionsClass * optionsClass);
00079 
00083     void SetOption(const char * className, const char * name, const char * value);
00084     void SetOption(const char * className, const char * name, float value);
00085     void SetOption(const char * className, const char * name, int value);
00086     void SetOption(const char * className, const char * name, bool value);
00087 
00091     const char *      GetOption(const char * className, const char * name, const char * defaultValue);
00092     float             GetOption(const char * className, const char * name, float defaultValue);
00093     int               GetOption(const char * className, const char * name, int defaultValue);
00094     bool              GetOption(const char * className, const char * name, bool defaultValue);
00095 
00099     void Save();
00100 
00104     void Load();
00105 };
00106 
00107 #endif // PS_OPTIONS_H