Updates from David Megginson:
These patches also eliminate the spurious warning messages about not being able to set values for joystick buttons.
This commit is contained in:
+139
-25
@@ -264,7 +264,7 @@ SGValue::getBoolValue () const
|
|||||||
return (getRawDouble() == 0.0 ? false : true);
|
return (getRawDouble() == 0.0 ? false : true);
|
||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
case STRING:
|
case STRING:
|
||||||
return ((getRawString() == "false" || getIntValue() == 0) ? false : true);
|
return ((getRawString() == "true" || getIntValue() != 0) ? true : false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -389,12 +389,24 @@ SGValue::getStringValue () const
|
|||||||
bool
|
bool
|
||||||
SGValue::setBoolValue (bool value)
|
SGValue::setBoolValue (bool value)
|
||||||
{
|
{
|
||||||
if (_type == UNKNOWN || _type == BOOL) {
|
if (_type == UNKNOWN)
|
||||||
_type = BOOL;
|
_type = INT;
|
||||||
|
switch (_type) {
|
||||||
|
case BOOL:
|
||||||
return setRawBool(value);
|
return setRawBool(value);
|
||||||
} else {
|
case INT:
|
||||||
return false;
|
return setRawInt((int)value);
|
||||||
|
case FLOAT:
|
||||||
|
return setRawFloat((float)value);
|
||||||
|
case DOUBLE:
|
||||||
|
return setRawDouble((double)value);
|
||||||
|
case STRING:
|
||||||
|
if (value)
|
||||||
|
return setRawString("true");
|
||||||
|
else
|
||||||
|
return setRawString("false");
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -406,12 +418,26 @@ SGValue::setBoolValue (bool value)
|
|||||||
bool
|
bool
|
||||||
SGValue::setIntValue (int value)
|
SGValue::setIntValue (int value)
|
||||||
{
|
{
|
||||||
if (_type == UNKNOWN || _type == INT) {
|
if (_type == UNKNOWN)
|
||||||
_type = INT;
|
_type = INT;
|
||||||
|
switch (_type) {
|
||||||
|
case BOOL:
|
||||||
|
if (value == 0)
|
||||||
|
return setRawBool(false);
|
||||||
|
else
|
||||||
|
return setRawBool(true);
|
||||||
|
case INT:
|
||||||
return setRawInt(value);
|
return setRawInt(value);
|
||||||
} else {
|
case FLOAT:
|
||||||
return false;
|
return setRawFloat((float)value);
|
||||||
|
case DOUBLE:
|
||||||
|
return setRawDouble((double)value);
|
||||||
|
case STRING:
|
||||||
|
char buf[128];
|
||||||
|
sprintf(buf, "%d", value);
|
||||||
|
return setRawString(buf);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -423,12 +449,26 @@ SGValue::setIntValue (int value)
|
|||||||
bool
|
bool
|
||||||
SGValue::setFloatValue (float value)
|
SGValue::setFloatValue (float value)
|
||||||
{
|
{
|
||||||
if (_type == UNKNOWN || _type == FLOAT) {
|
if (_type == UNKNOWN)
|
||||||
_type = FLOAT;
|
_type = FLOAT;
|
||||||
|
switch (_type) {
|
||||||
|
case BOOL:
|
||||||
|
if (value == 0.0)
|
||||||
|
return setRawBool(false);
|
||||||
|
else
|
||||||
|
return setRawBool(true);
|
||||||
|
case INT:
|
||||||
|
return setRawInt((int)value);
|
||||||
|
case FLOAT:
|
||||||
return setRawFloat(value);
|
return setRawFloat(value);
|
||||||
} else {
|
case DOUBLE:
|
||||||
return false;
|
return setRawDouble((double)value);
|
||||||
|
case STRING:
|
||||||
|
char buf[128];
|
||||||
|
sprintf(buf, "%f", value);
|
||||||
|
return setRawString(buf);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -440,12 +480,26 @@ SGValue::setFloatValue (float value)
|
|||||||
bool
|
bool
|
||||||
SGValue::setDoubleValue (double value)
|
SGValue::setDoubleValue (double value)
|
||||||
{
|
{
|
||||||
if (_type == UNKNOWN || _type == DOUBLE) {
|
if (_type == UNKNOWN)
|
||||||
_type = DOUBLE;
|
_type = DOUBLE;
|
||||||
|
switch (_type) {
|
||||||
|
case BOOL:
|
||||||
|
if (value == 0.0L)
|
||||||
|
return setRawBool(false);
|
||||||
|
else
|
||||||
|
return setRawBool(true);
|
||||||
|
case INT:
|
||||||
|
return setRawInt((int)value);
|
||||||
|
case FLOAT:
|
||||||
|
return setRawFloat((float)value);
|
||||||
|
case DOUBLE:
|
||||||
return setRawDouble(value);
|
return setRawDouble(value);
|
||||||
} else {
|
case STRING:
|
||||||
return false;
|
char buf[128];
|
||||||
|
sprintf(buf, "%lf", value);
|
||||||
|
return setRawString(buf);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -457,12 +511,25 @@ SGValue::setDoubleValue (double value)
|
|||||||
bool
|
bool
|
||||||
SGValue::setStringValue (const string &value)
|
SGValue::setStringValue (const string &value)
|
||||||
{
|
{
|
||||||
if (_type == UNKNOWN || _type == STRING) {
|
if (_type == UNKNOWN)
|
||||||
_type = STRING;
|
_type = STRING;
|
||||||
|
|
||||||
|
switch (_type) {
|
||||||
|
case BOOL:
|
||||||
|
if (value == "true" || atoi(value.c_str()) != 0)
|
||||||
|
return setRawBool(true);
|
||||||
|
else
|
||||||
|
return setRawBool(false);
|
||||||
|
case INT:
|
||||||
|
return setRawInt(atoi(value.c_str()));
|
||||||
|
case FLOAT:
|
||||||
|
return setRawFloat(atof(value.c_str()));
|
||||||
|
case DOUBLE:
|
||||||
|
return setRawDouble(atof(value.c_str()));
|
||||||
|
case STRING:
|
||||||
return setRawString(value);
|
return setRawString(value);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -474,11 +541,23 @@ SGValue::setStringValue (const string &value)
|
|||||||
bool
|
bool
|
||||||
SGValue::setUnknownValue (const string &value)
|
SGValue::setUnknownValue (const string &value)
|
||||||
{
|
{
|
||||||
if (_type == UNKNOWN || _type == STRING) {
|
switch (_type) {
|
||||||
|
case BOOL:
|
||||||
|
if (value == "true" || atoi(value.c_str()) != 0)
|
||||||
|
return setRawBool(true);
|
||||||
|
else
|
||||||
|
return setRawBool(false);
|
||||||
|
case INT:
|
||||||
|
return setRawInt(atoi(value.c_str()));
|
||||||
|
case FLOAT:
|
||||||
|
return setRawFloat(atof(value.c_str()));
|
||||||
|
case DOUBLE:
|
||||||
|
return setRawDouble(atof(value.c_str()));
|
||||||
|
case STRING:
|
||||||
|
case UNKNOWN:
|
||||||
return setRawString(value);
|
return setRawString(value);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -497,7 +576,7 @@ SGValue::tieBool (bool_getter getter, bool_setter setter,
|
|||||||
if (_tied) {
|
if (_tied) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (useDefault && setter && _type != UNKNOWN)
|
if (useDefault && setter)
|
||||||
(*setter)(getBoolValue());
|
(*setter)(getBoolValue());
|
||||||
_tied = true;
|
_tied = true;
|
||||||
_type = BOOL;
|
_type = BOOL;
|
||||||
@@ -523,7 +602,7 @@ SGValue::tieInt (int_getter getter, int_setter setter,
|
|||||||
if (_tied) {
|
if (_tied) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (useDefault && setter && _type != UNKNOWN)
|
if (useDefault && setter)
|
||||||
(*setter)(getIntValue());
|
(*setter)(getIntValue());
|
||||||
_tied = true;
|
_tied = true;
|
||||||
_type = INT;
|
_type = INT;
|
||||||
@@ -549,7 +628,7 @@ SGValue::tieFloat (float_getter getter, float_setter setter,
|
|||||||
if (_tied) {
|
if (_tied) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (useDefault && setter && _type != UNKNOWN)
|
if (useDefault && setter)
|
||||||
(*setter)(getFloatValue());
|
(*setter)(getFloatValue());
|
||||||
_tied = true;
|
_tied = true;
|
||||||
_type = FLOAT;
|
_type = FLOAT;
|
||||||
@@ -575,7 +654,7 @@ SGValue::tieDouble (double_getter getter, double_setter setter,
|
|||||||
if (_tied) {
|
if (_tied) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (useDefault && setter && _type != UNKNOWN)
|
if (useDefault && setter)
|
||||||
(*setter)(getDoubleValue());
|
(*setter)(getDoubleValue());
|
||||||
_tied = true;
|
_tied = true;
|
||||||
_type = DOUBLE;
|
_type = DOUBLE;
|
||||||
@@ -601,7 +680,7 @@ SGValue::tieString (string_getter getter, string_setter setter,
|
|||||||
if (_tied) {
|
if (_tied) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (useDefault && setter && _type != UNKNOWN)
|
if (useDefault && setter)
|
||||||
(*setter)(getStringValue());
|
(*setter)(getStringValue());
|
||||||
_tied = true;
|
_tied = true;
|
||||||
_type = STRING;
|
_type = STRING;
|
||||||
@@ -685,6 +764,20 @@ SGPropertyList::~SGPropertyList ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if a value is present.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
SGPropertyList::hasValue (const string &name) const
|
||||||
|
{
|
||||||
|
const_iterator el = _props.find(name);
|
||||||
|
if (el == _props.end())
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up the SGValue structure associated with a property.
|
* Look up the SGValue structure associated with a property.
|
||||||
*
|
*
|
||||||
@@ -917,6 +1010,7 @@ SGPropertyList::tieBool (const string &name,
|
|||||||
bool useDefault)
|
bool useDefault)
|
||||||
{
|
{
|
||||||
FG_LOG(FG_GENERAL, FG_INFO, "Tying bool property '" << name << '\'');
|
FG_LOG(FG_GENERAL, FG_INFO, "Tying bool property '" << name << '\'');
|
||||||
|
useDefault = useDefault && hasValue(name);
|
||||||
return getValue(name, true)->tieBool(getter, setter, useDefault);
|
return getValue(name, true)->tieBool(getter, setter, useDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -933,6 +1027,7 @@ SGPropertyList::tieInt (const string &name,
|
|||||||
bool useDefault)
|
bool useDefault)
|
||||||
{
|
{
|
||||||
FG_LOG(FG_GENERAL, FG_INFO, "Tying int property '" << name << '\'');
|
FG_LOG(FG_GENERAL, FG_INFO, "Tying int property '" << name << '\'');
|
||||||
|
useDefault = useDefault && hasValue(name);
|
||||||
return getValue(name, true)->tieInt(getter, setter, useDefault);
|
return getValue(name, true)->tieInt(getter, setter, useDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -949,6 +1044,7 @@ SGPropertyList::tieFloat (const string &name,
|
|||||||
bool useDefault)
|
bool useDefault)
|
||||||
{
|
{
|
||||||
FG_LOG(FG_GENERAL, FG_INFO, "Tying float property '" << name << '\'');
|
FG_LOG(FG_GENERAL, FG_INFO, "Tying float property '" << name << '\'');
|
||||||
|
useDefault = useDefault && hasValue(name);
|
||||||
return getValue(name, true)->tieFloat(getter, setter, useDefault);
|
return getValue(name, true)->tieFloat(getter, setter, useDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -965,6 +1061,7 @@ SGPropertyList::tieDouble (const string &name,
|
|||||||
bool useDefault)
|
bool useDefault)
|
||||||
{
|
{
|
||||||
FG_LOG(FG_GENERAL, FG_INFO, "Tying double property '" << name << '\'');
|
FG_LOG(FG_GENERAL, FG_INFO, "Tying double property '" << name << '\'');
|
||||||
|
useDefault = useDefault && hasValue(name);
|
||||||
return getValue(name, true)->tieDouble(getter, setter, useDefault);
|
return getValue(name, true)->tieDouble(getter, setter, useDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -981,6 +1078,7 @@ SGPropertyList::tieString (const string &name,
|
|||||||
bool useDefault)
|
bool useDefault)
|
||||||
{
|
{
|
||||||
FG_LOG(FG_GENERAL, FG_INFO, "Tying string property '" << name << '\'');
|
FG_LOG(FG_GENERAL, FG_INFO, "Tying string property '" << name << '\'');
|
||||||
|
useDefault = useDefault && hasValue(name);
|
||||||
return getValue(name, true)->tieString(getter, setter, useDefault);
|
return getValue(name, true)->tieString(getter, setter, useDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1198,6 +1296,22 @@ SGPropertyNode::getSubNode (const string &subpath) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the specified subpath has a value.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
SGPropertyNode::hasValue (const string &subpath) const
|
||||||
|
{
|
||||||
|
if (_props == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (subpath.size() == 0)
|
||||||
|
return _props->hasValue(_path);
|
||||||
|
else
|
||||||
|
return _props->hasValue(_path + string("/") + subpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the value of the current node.
|
* Return the value of the current node.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -261,6 +261,8 @@ public:
|
|||||||
virtual const_iterator begin () const { return _props.begin(); }
|
virtual const_iterator begin () const { return _props.begin(); }
|
||||||
virtual const_iterator end () const { return _props.end(); }
|
virtual const_iterator end () const { return _props.end(); }
|
||||||
|
|
||||||
|
virtual bool hasValue (const string &name) const;
|
||||||
|
|
||||||
virtual SGValue * getValue (const string &name, bool create = false);
|
virtual SGValue * getValue (const string &name, bool create = false);
|
||||||
virtual const SGValue * getValue (const string &name) const;
|
virtual const SGValue * getValue (const string &name) const;
|
||||||
|
|
||||||
@@ -374,6 +376,9 @@ public:
|
|||||||
virtual SGPropertyNode &getChild (int n) const;
|
virtual SGPropertyNode &getChild (int n) const;
|
||||||
virtual SGPropertyNode &getSubNode (const string &subpath) const;
|
virtual SGPropertyNode &getSubNode (const string &subpath) const;
|
||||||
|
|
||||||
|
// Check for a value.
|
||||||
|
virtual bool hasValue (const string &subpath = "") const;
|
||||||
|
|
||||||
// Get values directly.
|
// Get values directly.
|
||||||
virtual SGValue * getValue (const string &subpath = "");
|
virtual SGValue * getValue (const string &subpath = "");
|
||||||
virtual bool getBoolValue (const string &subpath = "",
|
virtual bool getBoolValue (const string &subpath = "",
|
||||||
|
|||||||
Reference in New Issue
Block a user