return (getRawDouble() == 0.0 ? false : true);
case UNKNOWN:
case STRING:
- return ((getRawString() == "false" || getIntValue() == 0) ? false : true);
+ return ((getRawString() == "true" || getIntValue() != 0) ? true : false);
}
return false;
}
bool
SGValue::setBoolValue (bool value)
{
- if (_type == UNKNOWN || _type == BOOL) {
- _type = BOOL;
+ if (_type == UNKNOWN)
+ _type = INT;
+ switch (_type) {
+ case BOOL:
return setRawBool(value);
- } else {
- return false;
+ case INT:
+ 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;
}
bool
SGValue::setIntValue (int value)
{
- if (_type == UNKNOWN || _type == INT) {
+ if (_type == UNKNOWN)
_type = INT;
+ switch (_type) {
+ case BOOL:
+ if (value == 0)
+ return setRawBool(false);
+ else
+ return setRawBool(true);
+ case INT:
return setRawInt(value);
- } else {
- return false;
+ case FLOAT:
+ return setRawFloat((float)value);
+ case DOUBLE:
+ return setRawDouble((double)value);
+ case STRING:
+ char buf[128];
+ sprintf(buf, "%d", value);
+ return setRawString(buf);
}
+ return false;
}
bool
SGValue::setFloatValue (float value)
{
- if (_type == UNKNOWN || _type == FLOAT) {
+ if (_type == UNKNOWN)
_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);
- } else {
- return false;
+ case DOUBLE:
+ return setRawDouble((double)value);
+ case STRING:
+ char buf[128];
+ sprintf(buf, "%f", value);
+ return setRawString(buf);
}
+ return false;
}
bool
SGValue::setDoubleValue (double value)
{
- if (_type == UNKNOWN || _type == DOUBLE) {
+ if (_type == UNKNOWN)
_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);
- } else {
- return false;
+ case STRING:
+ char buf[128];
+ sprintf(buf, "%lf", value);
+ return setRawString(buf);
}
+ return false;
}
bool
SGValue::setStringValue (const string &value)
{
- if (_type == UNKNOWN || _type == STRING) {
+ 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:
return setRawString(value);
- } else {
- return false;
}
+ return false;
}
bool
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);
- } else {
- return false;
}
+ return false;
}
if (_tied) {
return false;
} else {
- if (useDefault && setter && _type != UNKNOWN)
+ if (useDefault && setter)
(*setter)(getBoolValue());
_tied = true;
_type = BOOL;
if (_tied) {
return false;
} else {
- if (useDefault && setter && _type != UNKNOWN)
+ if (useDefault && setter)
(*setter)(getIntValue());
_tied = true;
_type = INT;
if (_tied) {
return false;
} else {
- if (useDefault && setter && _type != UNKNOWN)
+ if (useDefault && setter)
(*setter)(getFloatValue());
_tied = true;
_type = FLOAT;
if (_tied) {
return false;
} else {
- if (useDefault && setter && _type != UNKNOWN)
+ if (useDefault && setter)
(*setter)(getDoubleValue());
_tied = true;
_type = DOUBLE;
if (_tied) {
return false;
} else {
- if (useDefault && setter && _type != UNKNOWN)
+ if (useDefault && setter)
(*setter)(getStringValue());
_tied = true;
_type = STRING;
}
+/**
+ * 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.
*
bool useDefault)
{
FG_LOG(FG_GENERAL, FG_INFO, "Tying bool property '" << name << '\'');
+ useDefault = useDefault && hasValue(name);
return getValue(name, true)->tieBool(getter, setter, useDefault);
}
bool useDefault)
{
FG_LOG(FG_GENERAL, FG_INFO, "Tying int property '" << name << '\'');
+ useDefault = useDefault && hasValue(name);
return getValue(name, true)->tieInt(getter, setter, useDefault);
}
bool useDefault)
{
FG_LOG(FG_GENERAL, FG_INFO, "Tying float property '" << name << '\'');
+ useDefault = useDefault && hasValue(name);
return getValue(name, true)->tieFloat(getter, setter, useDefault);
}
bool useDefault)
{
FG_LOG(FG_GENERAL, FG_INFO, "Tying double property '" << name << '\'');
+ useDefault = useDefault && hasValue(name);
return getValue(name, true)->tieDouble(getter, setter, useDefault);
}
bool useDefault)
{
FG_LOG(FG_GENERAL, FG_INFO, "Tying string property '" << name << '\'');
+ useDefault = useDefault && hasValue(name);
return getValue(name, true)->tieString(getter, setter, useDefault);
}
}
+/**
+ * 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.
*