1
0
Fork 0

make cycles reset to correct default value.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3166
This commit is contained in:
Peter Veenstra 2008-05-30 12:42:38 +00:00
parent d869473970
commit 44aca76921
2 changed files with 38 additions and 5 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: setup.h,v 1.35 2008-04-29 08:23:16 qbix79 Exp $ */
/* $Id: setup.h,v 1.36 2008-05-30 12:42:37 qbix79 Exp $ */
#ifndef DOSBOX_SETUP_H
#define DOSBOX_SETUP_H
@ -130,6 +130,7 @@ public:
char const* Get_help();
virtual void SetValue(std::string const& str)=0;
Value const& GetValue() const { return value;}
Value const& Get_Default_Value() const { return default_value; }
//CheckValue returns true if value is in suggested_values;
//Type specific properties are encouraged to override this and check for type
//specific features.
@ -138,6 +139,7 @@ public:
void SetVal(Value const& in, bool forced,bool warn=true) {if(forced || CheckValue(in,warn)) value = in; else value = default_value;}
virtual ~Property(){ }
virtual const std::vector<Value>& GetValues() const;
Value::Etype Get_type(){return default_value.type;}
protected:
Value value;
@ -277,9 +279,10 @@ class Prop_multival:public Property{
protected:
Section_prop* section;
std::string seperator;
void make_default_value();
public:
Prop_multival(std::string const& _propname, Changeable::Value when,std::string const& sep):Property(_propname,when), section(new Section_prop("")),seperator(sep) {
value = "";
default_value = value = "";
}
Section_prop *GetSection() { return section; }
const Section_prop *GetSection() const { return section; }

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: setup.cpp,v 1.48 2008-04-29 08:23:16 qbix79 Exp $ */
/* $Id: setup.cpp,v 1.49 2008-05-30 12:42:38 qbix79 Exp $ */
#include "dosbox.h"
#include "cross.h"
@ -273,6 +273,23 @@ void Prop_hex::SetValue(std::string const& input){
SetVal(val,false,true);
}
void Prop_multival::make_default_value(){
Bitu i = 1;
Property *p = section->Get_prop(0);
if(!p) return;
std::string result = p->Get_Default_Value().ToString();
while( (p = section->Get_prop(i++)) ) {
std::string props = p->Get_Default_Value().ToString();
if(props == "") continue;
result += seperator; result += props;
}
Value val(result,Value::V_STRING);
SetVal(val,false,true);
}
//TODO checkvalue stuff
void Prop_multival_remain::SetValue(std::string const& input) {
Value val(input,Value::V_STRING);
@ -303,6 +320,12 @@ void Prop_multival_remain::SetValue(std::string const& input) {
in = local;
local = "";
}
//Test Value. If it fails set default
Value valtest (in,p->Get_type());
if(!p->CheckValue(valtest,true)) {
make_default_value();
return;
}
p->SetValue(in);
}
}
@ -324,21 +347,28 @@ void Prop_multival::SetValue(std::string const& input) {
if(loc != string::npos) local.erase(0,loc);
loc = local.find_first_of(seperator);
string in = "";//default value
if(loc != string::npos) { //seperator found
if(loc != string::npos) { //seperator found
in = local.substr(0,loc);
local.erase(0,loc+1);
} else if(local.size()) { //last argument
in = local;
local = "";
}
//Test Value. If it fails set default
Value valtest (in,p->Get_type());
if(!p->CheckValue(valtest,true)) {
make_default_value();
return;
}
p->SetValue(in);
}
}
const std::vector<Value>& Property::GetValues() const {
return suggested_values;
}
const std::vector<Value>& Prop_multival::GetValues() const
const std::vector<Value>& Prop_multival::GetValues() const
{
Property *p = section->Get_prop(0);
//No properties in this section. do nothing