renamed alot of types; hope this will not break the game
[k8-i-v-a-n.git] / src / felib / config.h
blob5a1dd86258b8bf938a9a670cc65de0f10ce302f3
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __FELIB_CONFIG_H__
13 #define __FELIB_CONFIG_H__
15 #include <fstream>
17 #include "festring.h"
20 class inputfile;
21 class felist;
22 struct configoption;
23 struct stringoption;
24 struct numberoption;
25 struct truthoption;
28 class configsystem {
29 public:
30 static truth Save ();
31 static truth Load ();
32 static void Show (void (*)() = 0, void (*)(felist&) = 0, truth = false);
33 static void AddOption (configoption *);
34 static void NormalStringDisplayer (const stringoption *, festring &);
35 static void NormalNumberDisplayer (const numberoption *, festring &);
36 static void NormalTruthDisplayer (const truthoption *, festring &);
37 static truth NormalStringChangeInterface (stringoption *);
38 static truth NormalNumberChangeInterface (numberoption *);
39 static truth NormalTruthChangeInterface (truthoption *);
40 static void NormalStringChanger (stringoption *, cfestring &);
41 static void NormalNumberChanger (numberoption *, sLong);
42 static void NormalTruthChanger (truthoption *, truth);
43 static void SetConfigFileName (cfestring &What) { ConfigFileName = What; }
45 private:
46 static configoption *Option[MAX_CONFIG_OPTIONS];
47 static festring ConfigFileName;
48 static int Options;
52 /* Currently there's no human-readable output option in outputfile, so we're forced to use std::ofstream */
53 struct configoption {
54 configoption (cchar *, cchar *);
55 virtual ~configoption () {}
56 virtual void SaveValue (std::ofstream &) const = 0;
57 virtual void LoadValue (inputfile &) = 0;
58 virtual truth ActivateChangeInterface () = 0;
59 virtual void DisplayeValue (festring &) const = 0;
60 cchar *Name;
61 cchar *Description;
65 struct stringoption : public configoption {
66 stringoption(cchar*, cchar*, cfestring&,
67 void (*)(const stringoption*, festring&)
68 = &configsystem::NormalStringDisplayer,
69 truth (*)(stringoption*)
70 = &configsystem::NormalStringChangeInterface,
71 void (*)(stringoption*, cfestring&)
72 = &configsystem::NormalStringChanger);
73 virtual void SaveValue(std::ofstream&) const;
74 virtual void LoadValue(inputfile&);
75 virtual void DisplayeValue(festring& Entry) const
76 { ValueDisplayer(this, Entry); }
77 virtual truth ActivateChangeInterface() { return ChangeInterface(this); }
78 void ChangeValue(cfestring& What) { ValueChanger(this, What); }
79 festring Value;
80 void (*ValueDisplayer)(const stringoption*, festring&);
81 truth (*ChangeInterface)(stringoption*);
82 void (*ValueChanger)(stringoption*, cfestring&);
85 struct numberoption : public configoption
87 numberoption(cchar*, cchar*, sLong,
88 void (*)(const numberoption*, festring&)
89 = &configsystem::NormalNumberDisplayer,
90 truth (*)(numberoption*)
91 = &configsystem::NormalNumberChangeInterface,
92 void (*)(numberoption*, sLong)
93 = &configsystem::NormalNumberChanger);
94 virtual void SaveValue(std::ofstream&) const;
95 virtual void LoadValue(inputfile&);
96 virtual void DisplayeValue(festring& Entry) const
97 { ValueDisplayer(this, Entry); }
98 virtual truth ActivateChangeInterface() { return ChangeInterface(this); }
99 void ChangeValue(sLong What) { ValueChanger(this, What); }
100 sLong Value;
101 void (*ValueDisplayer)(const numberoption*, festring&);
102 truth (*ChangeInterface)(numberoption*);
103 void (*ValueChanger)(numberoption*, sLong);
106 struct scrollbaroption : public numberoption
108 scrollbaroption(cchar*, cchar*, sLong,
109 void (*)(const numberoption*, festring&),
110 truth (*)(numberoption*),
111 void (*)(numberoption*, sLong)
112 = &configsystem::NormalNumberChanger,
113 void (*)(sLong) = 0);
114 void (*BarHandler)(sLong);
117 struct truthoption : public configoption
119 truthoption(cchar*, cchar*, truth,
120 void (*)(const truthoption*, festring&)
121 = &configsystem::NormalTruthDisplayer,
122 truth (*)(truthoption*)
123 = &configsystem::NormalTruthChangeInterface,
124 void (*)(truthoption*, truth)
125 = &configsystem::NormalTruthChanger);
126 virtual void SaveValue(std::ofstream&) const;
127 virtual void LoadValue(inputfile&);
128 virtual void DisplayeValue(festring& Entry) const
129 { ValueDisplayer(this, Entry); }
130 virtual truth ActivateChangeInterface() { return ChangeInterface(this); }
131 void ChangeValue(truth What) { ValueChanger(this, What); }
132 truth Value;
133 void (*ValueDisplayer)(const truthoption*, festring&);
134 truth (*ChangeInterface)(truthoption*);
135 void (*ValueChanger)(truthoption*, truth);
139 #endif