Melchior FRANZ:

Vivian pointed out that a redefined Ctrl-U key binding didn't work
correctly. I found out that this is, because the definition in
$FG_ROOT/keyboard.xml sets <value type="bool"> for binding[1],
and ... [better sit down first!] ... and assigning <value type="double">
in a *-set.xml file doesn't *really* set "double" as new type!

Instead, the boolean is kept, and a double sqeezed into it. In other
words: once tainted as bool, you can throw all doubles in the universe
on a property node, and all it will accept is 0 and 1. Without warning!

BTW: I changed the patch: I was overly cautious: clear_value() does already
care for ties and for setting NONE, so we just need to make that public as
clearValue(), and use that. Makes the patch a bit more verbose, though.  :-/
This commit is contained in:
ehofman
2005-05-09 14:31:41 +00:00
parent 4707b363aa
commit 64ab59c0e0
3 changed files with 30 additions and 28 deletions
+23 -22
View File
@@ -471,7 +471,7 @@ SGPropertyNode::set_string (const char * val)
} }
void void
SGPropertyNode::clear_value () SGPropertyNode::clearValue ()
{ {
switch (_type) { switch (_type) {
case NONE: case NONE:
@@ -762,7 +762,7 @@ SGPropertyNode::~SGPropertyNode ()
delete [] _display_name; delete [] _display_name;
delete [] _path; delete [] _path;
delete _path_cache; delete _path_cache;
clear_value(); clearValue();
delete _listeners; delete _listeners;
} }
@@ -775,7 +775,7 @@ SGPropertyNode::alias (SGPropertyNode * target)
{ {
if (target == 0 || _type == ALIAS || _tied) if (target == 0 || _type == ALIAS || _tied)
return false; return false;
clear_value(); clearValue();
_value.alias = target; _value.alias = target;
_type = ALIAS; _type = ALIAS;
return true; return true;
@@ -928,6 +928,7 @@ SGPropertyNode::removeChild (const char * name, int index, bool keep)
_removedChildren.push_back(node); _removedChildren.push_back(node);
} }
node->setAttribute(REMOVED, true); node->setAttribute(REMOVED, true);
node->clearValue();
ret = node; ret = node;
fireChildRemoved(node); fireChildRemoved(node);
} }
@@ -1168,7 +1169,7 @@ SGPropertyNode::setBoolValue (bool value)
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == NONE || _type == UNSPECIFIED) {
clear_value(); clearValue();
_tied = false; _tied = false;
_type = BOOL; _type = BOOL;
} }
@@ -1216,7 +1217,7 @@ SGPropertyNode::setIntValue (int value)
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == NONE || _type == UNSPECIFIED) {
clear_value(); clearValue();
_type = INT; _type = INT;
_local_val.int_val = 0; _local_val.int_val = 0;
} }
@@ -1267,7 +1268,7 @@ SGPropertyNode::setLongValue (long value)
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == NONE || _type == UNSPECIFIED) {
clear_value(); clearValue();
_type = LONG; _type = LONG;
_local_val.long_val = 0L; _local_val.long_val = 0L;
} }
@@ -1318,7 +1319,7 @@ SGPropertyNode::setFloatValue (float value)
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == NONE || _type == UNSPECIFIED) {
clear_value(); clearValue();
_type = FLOAT; _type = FLOAT;
_local_val.float_val = 0; _local_val.float_val = 0;
} }
@@ -1369,7 +1370,7 @@ SGPropertyNode::setDoubleValue (double value)
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == NONE || _type == UNSPECIFIED) {
clear_value(); clearValue();
_local_val.double_val = value; _local_val.double_val = value;
_type = DOUBLE; _type = DOUBLE;
} }
@@ -1420,7 +1421,7 @@ SGPropertyNode::setStringValue (const char * value)
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == NONE || _type == UNSPECIFIED) {
clear_value(); clearValue();
_type = STRING; _type = STRING;
} }
@@ -1464,7 +1465,7 @@ SGPropertyNode::setUnspecifiedValue (const char * value)
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE) { if (_type == NONE) {
clear_value(); clearValue();
_type = UNSPECIFIED; _type = UNSPECIFIED;
} }
@@ -1513,7 +1514,7 @@ SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
if (useDefault) if (useDefault)
old_val = getBoolValue(); old_val = getBoolValue();
clear_value(); clearValue();
_type = BOOL; _type = BOOL;
_tied = true; _tied = true;
_value.bool_val = rawValue.clone(); _value.bool_val = rawValue.clone();
@@ -1535,7 +1536,7 @@ SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
if (useDefault) if (useDefault)
old_val = getIntValue(); old_val = getIntValue();
clear_value(); clearValue();
_type = INT; _type = INT;
_tied = true; _tied = true;
_value.int_val = rawValue.clone(); _value.int_val = rawValue.clone();
@@ -1557,7 +1558,7 @@ SGPropertyNode::tie (const SGRawValue<long> &rawValue, bool useDefault)
if (useDefault) if (useDefault)
old_val = getLongValue(); old_val = getLongValue();
clear_value(); clearValue();
_type = LONG; _type = LONG;
_tied = true; _tied = true;
_value.long_val = rawValue.clone(); _value.long_val = rawValue.clone();
@@ -1579,7 +1580,7 @@ SGPropertyNode::tie (const SGRawValue<float> &rawValue, bool useDefault)
if (useDefault) if (useDefault)
old_val = getFloatValue(); old_val = getFloatValue();
clear_value(); clearValue();
_type = FLOAT; _type = FLOAT;
_tied = true; _tied = true;
_value.float_val = rawValue.clone(); _value.float_val = rawValue.clone();
@@ -1601,7 +1602,7 @@ SGPropertyNode::tie (const SGRawValue<double> &rawValue, bool useDefault)
if (useDefault) if (useDefault)
old_val = getDoubleValue(); old_val = getDoubleValue();
clear_value(); clearValue();
_type = DOUBLE; _type = DOUBLE;
_tied = true; _tied = true;
_value.double_val = rawValue.clone(); _value.double_val = rawValue.clone();
@@ -1624,7 +1625,7 @@ SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, bool useDefault)
if (useDefault) if (useDefault)
old_val = getStringValue(); old_val = getStringValue();
clear_value(); clearValue();
_type = STRING; _type = STRING;
_tied = true; _tied = true;
_value.string_val = rawValue.clone(); _value.string_val = rawValue.clone();
@@ -1644,35 +1645,35 @@ SGPropertyNode::untie ()
switch (_type) { switch (_type) {
case BOOL: { case BOOL: {
bool val = getBoolValue(); bool val = getBoolValue();
clear_value(); clearValue();
_type = BOOL; _type = BOOL;
_local_val.bool_val = val; _local_val.bool_val = val;
break; break;
} }
case INT: { case INT: {
int val = getIntValue(); int val = getIntValue();
clear_value(); clearValue();
_type = INT; _type = INT;
_local_val.int_val = val; _local_val.int_val = val;
break; break;
} }
case LONG: { case LONG: {
long val = getLongValue(); long val = getLongValue();
clear_value(); clearValue();
_type = LONG; _type = LONG;
_local_val.long_val = val; _local_val.long_val = val;
break; break;
} }
case FLOAT: { case FLOAT: {
float val = getFloatValue(); float val = getFloatValue();
clear_value(); clearValue();
_type = FLOAT; _type = FLOAT;
_local_val.float_val = val; _local_val.float_val = val;
break; break;
} }
case DOUBLE: { case DOUBLE: {
double val = getDoubleValue(); double val = getDoubleValue();
clear_value(); clearValue();
_type = DOUBLE; _type = DOUBLE;
_local_val.double_val = val; _local_val.double_val = val;
break; break;
@@ -1680,7 +1681,7 @@ SGPropertyNode::untie ()
case STRING: case STRING:
case UNSPECIFIED: { case UNSPECIFIED: {
string val = getStringValue(); string val = getStringValue();
clear_value(); clearValue();
_type = STRING; _type = STRING;
_local_val.string_val = copy_string(val.c_str()); _local_val.string_val = copy_string(val.c_str());
break; break;
+6 -6
View File
@@ -1172,6 +1172,12 @@ public:
void fireChildRemoved (SGPropertyNode * child); void fireChildRemoved (SGPropertyNode * child);
/**
* Clear any existing value and set the type to NONE.
*/
void clearValue ();
protected: protected:
void fireValueChanged (SGPropertyNode * node); void fireValueChanged (SGPropertyNode * node);
@@ -1203,12 +1209,6 @@ private:
bool set_string (const char * value); bool set_string (const char * value);
/**
* Clear any existing value and set the type to NONE.
*/
void clear_value ();
/** /**
* Get the value as a string. * Get the value as a string.
*/ */
+1
View File
@@ -173,6 +173,7 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
// Got the index, so grab the node. // Got the index, so grab the node.
SGPropertyNode * node = st.node->getChild(name, index, true); SGPropertyNode * node = st.node->getChild(name, index, true);
node->clearValue();
// Get the access-mode attributes, // Get the access-mode attributes,
// but don't set yet (in case they // but don't set yet (in case they