Debian Codegraph @

include/setup.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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 /* $Id: setup.h,v 1.41 2009-05-27 09:15:41 qbix79 Exp $ */
20
21 #ifndef DOSBOX_SETUP_H
22 #define DOSBOX_SETUP_H
23
24 #ifdef _MSC_VER
25 #pragma warning ( disable : 4786 )
26 #pragma warning ( disable : 4290 )
27 #endif
28
29
30 #ifndef CH_LIST
31 #define CH_LIST
32 #include <list>
33 #endif
34
35 #ifndef CH_VECTOR
36 #define CH_VECTOR
37 #include <vector>
38 #endif
39
40 #ifndef CH_STRING
41 #define CH_STRING
42 #include <string>
43 #endif
44
45 #ifndef CH_CSTDIO
46 #define CH_CSTDIO
47 #include <stdio.h>
48 #endif
49
50
51 class Hex {
52 private:
53 int _hex;
54 public:
55 Hex(int in):_hex(in) { };
56 Hex():_hex(0) { };
57 bool operator==(Hex const& other) {return _hex == other._hex;}
58 operator int () const { return _hex; }
59
60 };
61
62 class Value {
63 /*
64 * Multitype storage container that is aware of the currently stored type in it.
65 * Value st = "hello";
66 * Value in = 1;
67 * st = 12 //Exception
68 * in = 12 //works
69 */
70 private:
71 Hex _hex;
72 bool _bool;
73 int _int;
74 std::string* _string;
75 double _double;
76 public:
77 class WrongType { }; // Conversion error class
78 enum Etype { V_NONE, V_HEX, V_BOOL, V_INT, V_STRING, V_DOUBLE,V_CURRENT} type;
79
80 /* Constructors */
81 Value() :_string(0), type(V_NONE) { };
82 Value(Hex in) :_hex(in), type(V_HEX) { };
83 Value(int in) :_int(in), type(V_INT) { };
84 Value(bool in) :_bool(in), type(V_BOOL) { };
85 Value(double in) :_double(in), type(V_DOUBLE) { };
86 Value(std::string const& in) :_string(new std::string(in)),type(V_STRING) { };
87 Value(char const * const in) :_string(new std::string(in)),type(V_STRING) { };
88 Value(Value const& in):_string(0) {plaincopy(in);}
89 ~Value() { destroy();};
90 Value(std::string const& in,Etype _t) :_string(0),type(V_NONE) {SetValue(in,_t);}
91
92 /* Assigment operators */
93 Value& operator= (Hex in) { return copy(Value(in));}
94 Value& operator= (int in) { return copy(Value(in));}
95 Value& operator= (bool in) { return copy(Value(in));}
96 Value& operator= (double in) { return copy(Value(in));}
97 Value& operator= (std::string const& in) { return copy(Value(in));}
98 Value& operator= (char const * const in) { return copy(Value(in));}
99 Value& operator= (Value const& in) { return copy(Value(in));}
100
101 bool operator== (Value const & other);
102 operator bool () const;
103 operator Hex () const;
104 operator int () const;
105 operator double () const;
106 operator char const* () const;
107 void SetValue(std::string const& in,Etype _type = V_CURRENT);
108 std::string ToString() const;
109
110 private:
111 void destroy() throw();
112 Value& copy(Value const& in);
113 void plaincopy(Value const& in) throw();
114 void set_hex(std::string const& in);
115 void set_int(std::string const&in);
116 void set_bool(std::string const& in);
117 void set_string(std::string const& in);
118 void set_double(std::string const& in);
119 };
120
121 class Property {
122 public:
123 struct Changeable { enum Value {Always, WhenIdle,OnlyAtStart};};
124 const std::string propname;
125
126 Property(std::string const& _propname, Changeable::Value when):propname(_propname),change(when) { }
127 void Set_values(const char * const * in);
128 void Set_help(std::string const& str);
129 char const* Get_help();
130 virtual void SetValue(std::string const& str)=0;
131 Value const& GetValue() const { return value;}
132 Value const& Get_Default_Value() const { return default_value; }
133 //CheckValue returns true if value is in suggested_values;
134 //Type specific properties are encouraged to override this and check for type
135 //specific features.
136 virtual bool CheckValue(Value const& in, bool warn);
137 //Set interval value to in or default if in is invalid. force always sets the value.
138 void SetVal(Value const& in, bool forced,bool warn=true) {if(forced || CheckValue(in,warn)) value = in; else value = default_value;}
139 virtual ~Property(){ }
140 virtual const std::vector<Value>& GetValues() const;
141 Value::Etype Get_type(){return default_value.type;}
142
143 protected:
144 Value value;
145 std::vector<Value> suggested_values;
146 typedef std::vector<Value>::iterator iter;
147 Value default_value;
148 const Changeable::Value change;
149 };
150
151 class Prop_int:public Property {
152 public:
153 Prop_int(std::string const& _propname,Changeable::Value when, int _value)
154 :Property(_propname,when) {
155 default_value = value = _value;
156 min = max = -1;
157 }
158 Prop_int(std::string const& _propname,Changeable::Value when, int _min,int _max,int _value)
159 :Property(_propname,when) {
160 default_value = value = _value;
161 min = _min;
162 max = _max;
163 }
164 void SetMinMax(Value const& min,Value const& max) {this->min = min; this->max=max;}
165 void SetValue(std::string const& in);
166 ~Prop_int(){ }
167 virtual bool CheckValue(Value const& in, bool warn);
168 private:
169 Value min,max;
170 };
171
172 class Prop_double:public Property {
173 public:
174 Prop_double(std::string const & _propname, Changeable::Value when, double _value)
175 :Property(_propname,when){
176 default_value = value = _value;
177 }
178 void SetValue(std::string const& input);
179 ~Prop_double(){ }
180 };
181
182 class Prop_bool:public Property {
183 public:
184 Prop_bool(std::string const& _propname, Changeable::Value when, bool _value)
185 :Property(_propname,when) {
186 default_value = value = _value;
187 }
188 void SetValue(std::string const& in);
189 ~Prop_bool(){ }
190 };
191
192 class Prop_string:public Property{
193 public:
194 Prop_string(std::string const& _propname, Changeable::Value when, char const * const _value)
195 :Property(_propname,when) {
196 default_value = value = _value;
197 }
198 void SetValue(std::string const& in);
199 virtual bool CheckValue(Value const& in, bool warn);
200 ~Prop_string(){ }
201 };
202 class Prop_path:public Prop_string{
203 public:
204 std::string realpath;
205 Prop_path(std::string const& _propname, Changeable::Value when, char const * const _value)
206 :Prop_string(_propname,when,_value) {
207 default_value = value = _value;
208 realpath = _value;
209 }
210 void SetValue(std::string const& in);
211 ~Prop_path(){ }
212 };
213
214 class Prop_hex:public Property {
215 public:
216 Prop_hex(std::string const& _propname, Changeable::Value when, Hex _value)
217 :Property(_propname,when) {
218 default_value = value = _value;
219 }
220 void SetValue(std::string const& in);
221 ~Prop_hex(){ }
222 };
223
224 #define NO_SUCH_PROPERTY "PROP_NOT_EXIST"
225 class Section {
226 private:
227 typedef void (*SectionFunction)(Section*);
228 /* Wrapper class around startup and shutdown functions. the variable
229 * canchange indicates it can be called on configuration changes */
230 struct Function_wrapper {
231 SectionFunction function;
232 bool canchange;
233 Function_wrapper(SectionFunction const _fun,bool _ch){
234 function=_fun;
235 canchange=_ch;
236 }
237 };
238 std::list<Function_wrapper> initfunctions;
239 std::list<Function_wrapper> destroyfunctions;
240 std::string sectionname;
241 public:
242 Section(std::string const& _sectionname):sectionname(_sectionname) { }
243
244 void AddInitFunction(SectionFunction func,bool canchange=false);
245 void AddDestroyFunction(SectionFunction func,bool canchange=false);
246 void ExecuteInit(bool initall=true);
247 void ExecuteDestroy(bool destroyall=true);
248 const char* GetName() const {return sectionname.c_str();}
249
250 virtual std::string GetPropValue(std::string const& _property) const =0;
251 virtual void HandleInputline(std::string const& _line)=0;
252 virtual void PrintData(FILE* outfile) const =0;
253 virtual ~Section() { /*Children must call executedestroy ! */}
254 };
255
256 class Prop_multival;
257 class Prop_multival_remain;
258 class Section_prop:public Section {
259 private:
260 std::list<Property*> properties;
261 typedef std::list<Property*>::iterator it;
262 typedef std::list<Property*>::const_iterator const_it;
263
264 public:
265 Section_prop(std::string const& _sectionname):Section(_sectionname){}
266 Prop_int* Add_int(std::string const& _propname, Property::Changeable::Value when, int _value=0);
267 Prop_string* Add_string(std::string const& _propname, Property::Changeable::Value when, char const * const _value=NULL);
268 Prop_path* Add_path(std::string const& _propname, Property::Changeable::Value when, char const * const _value=NULL);
269 Prop_bool* Add_bool(std::string const& _propname, Property::Changeable::Value when, bool _value=false);
270 Prop_hex* Add_hex(std::string const& _propname, Property::Changeable::Value when, Hex _value=0);
271 // void Add_double(char const * const _propname, double _value=0.0);
272 Prop_multival *Add_multi(std::string const& _propname, Property::Changeable::Value when,std::string const& sep);
273 Prop_multival_remain *Add_multiremain(std::string const& _propname, Property::Changeable::Value when,std::string const& sep);
274
275 Property* Get_prop(int index);
276 int Get_int(std::string const& _propname) const;
277 const char* Get_string(std::string const& _propname) const;
278 bool Get_bool(std::string const& _propname) const;
279 Hex Get_hex(std::string const& _propname) const;
280 double Get_double(std::string const& _propname) const;
281 Prop_path* Get_path(std::string const& _propname) const;
282 Prop_multival* Get_multival(std::string const& _propname) const;
283 Prop_multival_remain* Get_multivalremain(std::string const& _propname) const;
284 void HandleInputline(std::string const& gegevens);
285 void PrintData(FILE* outfile) const;
286 virtual std::string GetPropValue(std::string const& _property) const;
287 //ExecuteDestroy should be here else the destroy functions use destroyed properties
288 virtual ~Section_prop();
289 };
290
291 class Prop_multival:public Property{
292 protected:
293 Section_prop* section;
294 std::string seperator;
295 void make_default_value();
296 public:
297 Prop_multival(std::string const& _propname, Changeable::Value when,std::string const& sep):Property(_propname,when), section(new Section_prop("")),seperator(sep) {
298 default_value = value = "";
299 }
300 Section_prop *GetSection() { return section; }
301 const Section_prop *GetSection() const { return section; }
302 virtual void SetValue(std::string const& input);
303 virtual const std::vector<Value>& GetValues() const;
304 ~Prop_multival() { delete section; }
305 }; //value bevat totale string. setvalue zet elk van de sub properties en checked die.
306
307 class Prop_multival_remain:public Prop_multival{
308 public:
309 Prop_multival_remain(std::string const& _propname, Changeable::Value when,std::string const& sep):Prop_multival(_propname,when,sep){ }
310
311 virtual void SetValue(std::string const& input);
312 };
313
314
315 class Section_line: public Section{
316 public:
317 Section_line(std::string const& _sectionname):Section(_sectionname){}
318 ~Section_line(){ExecuteDestroy(true);}
319 void HandleInputline(std::string const& gegevens);
320 void PrintData(FILE* outfile) const;
321 virtual std::string GetPropValue(std::string const& _property) const;
322 std::string data;
323 };
324
325 class Module_base {
326 /* Base for all hardware and software "devices" */
327 protected:
328 Section* m_configuration;
329 public:
330 Module_base(Section* configuration){m_configuration=configuration;};
331 // Module_base(Section* configuration, SaveState* state) {};
332 virtual ~Module_base(){/*LOG_MSG("executed")*/;};//Destructors are required
333 /* Returns true if succesful.*/
334 virtual bool Change_Config(Section* /*newconfig*/) {return false;} ;
335 };
336 #endif