1
0
Fork 0

Part of the configurating changes. Value is a class now. Some cleanups and support functions to make this transition smooth. It compiles and works, but it's not finished yet.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3088
This commit is contained in:
Peter Veenstra 2008-01-26 15:50:19 +00:00
parent 6532a8bc74
commit e0c08be26f
3 changed files with 219 additions and 51 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: setup.h,v 1.29 2008-01-19 11:02:29 qbix79 Exp $ */
/* $Id: setup.h,v 1.30 2008-01-26 15:50:19 qbix79 Exp $ */
#ifndef DOSBOX_SETUP_H
#define DOSBOX_SETUP_H
@ -37,74 +37,142 @@
#include <list>
#endif
#ifndef CH_VECTOR
#define CH_VECTOR
#include <vector>
#endif
#ifndef CH_STRING
#define CH_STRING
#include <string>
#endif
union Value{
class Hex {
private:
int _hex;
public:
Hex(int in):_hex(in) { };
Hex():_hex(0) { };
bool operator==(Hex const& other) {return _hex == other._hex;}
};
class Value {
public: //for the time being. Added a n to _hex to keep compilable during the work
Hex _hexn;
int _hex;
bool _bool;
int _int;
std::string* _string;
float _float;
double _double;
public:
class WrongType { }; // Conversion error class
enum { V_NONE, V_HEX, V_BOOL, V_INT, V_STRING, V_DOUBLE} type;
/* Constructors */
Value() :type(V_NONE) { };
Value(Hex in) :type(V_HEX), _hexn(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() { destroy();};
/* Assigment operators */
Value& operator= (Hex in) throw(WrongType) { return copy(Value(in));}
Value& operator= (int in) throw(WrongType) { return copy(Value(in));}
Value& operator= (bool in) throw(WrongType) { return copy(Value(in));}
Value& operator= (double in) throw(WrongType) { return copy(Value(in));}
Value& operator= (std::string const& in) throw(WrongType) { return copy(Value(in));}
Value& operator= (char const * const in) throw(WrongType) { return copy(Value(in));}
Value& operator= (Value const& in) throw(WrongType) { return copy(Value(in));}
bool operator== (Value const & other);
operator bool () throw(WrongType);
operator Hex () throw(WrongType);
operator int () throw(WrongType);
operator double () throw(WrongType);
operator char const* () throw(WrongType);
private:
void destroy();
Value& copy(Value const& in) throw(WrongType);
void plaincopy(Value 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;
Value GetValue() const { return value;}
virtual ~Property(){ }
std::string propname;
//CheckValue returns true (and sets value to in) 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;}
protected:
Value value;
std::vector<Value> suggested_values;
typedef std::vector<Value>::iterator iter;
Value default_value;
/*const*/ Changable::Value change;
};
class Prop_int:public Property {
public:
Prop_int(char const * const _propname, int _value):Property(_propname) {
value._int=_value;
default_value = value = _value;
min = max = -1;
}
void SetMinMax(Value const& min,Value const& max) {this->min = min; this->max=max;}
void SetValue(char* input);
void GetValuestring(char* str) const;
void GetValuestring(char* str) const;
~Prop_int(){ }
virtual bool CheckValue(Value const& in, bool warn);
private:
Value min,max;
};
class Prop_float:public Property {
class Prop_double:public Property {
public:
Prop_float(char const * const _propname, float _value):Property(_propname){
value._float=_value;
Prop_double(char const * const _propname, float _value):Property(_propname){
default_value = value = _value;
}
void SetValue(char* input);
void GetValuestring(char* str) const;
~Prop_float(){ }
~Prop_double(){ }
};
class Prop_bool:public Property {
public:
Prop_bool(char const * const _propname, bool _value):Property(_propname) {
value._bool=_value;
default_value = value = _value;
}
void SetValue(char* input);
void GetValuestring(char* str) const;
void GetValuestring(char* str) const;
~Prop_bool(){ }
};
class Prop_string:public Property{
public:
Prop_string(char const * const _propname, char const * const _value):Property(_propname) {
value._string=new std::string(_value);
}
~Prop_string(){
delete value._string;
default_value = value = _value;
}
void SetValue(char* input);
void GetValuestring(char* str) const;
void GetValuestring(char* str) const;
~Prop_string(){ }
};
class Prop_hex:public Property {
public:
Prop_hex(char const * const _propname, int _value):Property(_propname) {
value._hex=_value;
default_value = value._hex = _value;
}
void SetValue(char* input);
~Prop_hex(){ }
@ -150,18 +218,18 @@ private:
typedef std::list<Property*>::const_iterator const_it;
public:
Section_prop(char const * const _sectionname):Section(_sectionname){}
void Add_int(char const * const _propname, int _value=0);
void Add_string(char const * const _propname, char const * const _value=NULL);
void Add_bool(char const * const _propname, bool _value=false);
void Add_hex(char const * const _propname, int _value=0);
void Add_float(char const * const _propname, float _value=0.0);
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);
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;
float Get_float(char const * const _propname) const;
double Get_double(char const * const _propname) const;
void HandleInputline(char *gegevens);
void PrintData(FILE* outfile) const;
virtual char const * GetPropValue(char const * const _property) const;