Change references to property types

BOOL, FLOAT etc. conflict with typedefs in windows.h, so these types
are referred to using the props:: namespace.
This commit is contained in:
Tim Moore
2009-07-17 14:52:58 +02:00
parent d3f5bc6e2d
commit fcf72a7123
4 changed files with 246 additions and 248 deletions
+9 -9
View File
@@ -144,9 +144,9 @@ SGOrCondition::addCondition (SGCondition * condition)
static int static int
doComparison (const SGPropertyNode * left, const SGPropertyNode *right) doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
{ {
using namespace simgear::props; using namespace simgear;
switch (left->getType()) { switch (left->getType()) {
case BOOL: { case props::BOOL: {
bool v1 = left->getBoolValue(); bool v1 = left->getBoolValue();
bool v2 = right->getBoolValue(); bool v2 = right->getBoolValue();
if (v1 < v2) if (v1 < v2)
@@ -157,7 +157,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
return SGComparisonCondition::EQUALS; return SGComparisonCondition::EQUALS;
break; break;
} }
case INT: { case props::INT: {
int v1 = left->getIntValue(); int v1 = left->getIntValue();
int v2 = right->getIntValue(); int v2 = right->getIntValue();
if (v1 < v2) if (v1 < v2)
@@ -168,7 +168,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
return SGComparisonCondition::EQUALS; return SGComparisonCondition::EQUALS;
break; break;
} }
case LONG: { case props::LONG: {
long v1 = left->getLongValue(); long v1 = left->getLongValue();
long v2 = right->getLongValue(); long v2 = right->getLongValue();
if (v1 < v2) if (v1 < v2)
@@ -179,7 +179,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
return SGComparisonCondition::EQUALS; return SGComparisonCondition::EQUALS;
break; break;
} }
case FLOAT: { case props::FLOAT: {
float v1 = left->getFloatValue(); float v1 = left->getFloatValue();
float v2 = right->getFloatValue(); float v2 = right->getFloatValue();
if (v1 < v2) if (v1 < v2)
@@ -190,7 +190,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
return SGComparisonCondition::EQUALS; return SGComparisonCondition::EQUALS;
break; break;
} }
case DOUBLE: { case props::DOUBLE: {
double v1 = left->getDoubleValue(); double v1 = left->getDoubleValue();
double v2 = right->getDoubleValue(); double v2 = right->getDoubleValue();
if (v1 < v2) if (v1 < v2)
@@ -201,9 +201,9 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
return SGComparisonCondition::EQUALS; return SGComparisonCondition::EQUALS;
break; break;
} }
case STRING: case props::STRING:
case NONE: case props::NONE:
case UNSPECIFIED: { case props::UNSPECIFIED: {
string v1 = left->getStringValue(); string v1 = left->getStringValue();
string v2 = right->getStringValue(); string v2 = right->getStringValue();
if (v1 < v2) if (v1 < v2)
+211 -212
View File
@@ -43,7 +43,6 @@ using std::vector;
using std::stringstream; using std::stringstream;
using namespace simgear; using namespace simgear;
using namespace simgear::props;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@@ -489,28 +488,28 @@ SGPropertyNode::set_string (const char * val)
void void
SGPropertyNode::clearValue () SGPropertyNode::clearValue ()
{ {
if (_type == ALIAS) { if (_type == props::ALIAS) {
put(_value.alias); put(_value.alias);
_value.alias = 0; _value.alias = 0;
} else if (_type != NONE) { } else if (_type != props::NONE) {
switch (_type) { switch (_type) {
case BOOL: case props::BOOL:
_local_val.bool_val = SGRawValue<bool>::DefaultValue(); _local_val.bool_val = SGRawValue<bool>::DefaultValue();
break; break;
case INT: case props::INT:
_local_val.int_val = SGRawValue<int>::DefaultValue(); _local_val.int_val = SGRawValue<int>::DefaultValue();
break; break;
case LONG: case props::LONG:
_local_val.long_val = SGRawValue<long>::DefaultValue(); _local_val.long_val = SGRawValue<long>::DefaultValue();
break; break;
case FLOAT: case props::FLOAT:
_local_val.float_val = SGRawValue<float>::DefaultValue(); _local_val.float_val = SGRawValue<float>::DefaultValue();
break; break;
case DOUBLE: case props::DOUBLE:
_local_val.double_val = SGRawValue<double>::DefaultValue(); _local_val.double_val = SGRawValue<double>::DefaultValue();
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
if (!_tied) { if (!_tied) {
delete [] _local_val.string_val; delete [] _local_val.string_val;
} }
@@ -521,7 +520,7 @@ SGPropertyNode::clearValue ()
_value.val = 0; _value.val = 0;
} }
_tied = false; _tied = false;
_type = NONE; _type = props::NONE;
} }
@@ -534,37 +533,37 @@ SGPropertyNode::make_string () const
if (!getAttribute(READ)) if (!getAttribute(READ))
return ""; return "";
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
return _value.alias->getStringValue(); return _value.alias->getStringValue();
case BOOL: case props::BOOL:
return get_bool() ? "true" : "false"; return get_bool() ? "true" : "false";
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
return get_string(); return get_string();
case NONE: case props::NONE:
return ""; return "";
default: default:
break; break;
} }
stringstream sstr; stringstream sstr;
switch (_type) { switch (_type) {
case INT: case props::INT:
sstr << get_int(); sstr << get_int();
break; break;
case LONG: case props::LONG:
sstr << get_long(); sstr << get_long();
break; break;
case FLOAT: case props::FLOAT:
sstr << get_float(); sstr << get_float();
break; break;
case DOUBLE: case props::DOUBLE:
sstr << std::setprecision(10) << get_double(); sstr << std::setprecision(10) << get_double();
break; break;
case EXTENDED: case props::EXTENDED:
{ {
Type realType = _value.val->getType(); props::Type realType = _value.val->getType();
// Perhaps this should be done for all types? // Perhaps this should be done for all types?
if (realType == VEC3D || realType == VEC4D) if (realType == props::VEC3D || realType == props::VEC4D)
sstr.precision(10); sstr.precision(10);
static_cast<SGRawExtended*>(_value.val)->printOn(sstr); static_cast<SGRawExtended*>(_value.val)->printOn(sstr);
} }
@@ -624,7 +623,7 @@ SGPropertyNode::SGPropertyNode ()
: _index(0), : _index(0),
_parent(0), _parent(0),
_path_cache(0), _path_cache(0),
_type(NONE), _type(props::NONE),
_tied(false), _tied(false),
_attr(READ|WRITE), _attr(READ|WRITE),
_listeners(0) _listeners(0)
@@ -649,36 +648,36 @@ SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
{ {
_local_val.string_val = 0; _local_val.string_val = 0;
_value.val = 0; _value.val = 0;
if (_type == NONE) if (_type == props::NONE)
return; return;
if (_type == ALIAS) { if (_type == props::ALIAS) {
_value.alias = node._value.alias; _value.alias = node._value.alias;
get(_value.alias); get(_value.alias);
_tied = false; _tied = false;
return; return;
} }
if (_tied || _type == EXTENDED) { if (_tied || _type == props::EXTENDED) {
_value.val = node._value.val->clone(); _value.val = node._value.val->clone();
return; return;
} }
switch (_type) { switch (_type) {
case BOOL: case props::BOOL:
set_bool(node.get_bool()); set_bool(node.get_bool());
break; break;
case INT: case props::INT:
set_int(node.get_int()); set_int(node.get_int());
break; break;
case LONG: case props::LONG:
set_long(node.get_long()); set_long(node.get_long());
break; break;
case FLOAT: case props::FLOAT:
set_float(node.get_float()); set_float(node.get_float());
break; break;
case DOUBLE: case props::DOUBLE:
set_double(node.get_double()); set_double(node.get_double());
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
set_string(node.get_string()); set_string(node.get_string());
break; break;
default: default:
@@ -696,7 +695,7 @@ SGPropertyNode::SGPropertyNode (const char * name,
: _index(index), : _index(index),
_parent(parent), _parent(parent),
_path_cache(0), _path_cache(0),
_type(NONE), _type(props::NONE),
_tied(false), _tied(false),
_attr(READ|WRITE), _attr(READ|WRITE),
_listeners(0) _listeners(0)
@@ -738,12 +737,12 @@ SGPropertyNode::~SGPropertyNode ()
bool bool
SGPropertyNode::alias (SGPropertyNode * target) SGPropertyNode::alias (SGPropertyNode * target)
{ {
if (target == 0 || _type == ALIAS || _tied) if (target == 0 || _type == props::ALIAS || _tied)
return false; return false;
clearValue(); clearValue();
get(target); get(target);
_value.alias = target; _value.alias = target;
_type = ALIAS; _type = props::ALIAS;
return true; return true;
} }
@@ -764,7 +763,7 @@ SGPropertyNode::alias (const char * path)
bool bool
SGPropertyNode::unalias () SGPropertyNode::unalias ()
{ {
if (_type != ALIAS) if (_type != props::ALIAS)
return false; return false;
clearValue(); clearValue();
return true; return true;
@@ -777,14 +776,14 @@ SGPropertyNode::unalias ()
SGPropertyNode * SGPropertyNode *
SGPropertyNode::getAliasTarget () SGPropertyNode::getAliasTarget ()
{ {
return (_type == ALIAS ? _value.alias : 0); return (_type == props::ALIAS ? _value.alias : 0);
} }
const SGPropertyNode * const SGPropertyNode *
SGPropertyNode::getAliasTarget () const SGPropertyNode::getAliasTarget () const
{ {
return (_type == ALIAS ? _value.alias : 0); return (_type == props::ALIAS ? _value.alias : 0);
} }
/** /**
@@ -1008,12 +1007,12 @@ SGPropertyNode::getPath (bool simplify) const
return _path.c_str(); return _path.c_str();
} }
Type props::Type
SGPropertyNode::getType () const SGPropertyNode::getType () const
{ {
if (_type == ALIAS) if (_type == props::ALIAS)
return _value.alias->getType(); return _value.alias->getType();
else if (_type == EXTENDED) else if (_type == props::EXTENDED)
return _value.val->getType(); return _value.val->getType();
else else
return _type; return _type;
@@ -1024,7 +1023,7 @@ bool
SGPropertyNode::getBoolValue () const SGPropertyNode::getBoolValue () const
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == BOOL) if (_attr == (READ|WRITE) && _type == props::BOOL)
return get_bool(); return get_bool();
if (getAttribute(TRACE_READ)) if (getAttribute(TRACE_READ))
@@ -1032,22 +1031,22 @@ SGPropertyNode::getBoolValue () const
if (!getAttribute(READ)) if (!getAttribute(READ))
return SGRawValue<bool>::DefaultValue(); return SGRawValue<bool>::DefaultValue();
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
return _value.alias->getBoolValue(); return _value.alias->getBoolValue();
case BOOL: case props::BOOL:
return get_bool(); return get_bool();
case INT: case props::INT:
return get_int() == 0 ? false : true; return get_int() == 0 ? false : true;
case LONG: case props::LONG:
return get_long() == 0L ? false : true; return get_long() == 0L ? false : true;
case FLOAT: case props::FLOAT:
return get_float() == 0.0 ? false : true; return get_float() == 0.0 ? false : true;
case DOUBLE: case props::DOUBLE:
return get_double() == 0.0L ? false : true; return get_double() == 0.0L ? false : true;
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
return (compare_strings(get_string(), "true") || getDoubleValue() != 0.0L); return (compare_strings(get_string(), "true") || getDoubleValue() != 0.0L);
case NONE: case props::NONE:
default: default:
return SGRawValue<bool>::DefaultValue(); return SGRawValue<bool>::DefaultValue();
} }
@@ -1057,7 +1056,7 @@ int
SGPropertyNode::getIntValue () const SGPropertyNode::getIntValue () const
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == INT) if (_attr == (READ|WRITE) && _type == props::INT)
return get_int(); return get_int();
if (getAttribute(TRACE_READ)) if (getAttribute(TRACE_READ))
@@ -1065,22 +1064,22 @@ SGPropertyNode::getIntValue () const
if (!getAttribute(READ)) if (!getAttribute(READ))
return SGRawValue<int>::DefaultValue(); return SGRawValue<int>::DefaultValue();
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
return _value.alias->getIntValue(); return _value.alias->getIntValue();
case BOOL: case props::BOOL:
return int(get_bool()); return int(get_bool());
case INT: case props::INT:
return get_int(); return get_int();
case LONG: case props::LONG:
return int(get_long()); return int(get_long());
case FLOAT: case props::FLOAT:
return int(get_float()); return int(get_float());
case DOUBLE: case props::DOUBLE:
return int(get_double()); return int(get_double());
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
return atoi(get_string()); return atoi(get_string());
case NONE: case props::NONE:
default: default:
return SGRawValue<int>::DefaultValue(); return SGRawValue<int>::DefaultValue();
} }
@@ -1090,7 +1089,7 @@ long
SGPropertyNode::getLongValue () const SGPropertyNode::getLongValue () const
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == LONG) if (_attr == (READ|WRITE) && _type == props::LONG)
return get_long(); return get_long();
if (getAttribute(TRACE_READ)) if (getAttribute(TRACE_READ))
@@ -1098,22 +1097,22 @@ SGPropertyNode::getLongValue () const
if (!getAttribute(READ)) if (!getAttribute(READ))
return SGRawValue<long>::DefaultValue(); return SGRawValue<long>::DefaultValue();
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
return _value.alias->getLongValue(); return _value.alias->getLongValue();
case BOOL: case props::BOOL:
return long(get_bool()); return long(get_bool());
case INT: case props::INT:
return long(get_int()); return long(get_int());
case LONG: case props::LONG:
return get_long(); return get_long();
case FLOAT: case props::FLOAT:
return long(get_float()); return long(get_float());
case DOUBLE: case props::DOUBLE:
return long(get_double()); return long(get_double());
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
return strtol(get_string(), 0, 0); return strtol(get_string(), 0, 0);
case NONE: case props::NONE:
default: default:
return SGRawValue<long>::DefaultValue(); return SGRawValue<long>::DefaultValue();
} }
@@ -1123,7 +1122,7 @@ float
SGPropertyNode::getFloatValue () const SGPropertyNode::getFloatValue () const
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == FLOAT) if (_attr == (READ|WRITE) && _type == props::FLOAT)
return get_float(); return get_float();
if (getAttribute(TRACE_READ)) if (getAttribute(TRACE_READ))
@@ -1131,22 +1130,22 @@ SGPropertyNode::getFloatValue () const
if (!getAttribute(READ)) if (!getAttribute(READ))
return SGRawValue<float>::DefaultValue(); return SGRawValue<float>::DefaultValue();
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
return _value.alias->getFloatValue(); return _value.alias->getFloatValue();
case BOOL: case props::BOOL:
return float(get_bool()); return float(get_bool());
case INT: case props::INT:
return float(get_int()); return float(get_int());
case LONG: case props::LONG:
return float(get_long()); return float(get_long());
case FLOAT: case props::FLOAT:
return get_float(); return get_float();
case DOUBLE: case props::DOUBLE:
return float(get_double()); return float(get_double());
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
return atof(get_string()); return atof(get_string());
case NONE: case props::NONE:
default: default:
return SGRawValue<float>::DefaultValue(); return SGRawValue<float>::DefaultValue();
} }
@@ -1156,7 +1155,7 @@ double
SGPropertyNode::getDoubleValue () const SGPropertyNode::getDoubleValue () const
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == DOUBLE) if (_attr == (READ|WRITE) && _type == props::DOUBLE)
return get_double(); return get_double();
if (getAttribute(TRACE_READ)) if (getAttribute(TRACE_READ))
@@ -1165,22 +1164,22 @@ SGPropertyNode::getDoubleValue () const
return SGRawValue<double>::DefaultValue(); return SGRawValue<double>::DefaultValue();
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
return _value.alias->getDoubleValue(); return _value.alias->getDoubleValue();
case BOOL: case props::BOOL:
return double(get_bool()); return double(get_bool());
case INT: case props::INT:
return double(get_int()); return double(get_int());
case LONG: case props::LONG:
return double(get_long()); return double(get_long());
case FLOAT: case props::FLOAT:
return double(get_float()); return double(get_float());
case DOUBLE: case props::DOUBLE:
return get_double(); return get_double();
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
return strtod(get_string(), 0); return strtod(get_string(), 0);
case NONE: case props::NONE:
default: default:
return SGRawValue<double>::DefaultValue(); return SGRawValue<double>::DefaultValue();
} }
@@ -1190,7 +1189,7 @@ const char *
SGPropertyNode::getStringValue () const SGPropertyNode::getStringValue () const
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == STRING) if (_attr == (READ|WRITE) && _type == props::STRING)
return get_string(); return get_string();
if (getAttribute(TRACE_READ)) if (getAttribute(TRACE_READ))
@@ -1204,41 +1203,41 @@ bool
SGPropertyNode::setBoolValue (bool value) SGPropertyNode::setBoolValue (bool value)
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == BOOL) if (_attr == (READ|WRITE) && _type == props::BOOL)
return set_bool(value); return set_bool(value);
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == props::NONE || _type == props::UNSPECIFIED) {
clearValue(); clearValue();
_tied = false; _tied = false;
_type = BOOL; _type = props::BOOL;
} }
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
result = _value.alias->setBoolValue(value); result = _value.alias->setBoolValue(value);
break; break;
case BOOL: case props::BOOL:
result = set_bool(value); result = set_bool(value);
break; break;
case INT: case props::INT:
result = set_int(int(value)); result = set_int(int(value));
break; break;
case LONG: case props::LONG:
result = set_long(long(value)); result = set_long(long(value));
break; break;
case FLOAT: case props::FLOAT:
result = set_float(float(value)); result = set_float(float(value));
break; break;
case DOUBLE: case props::DOUBLE:
result = set_double(double(value)); result = set_double(double(value));
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
result = set_string(value ? "true" : "false"); result = set_string(value ? "true" : "false");
break; break;
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1252,44 +1251,44 @@ bool
SGPropertyNode::setIntValue (int value) SGPropertyNode::setIntValue (int value)
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == INT) if (_attr == (READ|WRITE) && _type == props::INT)
return set_int(value); return set_int(value);
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == props::NONE || _type == props::UNSPECIFIED) {
clearValue(); clearValue();
_type = INT; _type = props::INT;
_local_val.int_val = 0; _local_val.int_val = 0;
} }
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
result = _value.alias->setIntValue(value); result = _value.alias->setIntValue(value);
break; break;
case BOOL: case props::BOOL:
result = set_bool(value == 0 ? false : true); result = set_bool(value == 0 ? false : true);
break; break;
case INT: case props::INT:
result = set_int(value); result = set_int(value);
break; break;
case LONG: case props::LONG:
result = set_long(long(value)); result = set_long(long(value));
break; break;
case FLOAT: case props::FLOAT:
result = set_float(float(value)); result = set_float(float(value));
break; break;
case DOUBLE: case props::DOUBLE:
result = set_double(double(value)); result = set_double(double(value));
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: { case props::UNSPECIFIED: {
char buf[128]; char buf[128];
sprintf(buf, "%d", value); sprintf(buf, "%d", value);
result = set_string(buf); result = set_string(buf);
break; break;
} }
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1303,44 +1302,44 @@ bool
SGPropertyNode::setLongValue (long value) SGPropertyNode::setLongValue (long value)
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == LONG) if (_attr == (READ|WRITE) && _type == props::LONG)
return set_long(value); return set_long(value);
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == props::NONE || _type == props::UNSPECIFIED) {
clearValue(); clearValue();
_type = LONG; _type = props::LONG;
_local_val.long_val = 0L; _local_val.long_val = 0L;
} }
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
result = _value.alias->setLongValue(value); result = _value.alias->setLongValue(value);
break; break;
case BOOL: case props::BOOL:
result = set_bool(value == 0L ? false : true); result = set_bool(value == 0L ? false : true);
break; break;
case INT: case props::INT:
result = set_int(int(value)); result = set_int(int(value));
break; break;
case LONG: case props::LONG:
result = set_long(value); result = set_long(value);
break; break;
case FLOAT: case props::FLOAT:
result = set_float(float(value)); result = set_float(float(value));
break; break;
case DOUBLE: case props::DOUBLE:
result = set_double(double(value)); result = set_double(double(value));
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: { case props::UNSPECIFIED: {
char buf[128]; char buf[128];
sprintf(buf, "%ld", value); sprintf(buf, "%ld", value);
result = set_string(buf); result = set_string(buf);
break; break;
} }
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1354,44 +1353,44 @@ bool
SGPropertyNode::setFloatValue (float value) SGPropertyNode::setFloatValue (float value)
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == FLOAT) if (_attr == (READ|WRITE) && _type == props::FLOAT)
return set_float(value); return set_float(value);
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == props::NONE || _type == props::UNSPECIFIED) {
clearValue(); clearValue();
_type = FLOAT; _type = props::FLOAT;
_local_val.float_val = 0; _local_val.float_val = 0;
} }
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
result = _value.alias->setFloatValue(value); result = _value.alias->setFloatValue(value);
break; break;
case BOOL: case props::BOOL:
result = set_bool(value == 0.0 ? false : true); result = set_bool(value == 0.0 ? false : true);
break; break;
case INT: case props::INT:
result = set_int(int(value)); result = set_int(int(value));
break; break;
case LONG: case props::LONG:
result = set_long(long(value)); result = set_long(long(value));
break; break;
case FLOAT: case props::FLOAT:
result = set_float(value); result = set_float(value);
break; break;
case DOUBLE: case props::DOUBLE:
result = set_double(double(value)); result = set_double(double(value));
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: { case props::UNSPECIFIED: {
char buf[128]; char buf[128];
sprintf(buf, "%f", value); sprintf(buf, "%f", value);
result = set_string(buf); result = set_string(buf);
break; break;
} }
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1405,44 +1404,44 @@ bool
SGPropertyNode::setDoubleValue (double value) SGPropertyNode::setDoubleValue (double value)
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == DOUBLE) if (_attr == (READ|WRITE) && _type == props::DOUBLE)
return set_double(value); return set_double(value);
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == props::NONE || _type == props::UNSPECIFIED) {
clearValue(); clearValue();
_local_val.double_val = value; _local_val.double_val = value;
_type = DOUBLE; _type = props::DOUBLE;
} }
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
result = _value.alias->setDoubleValue(value); result = _value.alias->setDoubleValue(value);
break; break;
case BOOL: case props::BOOL:
result = set_bool(value == 0.0L ? false : true); result = set_bool(value == 0.0L ? false : true);
break; break;
case INT: case props::INT:
result = set_int(int(value)); result = set_int(int(value));
break; break;
case LONG: case props::LONG:
result = set_long(long(value)); result = set_long(long(value));
break; break;
case FLOAT: case props::FLOAT:
result = set_float(float(value)); result = set_float(float(value));
break; break;
case DOUBLE: case props::DOUBLE:
result = set_double(value); result = set_double(value);
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: { case props::UNSPECIFIED: {
char buf[128]; char buf[128];
sprintf(buf, "%f", value); sprintf(buf, "%f", value);
result = set_string(buf); result = set_string(buf);
break; break;
} }
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1456,47 +1455,47 @@ bool
SGPropertyNode::setStringValue (const char * value) SGPropertyNode::setStringValue (const char * value)
{ {
// Shortcut for common case // Shortcut for common case
if (_attr == (READ|WRITE) && _type == STRING) if (_attr == (READ|WRITE) && _type == props::STRING)
return set_string(value); return set_string(value);
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE || _type == UNSPECIFIED) { if (_type == props::NONE || _type == props::UNSPECIFIED) {
clearValue(); clearValue();
_type = STRING; _type = props::STRING;
} }
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
result = _value.alias->setStringValue(value); result = _value.alias->setStringValue(value);
break; break;
case BOOL: case props::BOOL:
result = set_bool((compare_strings(value, "true") result = set_bool((compare_strings(value, "true")
|| atoi(value)) ? true : false); || atoi(value)) ? true : false);
break; break;
case INT: case props::INT:
result = set_int(atoi(value)); result = set_int(atoi(value));
break; break;
case LONG: case props::LONG:
result = set_long(strtol(value, 0, 0)); result = set_long(strtol(value, 0, 0));
break; break;
case FLOAT: case props::FLOAT:
result = set_float(atof(value)); result = set_float(atof(value));
break; break;
case DOUBLE: case props::DOUBLE:
result = set_double(strtod(value, 0)); result = set_double(strtod(value, 0));
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
result = set_string(value); result = set_string(value);
break; break;
case EXTENDED: case props::EXTENDED:
{ {
stringstream sstr(value); stringstream sstr(value);
static_cast<SGRawExtended*>(_value.val)->readFrom(sstr); static_cast<SGRawExtended*>(_value.val)->readFrom(sstr);
} }
break; break;
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1511,44 +1510,44 @@ SGPropertyNode::setUnspecifiedValue (const char * value)
{ {
bool result = false; bool result = false;
TEST_WRITE; TEST_WRITE;
if (_type == NONE) { if (_type == props::NONE) {
clearValue(); clearValue();
_type = UNSPECIFIED; _type = props::UNSPECIFIED;
} }
Type type = _type; props::Type type = _type;
if (type == EXTENDED) if (type == props::EXTENDED)
type = _value.val->getType(); type = _value.val->getType();
switch (type) { switch (type) {
case ALIAS: case props::ALIAS:
result = _value.alias->setUnspecifiedValue(value); result = _value.alias->setUnspecifiedValue(value);
break; break;
case BOOL: case props::BOOL:
result = set_bool((compare_strings(value, "true") result = set_bool((compare_strings(value, "true")
|| atoi(value)) ? true : false); || atoi(value)) ? true : false);
break; break;
case INT: case props::INT:
result = set_int(atoi(value)); result = set_int(atoi(value));
break; break;
case LONG: case props::LONG:
result = set_long(strtol(value, 0, 0)); result = set_long(strtol(value, 0, 0));
break; break;
case FLOAT: case props::FLOAT:
result = set_float(atof(value)); result = set_float(atof(value));
break; break;
case DOUBLE: case props::DOUBLE:
result = set_double(strtod(value, 0)); result = set_double(strtod(value, 0));
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
result = set_string(value); result = set_string(value);
break; break;
case VEC3D: case props::VEC3D:
result = static_cast<SGRawValue<SGVec3d>*>(_value.val)->setValue(parseString<SGVec3d>(value)); result = static_cast<SGRawValue<SGVec3d>*>(_value.val)->setValue(parseString<SGVec3d>(value));
break; break;
case VEC4D: case props::VEC4D:
result = static_cast<SGRawValue<SGVec4d>*>(_value.val)->setValue(parseString<SGVec4d>(value)); result = static_cast<SGRawValue<SGVec4d>*>(_value.val)->setValue(parseString<SGVec4d>(value));
break; break;
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1563,31 +1562,31 @@ std::ostream& SGPropertyNode::printOn(std::ostream& stream) const
if (!getAttribute(READ)) if (!getAttribute(READ))
return stream; return stream;
switch (_type) { switch (_type) {
case ALIAS: case props::ALIAS:
return _value.alias->printOn(stream); return _value.alias->printOn(stream);
case BOOL: case props::BOOL:
stream << (get_bool() ? "true" : "false"); stream << (get_bool() ? "true" : "false");
break; break;
case INT: case props::INT:
stream << get_int(); stream << get_int();
break; break;
case LONG: case props::LONG:
stream << get_long(); stream << get_long();
break; break;
case FLOAT: case props::FLOAT:
stream << get_float(); stream << get_float();
break; break;
case DOUBLE: case props::DOUBLE:
stream << get_double(); stream << get_double();
break; break;
case STRING: case props::STRING:
case UNSPECIFIED: case props::UNSPECIFIED:
stream << get_string(); stream << get_string();
break; break;
case EXTENDED: case props::EXTENDED:
static_cast<SGRawExtended*>(_value.val)->printOn(stream); static_cast<SGRawExtended*>(_value.val)->printOn(stream);
break; break;
case NONE: case props::NONE:
break; break;
} }
return stream; return stream;
@@ -1597,7 +1596,7 @@ template<>
bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue,
bool useDefault) bool useDefault)
{ {
if (_type == ALIAS || _tied) if (_type == props::ALIAS || _tied)
return false; return false;
useDefault = useDefault && hasValue(); useDefault = useDefault && hasValue();
@@ -1605,7 +1604,7 @@ bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue,
if (useDefault) if (useDefault)
old_val = getStringValue(); old_val = getStringValue();
clearValue(); clearValue();
_type = STRING; _type = props::STRING;
_tied = true; _tied = true;
_value.val = rawValue.clone(); _value.val = rawValue.clone();
@@ -1621,59 +1620,59 @@ SGPropertyNode::untie ()
return false; return false;
switch (_type) { switch (_type) {
case BOOL: { case props::BOOL: {
bool val = getBoolValue(); bool val = getBoolValue();
clearValue(); clearValue();
_type = BOOL; _type = props::BOOL;
_local_val.bool_val = val; _local_val.bool_val = val;
break; break;
} }
case INT: { case props::INT: {
int val = getIntValue(); int val = getIntValue();
clearValue(); clearValue();
_type = INT; _type = props::INT;
_local_val.int_val = val; _local_val.int_val = val;
break; break;
} }
case LONG: { case props::LONG: {
long val = getLongValue(); long val = getLongValue();
clearValue(); clearValue();
_type = LONG; _type = props::LONG;
_local_val.long_val = val; _local_val.long_val = val;
break; break;
} }
case FLOAT: { case props::FLOAT: {
float val = getFloatValue(); float val = getFloatValue();
clearValue(); clearValue();
_type = FLOAT; _type = props::FLOAT;
_local_val.float_val = val; _local_val.float_val = val;
break; break;
} }
case DOUBLE: { case props::DOUBLE: {
double val = getDoubleValue(); double val = getDoubleValue();
clearValue(); clearValue();
_type = DOUBLE; _type = props::DOUBLE;
_local_val.double_val = val; _local_val.double_val = val;
break; break;
} }
case STRING: case props::STRING:
case UNSPECIFIED: { case props::UNSPECIFIED: {
string val = getStringValue(); string val = getStringValue();
clearValue(); clearValue();
_type = STRING; _type = props::STRING;
_local_val.string_val = copy_string(val.c_str()); _local_val.string_val = copy_string(val.c_str());
break; break;
} }
case EXTENDED: { case props::EXTENDED: {
SGRawExtended* val = static_cast<SGRawExtended*>(_value.val); SGRawExtended* val = static_cast<SGRawExtended*>(_value.val);
_value.val = 0; // Prevent clearValue() from deleting _value.val = 0; // Prevent clearValue() from deleting
clearValue(); clearValue();
_type = EXTENDED; _type = props::EXTENDED;
_value.val = val->makeContainer(); _value.val = val->makeContainer();
delete val; delete val;
break; break;
} }
case NONE: case props::NONE:
default: default:
break; break;
} }
@@ -1760,11 +1759,11 @@ SGPropertyNode::hasValue (const char * relative_path) const
/** /**
* Get the value type for another node. * Get the value type for another node.
*/ */
Type props::Type
SGPropertyNode::getType (const char * relative_path) const SGPropertyNode::getType (const char * relative_path) const
{ {
const SGPropertyNode * node = getNode(relative_path); const SGPropertyNode * node = getNode(relative_path);
return (node == 0 ? UNSPECIFIED : (Type)(node->getType())); return (node == 0 ? props::UNSPECIFIED : node->getType());
} }
+22 -22
View File
@@ -414,28 +414,28 @@ void readProperties (const char *buf, const int size,
static const char * static const char *
getTypeName (simgear::props::Type type) getTypeName (simgear::props::Type type)
{ {
using namespace simgear::props; using namespace simgear;
switch (type) { switch (type) {
case UNSPECIFIED: case props::UNSPECIFIED:
return "unspecified"; return "unspecified";
case BOOL: case props::BOOL:
return "bool"; return "bool";
case INT: case props::INT:
return "int"; return "int";
case LONG: case props::LONG:
return "long"; return "long";
case FLOAT: case props::FLOAT:
return "float"; return "float";
case DOUBLE: case props::DOUBLE:
return "double"; return "double";
case STRING: case props::STRING:
return "string"; return "string";
case VEC3D: case props::VEC3D:
return "vec3d"; return "vec3d";
case VEC4D: case props::VEC4D:
return "vec4d"; return "vec4d";
case ALIAS: case props::ALIAS:
case NONE: case props::NONE:
return "unspecified"; return "unspecified";
} }
@@ -617,46 +617,46 @@ writeProperties (const string &file, const SGPropertyNode * start_node,
bool bool
copyProperties (const SGPropertyNode *in, SGPropertyNode *out) copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
{ {
using namespace simgear::props; using namespace simgear;
bool retval = true; bool retval = true;
// First, copy the actual value, // First, copy the actual value,
// if any. // if any.
if (in->hasValue()) { if (in->hasValue()) {
switch (in->getType()) { switch (in->getType()) {
case BOOL: case props::BOOL:
if (!out->setBoolValue(in->getBoolValue())) if (!out->setBoolValue(in->getBoolValue()))
retval = false; retval = false;
break; break;
case INT: case props::INT:
if (!out->setIntValue(in->getIntValue())) if (!out->setIntValue(in->getIntValue()))
retval = false; retval = false;
break; break;
case LONG: case props::LONG:
if (!out->setLongValue(in->getLongValue())) if (!out->setLongValue(in->getLongValue()))
retval = false; retval = false;
break; break;
case FLOAT: case props::FLOAT:
if (!out->setFloatValue(in->getFloatValue())) if (!out->setFloatValue(in->getFloatValue()))
retval = false; retval = false;
break; break;
case DOUBLE: case props::DOUBLE:
if (!out->setDoubleValue(in->getDoubleValue())) if (!out->setDoubleValue(in->getDoubleValue()))
retval = false; retval = false;
break; break;
case STRING: case props::STRING:
if (!out->setStringValue(in->getStringValue())) if (!out->setStringValue(in->getStringValue()))
retval = false; retval = false;
break; break;
case UNSPECIFIED: case props::UNSPECIFIED:
if (!out->setUnspecifiedValue(in->getStringValue())) if (!out->setUnspecifiedValue(in->getStringValue()))
retval = false; retval = false;
break; break;
case VEC3D: case props::VEC3D:
if (!out->setValue(in->getValue<SGVec3d>())) if (!out->setValue(in->getValue<SGVec3d>()))
retval = false; retval = false;
break; break;
case VEC4D: case props::VEC4D:
if (!out->setValue(in->getValue<SGVec4d>())) if (!out->setValue(in->getValue<SGVec4d>()))
retval = false; retval = false;
break; break;
+4 -5
View File
@@ -704,7 +704,6 @@ struct UniformBuilder :public PassAttributeBuilder
void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
const osgDB::ReaderWriter::Options* options) const osgDB::ReaderWriter::Options* options)
{ {
using namespace simgear::props;
const SGPropertyNode* nameProp = prop->getChild("name"); const SGPropertyNode* nameProp = prop->getChild("name");
const SGPropertyNode* typeProp = prop->getChild("type"); const SGPropertyNode* typeProp = prop->getChild("type");
const SGPropertyNode* valProp const SGPropertyNode* valProp
@@ -725,13 +724,13 @@ struct UniformBuilder :public PassAttributeBuilder
if (!typeProp) { if (!typeProp) {
props::Type propType = valProp->getType(); props::Type propType = valProp->getType();
switch (propType) { switch (propType) {
case FLOAT: case props::FLOAT:
case DOUBLE: case props::DOUBLE:
break; // default float type; break; // default float type;
case VEC3D: case props::VEC3D:
uniformType = Uniform::FLOAT_VEC3; uniformType = Uniform::FLOAT_VEC3;
break; break;
case VEC4D: case props::VEC4D:
uniformType = Uniform::FLOAT_VEC4; uniformType = Uniform::FLOAT_VEC4;
break; break;
default: default: