diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index 1ac4d5e6..5c9cf8bf 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -737,7 +737,7 @@ namespace canvas return true; // Parent values do not override if element has own value - return isStyleEmpty( _node->getChild(child->getName()) ); + return isStyleEmpty( _node->getChild(child->getNameString()) ); } //---------------------------------------------------------------------------- diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index 5bd700b1..b3920448 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -414,7 +414,7 @@ namespace canvas void (Derived::*setter)(const std::string&), bool inheritable = true ) { - return addStyle + return addStyle ( name, type, @@ -507,7 +507,7 @@ namespace canvas OtherRef Derived::*instance_ref, bool inheritable = true ) { - return addStyle + return addStyle ( name, type, diff --git a/simgear/canvas/elements/CanvasGroup.cxx b/simgear/canvas/elements/CanvasGroup.cxx index 6755f6d5..202fe88d 100644 --- a/simgear/canvas/elements/CanvasGroup.cxx +++ b/simgear/canvas/elements/CanvasGroup.cxx @@ -120,7 +120,7 @@ namespace canvas SG_GENERAL, SG_WARN, "Group::getOrCreateChild: type missmatch! " - "('" << type << "' != '" << child->getProps()->getName() << "', " + "('" << type << "' != '" << child->getProps()->getNameString() << "', " "id = '" << id << "')" ); diff --git a/simgear/canvas/elements/CanvasMap.cxx b/simgear/canvas/elements/CanvasMap.cxx index ca97c4f7..3387e3b0 100644 --- a/simgear/canvas/elements/CanvasMap.cxx +++ b/simgear/canvas/elements/CanvasMap.cxx @@ -142,7 +142,7 @@ namespace canvas if( strutils::ends_with(child->getNameString(), GEO) ) // TODO remove from other node _geo_nodes.erase(child); - else if( parent != _node && child->getName() == HDG ) + else if( parent != _node && child->getNameString() == HDG ) { _hdg_nodes.erase(child); diff --git a/simgear/canvas/elements/CanvasText.cxx b/simgear/canvas/elements/CanvasText.cxx index bdea9d7a..b628c3d6 100644 --- a/simgear/canvas/elements/CanvasText.cxx +++ b/simgear/canvas/elements/CanvasText.cxx @@ -783,21 +783,20 @@ namespace canvas } //---------------------------------------------------------------------------- - void Text::setText(const char* text) + void Text::setText(const std::string &text) { _text->setText(text, osgText::String::ENCODING_UTF8); } //---------------------------------------------------------------------------- - void Text::setFont(const char* name) + void Text::setFont(const std::string& name) { _text->setFont( Canvas::getSystemAdapter()->getFont(name) ); } //---------------------------------------------------------------------------- - void Text::setAlignment(const char* align) + void Text::setAlignment(const std::string& align_string) { - const std::string align_string(align); if( 0 ) return; #define ENUM_MAPPING(enum_val, string_val) \ else if( align_string == string_val )\ diff --git a/simgear/canvas/elements/CanvasText.hxx b/simgear/canvas/elements/CanvasText.hxx index 9abb5105..2400e07b 100644 --- a/simgear/canvas/elements/CanvasText.hxx +++ b/simgear/canvas/elements/CanvasText.hxx @@ -44,9 +44,9 @@ namespace canvas ElementWeakPtr parent = 0 ); ~Text(); - void setText(const char* text); - void setFont(const char* name); - void setAlignment(const char* align); + void setText(const std::string& text); + void setFont(const std::string& name); + void setAlignment(const std::string& align_string); int heightForWidth(int w) const; int maxWidth() const; diff --git a/simgear/canvas/elements/map/geo_node_pair.hxx b/simgear/canvas/elements/map/geo_node_pair.hxx index aa01aa91..b9335e8f 100644 --- a/simgear/canvas/elements/map/geo_node_pair.hxx +++ b/simgear/canvas/elements/map/geo_node_pair.hxx @@ -89,12 +89,12 @@ namespace canvas } } - const char* getLat() const + std::string getLat() const { return _node_lat ? _node_lat->getStringValue() : ""; } - const char* getLon() const + std::string getLon() const { return _node_lon ? _node_lon->getStringValue() : ""; } diff --git a/simgear/package/Catalog.cxx b/simgear/package/Catalog.cxx index 2b57c11e..f13a93f4 100644 --- a/simgear/package/Catalog.cxx +++ b/simgear/package/Catalog.cxx @@ -385,7 +385,7 @@ void Catalog::parseProps(const SGPropertyNode* aProps) int nChildren = aProps->nChildren(); for (int i = 0; i < nChildren; i++) { const SGPropertyNode* pkgProps = aProps->getChild(i); - if (strcmp(pkgProps->getName(), "package") == 0) { + if (pkgProps->getNameString() == "package") { // can't use getPackageById here becuase the variant dict isn't // built yet. Instead we need to look at m_packages directly. @@ -408,7 +408,7 @@ void Catalog::parseProps(const SGPropertyNode* aProps) m_variantDict[*it] = p.ptr(); } } else { - SGPropertyNode* c = m_props->getChild(pkgProps->getName(), pkgProps->getIndex(), true); + SGPropertyNode* c = m_props->getChild(pkgProps->getNameString().c_str(), pkgProps->getIndex(), true); copyProperties(pkgProps, c); } } // of children iteration @@ -633,17 +633,9 @@ void Catalog::setUserEnabled(bool b) void Catalog::processAlternate(SGPropertyNode_ptr alt) { m_refreshRequest.reset(); + std::string altId = alt->getStringValue("id"); - std::string altId; - const auto idPtr = alt->getStringValue("id"); - if (idPtr) { - altId = std::string(idPtr); - } - - std::string altUrl; - if (alt->getStringValue("url")) { - altUrl = std::string(alt->getStringValue("url")); - } + std::string altUrl = alt->getStringValue("url"); CatalogRef existing; if (!altId.empty()) { diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index 56ef96cf..33d7a363 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -121,7 +121,7 @@ bool Package::matches(const SGPropertyNode* aFilter) const if (strutils::starts_with(filter_name, "rating-")) { int minRating = aFilter->getIntValue(); - std::string rname = aFilter->getName() + 7; + std::string rname = aFilter->getNameString().c_str() + 7; int ourRating = m_props->getChild("rating")->getIntValue(rname, 0); return (ourRating >= minRating); } diff --git a/simgear/props/PropertyBasedElement.cxx b/simgear/props/PropertyBasedElement.cxx index 621a1b91..8dba69e0 100644 --- a/simgear/props/PropertyBasedElement.cxx +++ b/simgear/props/PropertyBasedElement.cxx @@ -53,7 +53,7 @@ namespace simgear // TODO check if really not in use anymore if( _node->getParent() ) _node->getParent() - ->removeChild(_node->getName(), _node->getIndex()); + ->removeChild(_node->getNameString(), _node->getIndex()); } //---------------------------------------------------------------------------- diff --git a/simgear/props/condition.cxx b/simgear/props/condition.cxx index 5e561144..930ae19c 100644 --- a/simgear/props/condition.cxx +++ b/simgear/props/condition.cxx @@ -482,7 +482,7 @@ static SGCondition * readPropertyCondition( SGPropertyNode *prop_root, const SGPropertyNode *node ) { - return new SGPropertyCondition( prop_root, node->getStringValue() ); + return new SGPropertyCondition( prop_root, node->getStringValue().c_str() ); } static SGCondition * @@ -545,9 +545,9 @@ readComparison( SGPropertyNode *prop_root, *right = node->getChild(1); { - string leftName(left->getName()); + string leftName(left->getNameString()); if (leftName == "property") { - condition->setLeftProperty(prop_root, left->getStringValue()); + condition->setLeftProperty(prop_root, left->getStringValue().c_str()); } else if (leftName == "value") { condition->setLeftValue(left); } else if (leftName == "expression") { @@ -560,9 +560,9 @@ readComparison( SGPropertyNode *prop_root, } { - string rightName(right->getName()); + string rightName(right->getNameString()); if (rightName == "property") { - condition->setRightProperty(prop_root, right->getStringValue()); + condition->setRightProperty(prop_root, right->getStringValue().c_str()); } else if (rightName == "value") { condition->setRightValue(right); } else if (rightName == "expression") { @@ -576,9 +576,9 @@ readComparison( SGPropertyNode *prop_root, if( node->nChildren() == 3 ) { const SGPropertyNode *n = node->getChild(2); - string name(n->getName()); + string name(n->getNameString()); if (name == "precision-property") { - condition->setPrecisionProperty(prop_root, n->getStringValue()); + condition->setPrecisionProperty(prop_root, n->getStringValue().c_str()); } else if (name == "precision-value") { condition->setPrecisionValue(n); } else if (name == "precision-expression") { @@ -596,7 +596,7 @@ readComparison( SGPropertyNode *prop_root, static SGCondition * readCondition( SGPropertyNode *prop_root, const SGPropertyNode *node ) { - const string &name = node->getName(); + const string &name = node->getNameString(); if (name == "property") return readPropertyCondition(prop_root, node); else if (name == "not") diff --git a/simgear/props/propertyObject_test.cxx b/simgear/props/propertyObject_test.cxx index 7a2d814b..95fff921 100644 --- a/simgear/props/propertyObject_test.cxx +++ b/simgear/props/propertyObject_test.cxx @@ -80,7 +80,7 @@ void testString() assert(sp == "aaaa"); // read sp = "xxxx"; // assignment from char* literal - assert(!strcmp(testRoot->getStringValue("a/alice"), "xxxx")); + assert(testRoot->getStringValue("a/alice") == "xxxx"); std::string d = "yyyy"; sp = d; // assignment from std::string @@ -200,7 +200,7 @@ void testCreate() // check overloads for string version SGPropertyNode* n = testRoot->getNode("b", true); PropertyObject d(PropertyObject::create(n, "grape", "xyz")); - assert(!strcmp(testRoot->getStringValue("b/grape"), "xyz")); + assert(testRoot->getStringValue("b/grape") == "xyz"); } diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index a1a00634..517b08fe 100755 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -810,7 +810,7 @@ find_child(SGPropertyLock& lock, Itr begin, Itr end, int index, const PropertyLi #if PROPS_STANDALONE for (int i = 0; i < nNodes; i++) { SGPropertyNode * node = nodes[i]; - if (node->getIndex() == index && strings_equal(node->getName(), begin)) + if (node->getIndex() == index && strings_equal(node->getNameString(), begin)) return i; } #else @@ -820,7 +820,7 @@ find_child(SGPropertyLock& lock, Itr begin, Itr end, int index, const PropertyLi // searching for a matching index is a lot less time consuming than // comparing two strings so do that first. - if (node->getIndex() == index && boost::equals(node->getName(), name)) + if (node->getIndex() == index && boost::equals(node->getNameString(), name)) return static_cast(i); } #endif @@ -838,7 +838,7 @@ find_last_child (SGPropertyLockExclusive& exclusive, const char * name, const Pr for (size_t i = 0; i < nNodes; i++) { SGPropertyNode * node = nodes[i]; - if (strings_equal(node->getName(), name)) + if (node->getNameString() == string(name)) { int idx = node->getIndex(); if (idx > index) index = idx; @@ -1161,7 +1161,7 @@ struct SGPropertyNodeImpl } /* Get the value as a string. */ - static const char * + static std::string make_string(SGPropertyLock& lock, const SGPropertyNode& node) { if (!getAttribute(lock, node, SGPropertyNode::READ)) @@ -1171,7 +1171,7 @@ struct SGPropertyNodeImpl { SGPropertyNode* p = node._value.alias; lock.release(); - const char* ret = p->getStringValue(); + std::string ret = p->getStringValue(); lock.acquire(); return ret; } @@ -1211,8 +1211,7 @@ struct SGPropertyNodeImpl default: return ""; } - node._buffer = sstr.str(); - return node._buffer.c_str(); + return sstr.str(); } /** @@ -1221,7 +1220,7 @@ struct SGPropertyNodeImpl static void trace_write (SGPropertyLockExclusive& exclusive, const SGPropertyNode& node) { - const char* value = SGPropertyNodeImpl::make_string(exclusive, node); + std::string value = SGPropertyNodeImpl::make_string(exclusive, node); bool own = exclusive.m_own; if (own) exclusive.release(); { @@ -1248,7 +1247,7 @@ struct SGPropertyNodeImpl // // Hopefully we are only called for specific debugging purposes. // - const char* value = SGPropertyNodeImpl::make_string(lock, node); + std::string value = SGPropertyNodeImpl::make_string(lock, node); lock.release(); SG_LOG(SG_GENERAL, SG_ALERT, "TRACE: Read node " << node.getPath() << ", value \"" << value << '"'); @@ -1343,18 +1342,18 @@ struct SGPropertyNodeImpl node._type = props::NONE; } - static const char * + static std::string getStringValue(SGPropertyLock& lock, const SGPropertyNode& node) { // This is inherantly unsafe. // Shortcut for common case if (node._attr == (SGPropertyNode::READ|SGPropertyNode::WRITE) && node._type == props::STRING) - return get_string(lock, node); + return std::string(get_string(lock, node)); if (getAttribute(lock, node, SGPropertyNode::TRACE_READ)) trace_read(lock, node); if (!getAttribute(lock, node, SGPropertyNode::READ)) - return SGRawValue::DefaultValue(); + return std::string(SGRawValue::DefaultValue()); return make_string(lock, node); } @@ -1972,25 +1971,18 @@ struct SGPropertyNodeImpl } static PropertyList - getChildren(SGPropertyLock& lock, const SGPropertyNode& node, const char* name) + getChildren(SGPropertyLock& lock, const SGPropertyNode& node, const std::string& name) { PropertyList children; size_t max = node._children.size(); for (size_t i = 0; i < max; i++) - if (strings_equal(node._children[i]->getName(), name)) + if (node._children[i]->getNameString() == name) children.push_back(node._children[i]); sort(children.begin(), children.end(), CompareIndices()); return children; } - - static simgear::PropertyList - getChildren(SGPropertyLock& lock, const SGPropertyNode& node, const std::string& name) - { - return getChildren(lock, node, name.c_str()); - } - }; @@ -2017,7 +2009,7 @@ find_node_aux(SGPropertyNode * current, SplitItr& itr, bool create, int last_ind if (equals(name, "..")) { SGPropertyNode* parent = current->getParent(); if (!parent) { - SG_LOG(SG_GENERAL, SG_ALERT, "attempt to move past root with '..' node " << current->getName()); + SG_LOG(SG_GENERAL, SG_ALERT, "attempt to move past root with '..' node " << current->getNameString()); return nullptr; } return find_node_aux(parent, ++itr, create, last_index); @@ -2521,13 +2513,6 @@ bool SGPropertyNode::hasValue() const return SGPropertyNodeImpl::hasValue(shared, *this); } - -const char * SGPropertyNode::getName () const -{ - SGPropertyLockShared shared(*this); - return _name.c_str(); -} - const std::string& SGPropertyNode::getNameString () const { SGPropertyLockShared shared(*this); @@ -2744,14 +2729,14 @@ SGPropertyNode_ptr SGPropertyNode::removeChild(const std::string& name, int inde * Remove all children with the specified name. */ PropertyList -SGPropertyNode::removeChildren(const char * name) +SGPropertyNode::removeChildren(const std::string& name) { PropertyList children; { SGPropertyLockShared shared(*this); for (int pos = static_cast(_children.size() - 1); pos >= 0; pos--) { - if (strings_equal(_children[pos]->getName(), name)) { + if (_children[pos]->getNameString() == name) { children.push_back(_children[pos]); } } @@ -2764,11 +2749,6 @@ SGPropertyNode::removeChildren(const char * name) return children; } -simgear::PropertyList SGPropertyNode::removeChildren(const std::string& name) -{ - return removeChildren(name.c_str()); -} - void SGPropertyNode::removeAllChildren() { @@ -2891,7 +2871,7 @@ SGPropertyNode::getDoubleValue() const } -const char * +std::string SGPropertyNode::getStringValue() const { SGPropertyLockShared shared(*this); @@ -2899,7 +2879,7 @@ SGPropertyNode::getStringValue() const } bool -SGPropertyNode::setUnspecifiedValue (const char * value) +SGPropertyNode::setUnspecifiedValue (const std::string &value) { SGPropertyLockExclusive exclusive(*this); bool result = false; @@ -2921,24 +2901,24 @@ SGPropertyNode::setUnspecifiedValue (const char * value) break; } case props::BOOL: - result = SGPropertyNodeImpl::set_bool(exclusive, *this, (strings_equal(value, "true") - || atoi(value)) ? true : false); + result = SGPropertyNodeImpl::set_bool(exclusive, *this, value == "true" + || atoi(value.c_str()) ? true : false); break; case props::INT: - result = SGPropertyNodeImpl::set_int(exclusive, *this, atoi(value)); + result = SGPropertyNodeImpl::set_int(exclusive, *this, atoi(value.c_str())); break; case props::LONG: - result = SGPropertyNodeImpl::set_long(exclusive, *this, strtol(value, 0, 0)); + result = SGPropertyNodeImpl::set_long(exclusive, *this, strtol(value.c_str(), 0, 0)); break; case props::FLOAT: - result = SGPropertyNodeImpl::set_float(exclusive, *this, atof(value)); + result = SGPropertyNodeImpl::set_float(exclusive, *this, atof(value.c_str())); break; case props::DOUBLE: - result = SGPropertyNodeImpl::set_double(exclusive, *this, strtod(value, 0)); + result = SGPropertyNodeImpl::set_double(exclusive, *this, strtod(value.c_str(), 0)); break; case props::STRING: case props::UNSPECIFIED: - result = SGPropertyNodeImpl::set_string(exclusive, *this, value); + result = SGPropertyNodeImpl::set_string(exclusive, *this, value.c_str()); break; #if !PROPS_STANDALONE case props::VEC3D: @@ -3431,16 +3411,18 @@ double SGPropertyNode::getDoubleValue (const std::string& relative_path, double /** * Get a string value for another node. */ -const char * +std::string SGPropertyNode::getStringValue (const char * relative_path, const char * defaultValue) const { + // TODO Check defaultValue != null const SGPropertyNode * node = getNode(relative_path); return (node) ? node->getStringValue() : defaultValue; } -const char * SGPropertyNode::getStringValue (const std::string& relative_path, const char * defaultValue) const +std::string SGPropertyNode::getStringValue (const std::string& relative_path, const char * defaultValue) const { + // TODO Check defaultValue != null return getStringValue(relative_path.c_str(), defaultValue); } @@ -3994,7 +3976,7 @@ namespace simgear return lhs.getValue() == rhs.getValue(); case props::STRING: case props::UNSPECIFIED: - return !strcmp(lhs.getStringValue(), rhs.getStringValue()); + return lhs.getStringValue() == rhs.getStringValue(); #if !PROPS_STANDALONE case props::VEC3D: return lhs.getValue() == rhs.getValue(); @@ -4040,21 +4022,21 @@ void SGPropertyNode::copy(SGPropertyNode *to) const for (int i = 0; i < nChildren(); i++) { const SGPropertyNode *child = getChild(i); if (!child) break; // We don't lock child, so getChild() could return 0; - SGPropertyNode* to_child = to->getChild(child->getName()); + SGPropertyNode* to_child = to->getChild(child->getNameString()); if (!to_child) - to_child = to->addChild(child->getName()); + to_child = to->addChild(child->getNameString()); if (child->nChildren()) { child->copy(to_child); } else { - to_child->setValue(child->getStringValue()); + to_child->setValue(child->getStringValue().c_str()); } } } else - to->setValue(getStringValue()); + to->setValue(getStringValue().c_str()); } SGPropertyNode * SGPropertyNode::getNode (const std::string& relative_path, bool create) @@ -4333,7 +4315,6 @@ template int SGPropertyNode::getValue(void*) const; template long SGPropertyNode::getValue(void*) const; template float SGPropertyNode::getValue(void*) const; template double SGPropertyNode::getValue(void*) const; -template const char* SGPropertyNode::getValue(void*) const; template SGVec3 SGPropertyNode::getValue>(void*) const; template SGVec4 SGPropertyNode::getValue>(void*) const; @@ -4367,12 +4348,6 @@ double SGPropertyNode::getValue(SGPropertyLock& lock, void* dummy) const return SGPropertyNodeImpl::getDoubleValue(lock, *this); } -template<> -const char* SGPropertyNode::getValue(SGPropertyLock& lock, void* dummy) const -{ - return SGPropertyNodeImpl::getStringValue(lock, *this); -} - template bool SGPropertyNode::setValue(const bool&, void*); template bool SGPropertyNode::setValue(const int&, void*); template bool SGPropertyNode::setValue(const long&, void*); @@ -4417,8 +4392,8 @@ size_t hash_value(const SGPropertyNode& node) case props::STRING: case props::UNSPECIFIED: { - const char *val = SGPropertyNodeImpl::getStringValue(shared, node); - return boost::hash_range(val, val + strlen(val)); + std::string val = SGPropertyNodeImpl::getStringValue(shared, node); + return boost::hash_range(val.begin(), val.end()); } case props::VEC3D: { diff --git a/simgear/props/props.hxx b/simgear/props/props.hxx index 66829649..6290a7c2 100644 --- a/simgear/props/props.hxx +++ b/simgear/props/props.hxx @@ -915,9 +915,6 @@ public: /** Test whether this node contains a primitive leaf value. */ bool hasValue() const; - /** Get the node's simple (XML) name. Return value is not thread-safe. */ - const char* getName() const; - /** Get the node's simple name as a string. Return value is not thread-safe. */ const std::string& getNameString() const; @@ -997,7 +994,6 @@ public: SGPropertyNode_ptr removeChild(const std::string& name, int index = 0); /** Remove all children with the specified name. */ - simgear::PropertyList removeChildren(const char* name); simgear::PropertyList removeChildren(const std::string& name); /** Remove all children (does not change the value of the node) */ @@ -1084,7 +1080,7 @@ public: long getLongValue() const; float getFloatValue() const; double getDoubleValue() const; - const char* getStringValue() const; + std::string getStringValue() const; /** Set value of this node. */ bool setBoolValue(bool value); @@ -1096,7 +1092,7 @@ public: bool setStringValue(const std::string& value); /** Set a value of unspecified type for this node. */ - bool setUnspecifiedValue(const char* value); + bool setUnspecifiedValue(const std::string &value); // // Template methods for get/set value. @@ -1236,14 +1232,14 @@ public: long getLongValue(const char* relative_path, long defaultValue = 0L) const; float getFloatValue(const char* relative_path, float defaultValue = 0.0f) const; double getDoubleValue(const char* relative_path, double defaultValue = 0.0) const; - const char* getStringValue(const char* relative_path, const char* defaultValue = "") const; + std::string getStringValue(const char* relative_path, const char* defaultValue = "") const; bool getBoolValue(const std::string& relative_path, bool defaultValue = false) const; int getIntValue(const std::string& relative_path, int defaultValue = 0) const; long getLongValue(const std::string& relative_path, long defaultValue = 0L) const; float getFloatValue(const std::string& relative_path, float defaultValue = 0.0f) const; double getDoubleValue(const std::string& relative_path, double defaultValue = 0.0) const; - const char* getStringValue(const std::string& relative_path, const char* defaultValue = "") const; + std::string getStringValue(const std::string& relative_path, const char* defaultValue = "") const; /** Set another node's value. */ bool setBoolValue(const char* relative_path, bool value); @@ -1465,12 +1461,6 @@ inline double getValue(const SGPropertyNode* node) return node->getDoubleValue(); } -template<> -inline const char* getValue(const SGPropertyNode* node) -{ - return node->getStringValue(); -} - template<> inline std::string getValue(const SGPropertyNode* node) { diff --git a/simgear/props/props_io.cxx b/simgear/props/props_io.cxx index 1fae00df..e9da458e 100644 --- a/simgear/props/props_io.cxx +++ b/simgear/props/props_io.cxx @@ -377,13 +377,13 @@ PropsVisitor::endElement (const char * name) int nChildren = st.node->nChildren(); for (int i = 0; i < nChildren; i++) { SGPropertyNode *src = st.node->getChild(i); - const char *name = src->getName(); + string name = src->getNameString(); int index = parent.counters[name]; parent.counters[name]++; SGPropertyNode *dst = parent.node->getChild(name, index, true); copyProperties(src, dst); } - parent.node->removeChild(st.node->getName(), st.node->getIndex()); + parent.node->removeChild(st.node->getNameString(), st.node->getIndex()); } pop_state(); } @@ -555,7 +555,7 @@ writeAtts( std::ostream &output, if( attr ) for(int i = 0; i < attr->nChildren(); ++i) { - output << ' ' << attr->getChild(i)->getName() << "=\""; + output << ' ' << attr->getChild(i)->getNameString() << "=\""; const std::string data = attr->getChild(i)->getStringValue(); for(int j = 0; j < (int)data.size(); ++j) @@ -623,7 +623,7 @@ writeNode( std::ostream &output, if (!write_all && !isArchivable(node, archive_flag)) return true; // Everything's OK, but we won't write. - const string name = node->getName(); + const string name = node->getNameString(); int nChildren = node->nChildren(); const SGPropertyNode* attr_node = node->getChild(ATTR, 0); bool attr_written = false, diff --git a/simgear/props/props_test.cxx b/simgear/props/props_test.cxx index 5d90aee0..dcb3b7b4 100644 --- a/simgear/props/props_test.cxx +++ b/simgear/props/props_test.cxx @@ -341,7 +341,7 @@ test_property_nodes () std::vector bar = child->getChildren("bar"); cout << "There are " << bar.size() << " matches" << endl; for (int i = 0; i < (int)bar.size(); i++) - cout << bar[i]->getName() << '[' << bar[i]->getIndex() << ']' << endl; + cout << bar[i]->getNameString() << '[' << bar[i]->getIndex() << ']' << endl; cout << endl; cout << "Testing addition of a totally empty node" << endl; diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index 47af7ed2..afd72280 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -134,7 +134,7 @@ ref_ptr UniformFactoryImpl::getUniform( Effect * effect, val = getGlobalProperty(prop, options); } } else { - SG_LOG(SG_GL,SG_DEBUG,"Invalid parameter " << valProp->getName() << " for uniform " << name << " in Effect "); + SG_LOG(SG_GL,SG_DEBUG,"Invalid parameter " << valProp->getNameString() << " for uniform " << name << " in Effect "); } } @@ -312,7 +312,7 @@ void buildPass(Effect* effect, Technique* tniq, const SGPropertyNode* prop, builder->buildAttribute(effect, pass, attrProp, options); else SG_LOG(SG_INPUT, SG_ALERT, - "skipping unknown pass attribute " << attrProp->getName()); + "skipping unknown pass attribute " << attrProp->getNameString()); } } @@ -325,7 +325,7 @@ osg::Vec4f getColor(const SGPropertyNode* prop) return osg::Vec4f(toOsg(prop->getValue()), 1.0f); } else { SG_LOG(SG_INPUT, SG_ALERT, - "invalid color property " << prop->getName() << " " + "invalid color property " << prop->getNameString() << " " << prop->getStringValue()); return osg::Vec4f(0.0f, 0.0f, 0.0f, 1.0f); } diff --git a/simgear/scene/material/EffectBuilder.hxx b/simgear/scene/material/EffectBuilder.hxx index 6420fa25..36c2c4ce 100644 --- a/simgear/scene/material/EffectBuilder.hxx +++ b/simgear/scene/material/EffectBuilder.hxx @@ -218,9 +218,7 @@ void findAttr(const effect::EffectPropertyMap& pMap, { if (!prop) throw effect::BuilderException("findAttr: empty property"); - const char* name = prop->getStringValue(); - if (!name) - throw effect::BuilderException("findAttr: no name for lookup"); + std::string name = prop->getStringValue(); findAttr(pMap, name, result); } diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index 5016a14d..5ae4d48b 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -1124,7 +1124,7 @@ TexGen* buildTexGen(Effect* effect, const SGPropertyNode* tgenProp) for (int i = 0; i < planesNode->nChildren(); ++i) { const SGPropertyNode* planeNode = planesNode->getChild(i); TexGen::Coord coord; - findAttr(tgenCoords, planeNode->getName(), coord); + findAttr(tgenCoords, planeNode->getNameString(), coord); const SGPropertyNode* realNode = getEffectPropertyNode(effect, planeNode); SGVec4d plane = realNode->getValue(); diff --git a/simgear/scene/material/makeEffect.cxx b/simgear/scene/material/makeEffect.cxx index 8fcd1ba7..2c67f93e 100644 --- a/simgear/scene/material/makeEffect.cxx +++ b/simgear/scene/material/makeEffect.cxx @@ -77,12 +77,12 @@ void mergePropertyTrees(SGPropertyNode* resultNode, const SGPropertyNode* node = right->getChild(i); auto litr = find_if(leftChildren.begin(), leftChildren.end(), [node](const SGPropertyNode* arg) { - if (strcmp(node->getName(), arg->getName())) + if (node->getNameString() != arg->getNameString()) return false; return node->getIndex() == arg->getIndex(); }); SGPropertyNode* newChild - = resultNode->getChild(node->getName(), node->getIndex(), true); + = resultNode->getChild(node->getNameString(), node->getIndex(), true); if (litr != leftChildren.end()) { mergePropertyTrees(newChild, *litr, node); leftChildren.erase(litr); @@ -96,7 +96,7 @@ void mergePropertyTrees(SGPropertyNode* resultNode, itr != e; ++itr) { SGPropertyNode* newChild - = resultNode->getChild((*itr)->getName(), (*itr)->getIndex(), true); + = resultNode->getChild((*itr)->getNameString(), (*itr)->getIndex(), true); copyProperties(*itr, newChild); } } diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 99a92cfb..874770c3 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -431,9 +431,8 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, // read glyph table for taxi-/runway-signs std::vector glyph_nodes = props->getChildren("glyph"); for (unsigned int i = 0; i < glyph_nodes.size(); i++) { - const char *name = glyph_nodes[i]->getStringValue("name"); - if (name) - glyphs[name] = new SGMaterialGlyph(glyph_nodes[i]); + std::string name = glyph_nodes[i]->getStringValue("name"); + glyphs[name] = new SGMaterialGlyph(glyph_nodes[i]); } // Read parameters entry, which is passed into the effect diff --git a/simgear/scene/model/SGLight.cxx b/simgear/scene/model/SGLight.cxx index 8d5670c4..5e472fd4 100644 --- a/simgear/scene/model/SGLight.cxx +++ b/simgear/scene/model/SGLight.cxx @@ -75,7 +75,7 @@ public: void valueChanged(SGPropertyNode* node) override { - while (strcmp(node->getName(), "light") && node->getParent()) { + while (node->getNameString() != "light" && node->getParent()) { node = node->getParent(); } _light->configure(node); diff --git a/simgear/scene/model/SGReaderWriterXML.cxx b/simgear/scene/model/SGReaderWriterXML.cxx index 91d0d95f..c9297f26 100644 --- a/simgear/scene/model/SGReaderWriterXML.cxx +++ b/simgear/scene/model/SGReaderWriterXML.cxx @@ -164,14 +164,14 @@ void makeEffectAnimations(PropertyList& animation_nodes, if (!typeProp) continue; - const char* typeString = typeProp->getStringValue(); - if (!strcmp(typeString, "material")) { + std::string typeString = typeProp->getStringValue(); + if (typeString == "material") { effectProp = SGMaterialAnimation::makeEffectProperties(animProp); - } else if (!strcmp(typeString, "shader")) { + } else if (typeString == "shader") { SGPropertyNode* shaderProp = animProp->getChild("shader"); - if (!shaderProp || strcmp(shaderProp->getStringValue(), "chrome")) + if (!shaderProp || shaderProp->getStringValue() != "chrome") continue; *itr = 0; // effect replaces animation SGPropertyNode* textureProp = animProp->getChild("texture"); @@ -182,7 +182,7 @@ void makeEffectAnimations(PropertyList& animation_nodes, ->setValue("Effects/chrome"); SGPropertyNode* paramsProp = makeChild(effectProp.get(), "parameters"); makeChild(paramsProp, "chrome-texture") - ->setValue(textureProp->getStringValue()); + ->setValue(textureProp->getStringValue().c_str()); } if (effectProp.valid()) { PropertyList objectNameNodes = animProp->getChildren("object-name"); @@ -376,7 +376,7 @@ void addTooltipAnimations(const SGPath& path, SGPropertyNode_ptr props, osg::ref SGPropertyNode* animation = animations[i]; - if (!strcmp(animation->getStringValue("type"), "pick")) { + if (animation->getStringValue("type") == "pick") { /* There appear to be many of these, and we end up consuming GB's of memory if we install a tooltip for each one, so ignore. */ diff --git a/simgear/scene/model/SGText.cxx b/simgear/scene/model/SGText.cxx index 17810293..870164fa 100644 --- a/simgear/scene/model/SGText.cxx +++ b/simgear/scene/model/SGText.cxx @@ -40,7 +40,7 @@ using std::string; class SGText::UpdateCallback : public osg::NodeCallback { public: - UpdateCallback( osgText::Text * aText, SGConstPropertyNode_ptr aProperty, double aScale, double aOffset, bool aTruncate, bool aNumeric, const char * aFormat ) : + UpdateCallback( osgText::Text * aText, SGConstPropertyNode_ptr aProperty, double aScale, double aOffset, bool aTruncate, bool aNumeric, const std::string &aFormat ) : text( aText ), property( aProperty ), scale( aScale ), @@ -77,7 +77,7 @@ void SGText::UpdateCallback::operator()(osg::Node * node, osg::NodeVisitor *nv ) if (truncate) d = (d < 0) ? -floor(-d) : floor(d); snprintf( buf, sizeof(buf)-1, format.c_str(), d ); } else { - snprintf( buf, sizeof(buf)-1, format.c_str(), property->getStringValue() ); + snprintf( buf, sizeof(buf)-1, format.c_str(), property->getStringValue().c_str() ); } if( text->getText().createUTF8EncodedString().compare( buf ) ) { // be lazy and set the text only if the property has changed. @@ -219,7 +219,7 @@ osg::Node * SGText::appendText(const SGPropertyNode* configNode, text->setText( configNode->getStringValue( "text", "" ) ); } else { SGConstPropertyNode_ptr property = modelRoot->getNode( configNode->getStringValue( "property", "foo" ), true ); - const char * format = configNode->getStringValue( "format", "" ); + std::string format = configNode->getStringValue( "format", "" ); double scale = configNode->getDoubleValue( "scale", 1.0 ); double offset = configNode->getDoubleValue( "offset", 0.0 ); bool truncate = configNode->getBoolValue( "truncate", false ); diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index 24996cb8..9e1c267a 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -1043,7 +1043,7 @@ void SGTerraSync::WorkerThread::initCompletedTilesPersistentCache() { for (int i = 0; i < cacheRoot->nChildren(); ++i) { SGPropertyNode *entry = cacheRoot->getChild(i); - bool isNotFound = (strcmp(entry->getName(), "not-found") == 0); + bool isNotFound = (entry->getNameString() == "not-found"); string tileName = entry->getStringValue("path"); time_t stamp = entry->getIntValue("stamp"); SG_LOG(SG_TERRASYNC, SG_DEBUG, "tileName=" << tileName diff --git a/simgear/structure/SGExpression.cxx b/simgear/structure/SGExpression.cxx index 5765f30c..5d31ee45 100644 --- a/simgear/structure/SGExpression.cxx +++ b/simgear/structure/SGExpression.cxx @@ -1,6 +1,6 @@ /* -*-c++-*- * - * Copyright (C) 2006-2007 Mathias Froehlich + * Copyright (C) 2006-2007 Mathias Froehlich * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -70,14 +70,10 @@ const expression::Value eval(const Expression* exp, template static bool -SGReadValueFromString(const char* str, T& value) +SGReadValueFromString(const std::string& str, T& value) { - if (!str) { - SG_LOG(SG_IO, SG_ALERT, "Cannot read string content."); - return false; - } std::stringstream s; - s.str(std::string(str)); + s.str(str); s >> value; if (s.fail()) { SG_LOG(SG_IO, SG_ALERT, "Cannot read string content."); @@ -141,7 +137,7 @@ SGReadExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression) if (!expression) return 0; - std::string name = expression->getName(); + std::string name = expression->getNameString(); if (name == "value") { T value; @@ -158,10 +154,7 @@ SGReadExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression) "No inputRoot argument given!"); return 0; } - if (!expression->getStringValue()) { - SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression."); - return 0; - } + SGPropertyNode* inputNode; inputNode = inputRoot->getNode(expression->getStringValue(), true); return new SGPropertyExpression(inputNode); @@ -329,7 +322,7 @@ SGReadExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression) // find input expression - i.e a child not named 'entry' const SGPropertyNode* inputNode = NULL; for (int i=0; (inChildren()) && !inputNode; ++i) { - if (strcmp(expression->getChild(i)->getName(), "entry") == 0) { + if (expression->getChild(i)->getNameString() == "entry") { continue; } diff --git a/simgear/structure/SGExpression.hxx b/simgear/structure/SGExpression.hxx index bbe9c037..3cdc9987 100644 --- a/simgear/structure/SGExpression.hxx +++ b/simgear/structure/SGExpression.hxx @@ -1,6 +1,6 @@ /* -*-c++-*- * - * Copyright (C) 2006-2007 Mathias Froehlich + * Copyright (C) 2006-2007 Mathias Froehlich * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -1029,9 +1029,9 @@ namespace simgear Expression* read(const SGPropertyNode* exp) { ParserMap& map = getParserMap(); - ParserMap::iterator itr = map.find(exp->getName()); + ParserMap::iterator itr = map.find(exp->getNameString()); if (itr == map.end()) - throw ParseError(std::string("unknown expression ") + exp->getName()); + throw ParseError(std::string("unknown expression ") + exp->getNameString()); exp_parser parser = itr->second; return (*parser)(exp, this); }