Partial rewrite of the configsystem part 2. Should be usuable. Missing parts are cosmetic. (based on Moe his stuff). I hope everything works in visual C.
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3098
This commit is contained in:
parent
0a8945c885
commit
45074288cf
10 changed files with 811 additions and 536 deletions
159
include/setup.h
159
include/setup.h
|
@ -16,13 +16,14 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: setup.h,v 1.31 2008-01-27 18:31:01 qbix79 Exp $ */
|
||||
/* $Id: setup.h,v 1.32 2008-02-10 11:14:02 qbix79 Exp $ */
|
||||
|
||||
#ifndef DOSBOX_SETUP_H
|
||||
#define DOSBOX_SETUP_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( disable : 4786 )
|
||||
#pragma warning ( disable : 4290 )
|
||||
#endif
|
||||
|
||||
#ifndef DOSBOX_CROSS_H
|
||||
|
@ -47,7 +48,6 @@
|
|||
#include <string>
|
||||
#endif
|
||||
|
||||
#pragma warning(disable: 4290)
|
||||
|
||||
class Hex {
|
||||
private:
|
||||
|
@ -56,30 +56,39 @@ public:
|
|||
Hex(int in):_hex(in) { };
|
||||
Hex():_hex(0) { };
|
||||
bool operator==(Hex const& other) {return _hex == other._hex;}
|
||||
operator int () const { return _hex; }
|
||||
|
||||
};
|
||||
|
||||
class Value {
|
||||
public: //for the time being. Added a n to _hex to keep compilable during the work
|
||||
Hex _hexn;
|
||||
int _hex;
|
||||
/*
|
||||
* Multitype storage container that is aware of the currently stored type in it.
|
||||
* Value st = "hello";
|
||||
* Value in = 1;
|
||||
* st = 12 //Exception
|
||||
* in = 12 //works
|
||||
*/
|
||||
private:
|
||||
Hex _hex;
|
||||
bool _bool;
|
||||
int _int;
|
||||
std::string* _string;
|
||||
double _double;
|
||||
public:
|
||||
class WrongType { }; // Conversion error class
|
||||
enum { V_NONE, V_HEX, V_BOOL, V_INT, V_STRING, V_DOUBLE} type;
|
||||
enum Etype { V_NONE, V_HEX, V_BOOL, V_INT, V_STRING, V_DOUBLE,V_CURRENT} type;
|
||||
|
||||
/* Constructors */
|
||||
Value() :type(V_NONE) { };
|
||||
Value(Hex in) :type(V_HEX), _hexn(in) { };
|
||||
Value() :type(V_NONE),_string(0) { };
|
||||
Value(Hex in) :type(V_HEX), _hex(in) { };
|
||||
Value(int in) :type(V_INT), _int(in) { };
|
||||
Value(bool in) :type(V_BOOL), _bool(in) { };
|
||||
Value(double in) :type(V_DOUBLE), _double(in) { };
|
||||
Value(std::string const& in) :type(V_STRING), _string(new std::string(in)) { };
|
||||
Value(char const * const in) :type(V_STRING), _string(new std::string(in)) { };
|
||||
Value(Value const& in) {plaincopy(in);}
|
||||
Value(Value const& in):_string(0) {plaincopy(in);}
|
||||
~Value() { destroy();};
|
||||
Value(std::string const& in,Etype _t) :type(V_NONE),_string(0){SetValue(in,_t);}
|
||||
|
||||
/* Assigment operators */
|
||||
Value& operator= (Hex in) throw(WrongType) { return copy(Value(in));}
|
||||
|
@ -96,91 +105,108 @@ public:
|
|||
operator int () const throw(WrongType);
|
||||
operator double () const throw(WrongType);
|
||||
operator char const* () const throw(WrongType);
|
||||
void SetValue(std::string const& in,Etype _type = V_CURRENT) throw(WrongType);
|
||||
std::string ToString() const;
|
||||
|
||||
private:
|
||||
void destroy();
|
||||
void destroy() throw();
|
||||
Value& copy(Value const& in) throw(WrongType);
|
||||
void plaincopy(Value const& in);
|
||||
|
||||
void plaincopy(Value const& in) throw();
|
||||
void set_hex(std::string const& in);
|
||||
void set_int(std::string const&in);
|
||||
void set_bool(std::string const& in);
|
||||
void set_string(std::string const& in);
|
||||
void set_double(std::string const& in);
|
||||
};
|
||||
|
||||
class Property {
|
||||
public:
|
||||
struct Changable { enum Value {Always, WhenIdle,OnlyAtStart};};
|
||||
Property(char const * const _propname):propname(_propname) { }
|
||||
virtual void SetValue(char* input)=0;
|
||||
virtual void GetValuestring(char* str) const=0;
|
||||
struct Changeable { enum Value {Always, WhenIdle,OnlyAtStart};};
|
||||
const std::string propname;
|
||||
|
||||
Property(std::string const& _propname, Changeable::Value when):propname(_propname),change(when) { }
|
||||
void Set_values(const char * const * in);
|
||||
void Set_help(std::string const& str);
|
||||
char const* Get_help();
|
||||
virtual void SetValue(std::string const& str)=0;
|
||||
Value const& GetValue() const { return value;}
|
||||
virtual ~Property(){ }
|
||||
std::string propname;
|
||||
//CheckValue returns true (and sets value to in) if value is in suggested_values;
|
||||
//CheckValue returns true if value is in suggested_values;
|
||||
//Type specific properties are encouraged to override this and check for type
|
||||
//specific features.
|
||||
virtual bool CheckValue(Value const& in, bool warn);
|
||||
//Set interval value to in or default if in is invalid. force always sets the value.
|
||||
void SetVal(Value const& in, bool forced) {if(forced || CheckValue(in,false)) value = in; else value = default_value;}
|
||||
void SetVal(Value const& in, bool forced,bool warn=true) {if(forced || CheckValue(in,warn)) value = in; else value = default_value;}
|
||||
virtual ~Property(){ }
|
||||
protected:
|
||||
Value value;
|
||||
std::vector<Value> suggested_values;
|
||||
typedef std::vector<Value>::iterator iter;
|
||||
Value default_value;
|
||||
/*const*/ Changable::Value change;
|
||||
const Changeable::Value change;
|
||||
};
|
||||
|
||||
class Prop_int:public Property {
|
||||
public:
|
||||
Prop_int(char const * const _propname, int _value):Property(_propname) {
|
||||
Prop_int(std::string const& _propname,Changeable::Value when, int _value)
|
||||
:Property(_propname,when) {
|
||||
default_value = value = _value;
|
||||
min = max = -1;
|
||||
}
|
||||
Prop_int(std::string const& _propname,Changeable::Value when, int _min,int _max,int _value)
|
||||
:Property(_propname,when) {
|
||||
default_value = value = _value;
|
||||
min = _min;
|
||||
max = _max;
|
||||
}
|
||||
void SetMinMax(Value const& min,Value const& max) {this->min = min; this->max=max;}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str) const;
|
||||
void SetValue(std::string const& in);
|
||||
~Prop_int(){ }
|
||||
virtual bool CheckValue(Value const& in, bool warn);
|
||||
private:
|
||||
Value min,max;
|
||||
};
|
||||
|
||||
class Prop_double:public Property {
|
||||
public:
|
||||
Prop_double(char const * const _propname, double _value):Property(_propname){
|
||||
Prop_double(std::string const & _propname, Changeable::Value when, double _value)
|
||||
:Property(_propname,when){
|
||||
default_value = value = _value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str) const;
|
||||
void SetValue(std::string const& input);
|
||||
~Prop_double(){ }
|
||||
};
|
||||
|
||||
class Prop_bool:public Property {
|
||||
public:
|
||||
Prop_bool(char const * const _propname, bool _value):Property(_propname) {
|
||||
Prop_bool(std::string const& _propname, Changeable::Value when, bool _value)
|
||||
:Property(_propname,when) {
|
||||
default_value = value = _value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str) const;
|
||||
void SetValue(std::string const& in);
|
||||
~Prop_bool(){ }
|
||||
};
|
||||
|
||||
class Prop_string:public Property{
|
||||
public:
|
||||
Prop_string(char const * const _propname, char const * const _value):Property(_propname) {
|
||||
Prop_string(std::string const& _propname, Changeable::Value when, char const * const _value)
|
||||
:Property(_propname,when) {
|
||||
default_value = value = _value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str) const;
|
||||
void SetValue(std::string const& in);
|
||||
~Prop_string(){ }
|
||||
|
||||
};
|
||||
|
||||
class Prop_hex:public Property {
|
||||
public:
|
||||
Prop_hex(char const * const _propname, int _value):Property(_propname) {
|
||||
default_value = value._hex = _value;
|
||||
Prop_hex(std::string const& _propname, Changeable::Value when, Hex _value)
|
||||
:Property(_propname,when) {
|
||||
default_value = value = _value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void SetValue(std::string const& in);
|
||||
~Prop_hex(){ }
|
||||
void GetValuestring(char* str) const;
|
||||
};
|
||||
|
||||
#define NO_SUCH_PROPERTY "PROP_NOT_EXIST"
|
||||
class Section {
|
||||
private:
|
||||
typedef void (*SectionFunction)(Section*);
|
||||
|
@ -198,7 +224,7 @@ private:
|
|||
std::list<Function_wrapper> destroyfunctions;
|
||||
std::string sectionname;
|
||||
public:
|
||||
Section(char const * const _sectionname):sectionname(_sectionname) { }
|
||||
Section(std::string const& _sectionname):sectionname(_sectionname) { }
|
||||
|
||||
void AddInitFunction(SectionFunction func,bool canchange=false);
|
||||
void AddDestroyFunction(SectionFunction func,bool canchange=false);
|
||||
|
@ -206,46 +232,61 @@ public:
|
|||
void ExecuteDestroy(bool destroyall=true);
|
||||
const char* GetName() const {return sectionname.c_str();}
|
||||
|
||||
virtual char const * GetPropValue(char const * const _property) const =0;
|
||||
virtual void HandleInputline(char * _line)=0;
|
||||
virtual std::string GetPropValue(std::string const& _property) const =0;
|
||||
virtual void HandleInputline(std::string const& _line)=0;
|
||||
virtual void PrintData(FILE* outfile) const =0;
|
||||
virtual ~Section() { /*Children must call executedestroy ! */}
|
||||
};
|
||||
|
||||
|
||||
class Prop_multival;
|
||||
class Section_prop:public Section {
|
||||
private:
|
||||
std::list<Property*> properties;
|
||||
typedef std::list<Property*>::iterator it;
|
||||
typedef std::list<Property*>::const_iterator const_it;
|
||||
|
||||
public:
|
||||
Section_prop(char const * const _sectionname):Section(_sectionname){}
|
||||
Prop_int& Add_int(char const * const _propname, int _value=0);
|
||||
Prop_string& Add_string(char const * const _propname, char const * const _value=NULL);
|
||||
Prop_bool& Add_bool(char const * const _propname, bool _value=false);
|
||||
Prop_hex& Add_hex(char const * const _propname, int _value=0);
|
||||
void Add_double(char const * const _propname, double _value=0.0);
|
||||
Section_prop(std::string const& _sectionname):Section(_sectionname){}
|
||||
Prop_int* Add_int(std::string const& _propname, Property::Changeable::Value when, int _value=0);
|
||||
Prop_string* Add_string(std::string const& _propname, Property::Changeable::Value when, char const * const _value=NULL);
|
||||
Prop_bool* Add_bool(std::string const& _propname, Property::Changeable::Value when, bool _value=false);
|
||||
Prop_hex* Add_hex(std::string const& _propname, Property::Changeable::Value when, Hex _value=0);
|
||||
// void Add_double(char const * const _propname, double _value=0.0); P
|
||||
Prop_multival *Add_multi(std::string const& _propname, Property::Changeable::Value when,std::string const& sep);
|
||||
|
||||
Property* Get_prop(int index);
|
||||
int Get_int(char const * const _propname) const;
|
||||
const char* Get_string(char const * const _propname) const;
|
||||
bool Get_bool(char const * const _propname) const;
|
||||
int Get_hex(char const * const _propname) const;
|
||||
double Get_double(char const * const _propname) const;
|
||||
void HandleInputline(char *gegevens);
|
||||
int Get_int(std::string const& _propname) const;
|
||||
const char* Get_string(std::string const& _propname) const;
|
||||
bool Get_bool(std::string const& _propname) const;
|
||||
Hex Get_hex(std::string const& _propname) const;
|
||||
double Get_double(std::string const& _propname) const;
|
||||
Prop_multival* Get_multival(std::string const& _propname) const;
|
||||
void HandleInputline(std::string const& gegevens);
|
||||
void PrintData(FILE* outfile) const;
|
||||
virtual char const * GetPropValue(char const * const _property) const;
|
||||
virtual std::string GetPropValue(std::string const& _property) const;
|
||||
//ExecuteDestroy should be here else the destroy functions use destroyed properties
|
||||
virtual ~Section_prop();
|
||||
};
|
||||
|
||||
class Prop_multival:public Property{
|
||||
Section_prop* section;
|
||||
std::string seperator;
|
||||
public:
|
||||
Prop_multival(std::string const& _propname, Changeable::Value when,std::string const& sep):Property(_propname,when), section(new Section_prop("")),seperator(sep) {
|
||||
value = "";
|
||||
}
|
||||
Section_prop *GetSection() { return section; }
|
||||
const Section_prop *GetSection() const { return section; }
|
||||
void SetValue(std::string const& input);
|
||||
}; //value bevat totalle string. setvalue zet elk van de sub properties en checked die.
|
||||
|
||||
class Section_line: public Section{
|
||||
public:
|
||||
Section_line(char const * const _sectionname):Section(_sectionname){}
|
||||
Section_line(std::string const& _sectionname):Section(_sectionname){}
|
||||
~Section_line(){ExecuteDestroy(true);}
|
||||
void HandleInputline(char* gegevens);
|
||||
void HandleInputline(std::string const& gegevens);
|
||||
void PrintData(FILE* outfile) const;
|
||||
virtual const char* GetPropValue(char const * const _property) const;
|
||||
virtual std::string GetPropValue(std::string const& _property) const;
|
||||
std::string data;
|
||||
};
|
||||
|
||||
|
@ -267,7 +308,7 @@ public:
|
|||
Section_prop * AddSection_prop(char const * const _name,void (*_initfunction)(Section*),bool canchange=false);
|
||||
|
||||
Section* GetSection(int index);
|
||||
Section* GetSection(char const* const _sectionname) const;
|
||||
Section* GetSection(std::string const&_sectionname) const;
|
||||
Section* GetSectionFromProperty(char const * const prop) const;
|
||||
|
||||
void SetStartUp(void (*_function)(void));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue