Planeshift
psoptions.h
Go to the documentation of this file.
1 /*
2  * Author: Andrew Robberts
3  *
4  * Copyright (C) 2007 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef PS_OPTIONS_H
21 #define PS_OPTIONS_H
22 
23 #include <csutil/hash.h>
24 #include <csgeom/vector2.h>
25 #include <csgeom/vector3.h>
26 #include <iutil/cfgfile.h>
27 #include <csutil/csstring.h>
28 
29 #include "paws/pawsmanager.h"
30 #include "util/scriptvar.h"
31 
33 {
34  virtual ~iOptionsClass() {}
35 
41  virtual void LoadOptions() = 0;
42 
48  virtual void SaveOptions() = 0;
49 };
50 
52 {
53 private:
54  csHash<iOptionsClass *> optionsClasses;
55  csRef<iConfigFile> configFile;
56  csHash<csString, csString> subscriptions;
57  csString filename;
58 
59  void BuildKey(csString & result, const char * className, const char * optionName) const;
60  void EnsureSubscription(const char * name);
61 
62 public:
63  psOptions(const char * filename, iVFS* vfs);
64  ~psOptions();
65 
66  // inherited from iPAWSSubscriber
67  void OnUpdateData(const char *name, PAWSData& data);
68  void NewSubscription(const char *name);
69 
70  // inherited from iScriptableVar
71  double GetProperty(MathEnvironment* env, const char* ptr);
72  double CalcFunction(MathEnvironment* env, const char* functionName, const double* params);
73  const char * ToString() { return "options"; }
74 
78  void RegisterOptionsClass(const char * className, iOptionsClass * optionsClass);
79 
83  void SetOption(const char * className, const char * name, const char * value);
84  void SetOption(const char * className, const char * name, float value);
85  void SetOption(const char * className, const char * name, int value);
86  void SetOption(const char * className, const char * name, bool value);
87 
91  const char * GetOption(const char * className, const char * name, const char * defaultValue);
92  float GetOption(const char * className, const char * name, float defaultValue);
93  int GetOption(const char * className, const char * name, int defaultValue);
94  bool GetOption(const char * className, const char * name, bool defaultValue);
95 
99  void Save();
100 
104  void Load();
105 };
106 
107 #endif // PS_OPTIONS_H
virtual void SaveOptions()=0
This function is called whenever the options system needs the options class to give it its options va...
A specific MathEnvironment to be used in a MathScript.
Definition: mathscript.h:188
virtual void LoadOptions()=0
This function is called when the options system has been issued a Save() call.
virtual ~iOptionsClass()
Definition: psoptions.h:34
const char * ToString()
Definition: psoptions.h:73