From: Tim Moore Date: Fri, 17 Jul 2009 09:40:36 +0000 (+0200) Subject: Changed SGRawValue::DefaultValue to an inline function. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d3f5bc6e2d6e3ececf3ca43464b2fc2771428231;p=simgear.git Changed SGRawValue::DefaultValue to an inline function. This avoids MSVC bugs in declaring templated specializations of static members. --- diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index 9191d4fb..78a0c06f 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -70,19 +70,7 @@ public: #define TEST_READ(dflt) if (!getAttribute(READ)) return dflt #define TEST_WRITE if (!getAttribute(WRITE)) return false -//////////////////////////////////////////////////////////////////////// -// Default values for every type. -//////////////////////////////////////////////////////////////////////// -template<> const bool SGRawValue::DefaultValue = false; -template<> const int SGRawValue::DefaultValue = 0; -template<> const long SGRawValue::DefaultValue = 0L; -template<> const float SGRawValue::DefaultValue = 0.0; -template<> const double SGRawValue::DefaultValue = 0.0L; -template<> const char * const SGRawValue::DefaultValue = ""; -template<> const SGVec3d SGRawValue::DefaultValue = SGVec3d(); -template<> const SGVec4d SGRawValue::DefaultValue = SGVec4d(); - //////////////////////////////////////////////////////////////////////// // Local path normalization code. //////////////////////////////////////////////////////////////////////// @@ -507,19 +495,19 @@ SGPropertyNode::clearValue () } else if (_type != NONE) { switch (_type) { case BOOL: - _local_val.bool_val = SGRawValue::DefaultValue; + _local_val.bool_val = SGRawValue::DefaultValue(); break; case INT: - _local_val.int_val = SGRawValue::DefaultValue; + _local_val.int_val = SGRawValue::DefaultValue(); break; case LONG: - _local_val.long_val = SGRawValue::DefaultValue; + _local_val.long_val = SGRawValue::DefaultValue(); break; case FLOAT: - _local_val.float_val = SGRawValue::DefaultValue; + _local_val.float_val = SGRawValue::DefaultValue(); break; case DOUBLE: - _local_val.double_val = SGRawValue::DefaultValue; + _local_val.double_val = SGRawValue::DefaultValue(); break; case STRING: case UNSPECIFIED: @@ -1042,7 +1030,7 @@ SGPropertyNode::getBoolValue () const if (getAttribute(TRACE_READ)) trace_read(); if (!getAttribute(READ)) - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); switch (_type) { case ALIAS: return _value.alias->getBoolValue(); @@ -1061,7 +1049,7 @@ SGPropertyNode::getBoolValue () const return (compare_strings(get_string(), "true") || getDoubleValue() != 0.0L); case NONE: default: - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); } } @@ -1075,7 +1063,7 @@ SGPropertyNode::getIntValue () const if (getAttribute(TRACE_READ)) trace_read(); if (!getAttribute(READ)) - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); switch (_type) { case ALIAS: return _value.alias->getIntValue(); @@ -1094,7 +1082,7 @@ SGPropertyNode::getIntValue () const return atoi(get_string()); case NONE: default: - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); } } @@ -1108,7 +1096,7 @@ SGPropertyNode::getLongValue () const if (getAttribute(TRACE_READ)) trace_read(); if (!getAttribute(READ)) - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); switch (_type) { case ALIAS: return _value.alias->getLongValue(); @@ -1127,7 +1115,7 @@ SGPropertyNode::getLongValue () const return strtol(get_string(), 0, 0); case NONE: default: - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); } } @@ -1141,7 +1129,7 @@ SGPropertyNode::getFloatValue () const if (getAttribute(TRACE_READ)) trace_read(); if (!getAttribute(READ)) - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); switch (_type) { case ALIAS: return _value.alias->getFloatValue(); @@ -1160,7 +1148,7 @@ SGPropertyNode::getFloatValue () const return atof(get_string()); case NONE: default: - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); } } @@ -1174,7 +1162,7 @@ SGPropertyNode::getDoubleValue () const if (getAttribute(TRACE_READ)) trace_read(); if (!getAttribute(READ)) - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); switch (_type) { case ALIAS: @@ -1194,7 +1182,7 @@ SGPropertyNode::getDoubleValue () const return strtod(get_string(), 0); case NONE: default: - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); } } @@ -1208,7 +1196,7 @@ SGPropertyNode::getStringValue () const if (getAttribute(TRACE_READ)) trace_read(); if (!getAttribute(READ)) - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); return make_string(); } diff --git a/simgear/props/props.hxx b/simgear/props/props.hxx index dc7a5878..b5bf8a2d 100644 --- a/simgear/props/props.hxx +++ b/simgear/props/props.hxx @@ -312,7 +312,10 @@ public: * may need different kinds of default values (such as epoch for a * date type). The default value is used when creating new values. */ - static const T DefaultValue; // Default for this kind of raw value. + static T DefaultValue() + { + return T(); + } /** @@ -368,14 +371,15 @@ public: // Default values for every type. //////////////////////////////////////////////////////////////////////// -template<> const bool SGRawValue::DefaultValue; -template<> const int SGRawValue::DefaultValue; -template<> const long SGRawValue::DefaultValue; -template<> const float SGRawValue::DefaultValue; -template<> const double SGRawValue::DefaultValue; -template<> const char * const SGRawValue::DefaultValue; -template<> const SGVec3d SGRawValue::DefaultValue; -template<> const SGVec4d SGRawValue::DefaultValue; +template<> inline bool SGRawValue::DefaultValue() +{ + return false; +} + +template<> inline const char * SGRawValue::DefaultValue() +{ + return ""; +} /** * A raw value bound to a pointer. @@ -486,7 +490,7 @@ public: */ virtual T getValue () const { if (_getter) return (*_getter)(); - else return SGRawValue::DefaultValue; + else return SGRawValue::DefaultValue(); } /** @@ -535,7 +539,7 @@ public: virtual ~SGRawValueFunctionsIndexed () {} virtual T getValue () const { if (_getter) return (*_getter)(_index); - else return SGRawValue::DefaultValue; + else return SGRawValue::DefaultValue(); } virtual bool setValue (T value) { if (_setter) { (*_setter)(_index, value); return true; } @@ -568,7 +572,7 @@ public: virtual ~SGRawValueMethods () {} virtual T getValue () const { if (_getter) { return (_obj.*_getter)(); } - else { return SGRawValue::DefaultValue; } + else { return SGRawValue::DefaultValue(); } } virtual bool setValue (T value) { if (_setter) { (_obj.*_setter)(value); return true; } @@ -602,7 +606,7 @@ public: virtual ~SGRawValueMethodsIndexed () {} virtual T getValue () const { if (_getter) { return (_obj.*_getter)(_index); } - else { return SGRawValue::DefaultValue; } + else { return SGRawValue::DefaultValue(); } } virtual bool setValue (T value) { if (_setter) { (_obj.*_setter)(_index, value); return true; } @@ -1816,7 +1820,7 @@ bool SGPropertyNode::tie(const SGRawValue &rawValue, bool useDefault) return false; useDefault = useDefault && hasValue(); - T old_val = SGRawValue::DefaultValue; + T old_val = SGRawValue::DefaultValue(); if (useDefault) old_val = getValue(this); clearValue(); @@ -1847,7 +1851,7 @@ T SGPropertyNode::getValue(typename boost::disable_if_c::DefaultValue; + return SGRawValue::DefaultValue(); switch (_type) { case EXTENDED: if (_value.val->getType() == PropertyTraits::type_tag) @@ -1858,7 +1862,7 @@ T SGPropertyNode::getValue(typename boost::disable_if_c(make_string()); break; } - return SGRawValue::DefaultValue; + return SGRawValue::DefaultValue(); } template