Make SGPropertyNode::getStringValue() thread-safe.
This is by Lars Toenning <dev@ltoenning.de>, Roman Ludwicki <romek21@op.pl> and SDeAstis <salvatore.deastis@gmail.com>, in 2021 Hackathon. SGPropertyNode::getStringValue() now returns std::string by value instead of const char* pointer into SGPropertyNode's internal data. Patched up various call sites to use new API. Remove SGPropertyNode::getName() and use SGPropertyNode::getNameString() everywhere.
This commit is contained in:
committed by
Julian Smith
parent
da3507f3df
commit
dd09e5f466
@@ -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()) );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -414,7 +414,7 @@ namespace canvas
|
||||
void (Derived::*setter)(const std::string&),
|
||||
bool inheritable = true )
|
||||
{
|
||||
return addStyle<const char*, const std::string&>
|
||||
return addStyle<std::string, const std::string&>
|
||||
(
|
||||
name,
|
||||
type,
|
||||
@@ -507,7 +507,7 @@ namespace canvas
|
||||
OtherRef Derived::*instance_ref,
|
||||
bool inheritable = true )
|
||||
{
|
||||
return addStyle<const char*, const std::string&>
|
||||
return addStyle<std::string, const std::string&>
|
||||
(
|
||||
name,
|
||||
type,
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace canvas
|
||||
SG_GENERAL,
|
||||
SG_WARN,
|
||||
"Group::getOrCreateChild: type missmatch! "
|
||||
"('" << type << "' != '" << child->getProps()->getName() << "', "
|
||||
"('" << type << "' != '" << child->getProps()->getNameString() << "', "
|
||||
"id = '" << id << "')"
|
||||
);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 )\
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() : "";
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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<std::string> d(PropertyObject<std::string>::create(n, "grape", "xyz"));
|
||||
assert(!strcmp(testRoot->getStringValue("b/grape"), "xyz"));
|
||||
assert(testRoot->getStringValue("b/grape") == "xyz");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<int>(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<const char *>::DefaultValue();
|
||||
return std::string(SGRawValue<const char *>::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<int>(_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<double>() == rhs.getValue<double>();
|
||||
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<SGVec3d>() == rhs.getValue<SGVec3d>();
|
||||
@@ -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<int>(void*) const;
|
||||
template long SGPropertyNode::getValue<long>(void*) const;
|
||||
template float SGPropertyNode::getValue<float>(void*) const;
|
||||
template double SGPropertyNode::getValue<double>(void*) const;
|
||||
template const char* SGPropertyNode::getValue<const char*>(void*) const;
|
||||
template SGVec3<double> SGPropertyNode::getValue<SGVec3<double>>(void*) const;
|
||||
template SGVec4<double> SGPropertyNode::getValue<SGVec4<double>>(void*) const;
|
||||
|
||||
@@ -4367,12 +4348,6 @@ double SGPropertyNode::getValue<double>(SGPropertyLock& lock, void* dummy) const
|
||||
return SGPropertyNodeImpl::getDoubleValue(lock, *this);
|
||||
}
|
||||
|
||||
template<>
|
||||
const char* SGPropertyNode::getValue<const char*>(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:
|
||||
{
|
||||
|
||||
@@ -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<double>(const SGPropertyNode* node)
|
||||
return node->getDoubleValue();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline const char* getValue<const char*>(const SGPropertyNode* node)
|
||||
{
|
||||
return node->getStringValue();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string getValue<std::string>(const SGPropertyNode* node)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -341,7 +341,7 @@ test_property_nodes ()
|
||||
std::vector<SGPropertyNode_ptr> 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;
|
||||
|
||||
@@ -134,7 +134,7 @@ ref_ptr<Uniform> 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<SGVec3d>()), 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);
|
||||
}
|
||||
|
||||
@@ -218,9 +218,7 @@ void findAttr(const effect::EffectPropertyMap<T>& 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<SGVec4d>();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,9 +431,8 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
|
||||
// read glyph table for taxi-/runway-signs
|
||||
std::vector<SGPropertyNode_ptr> 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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<typename T>
|
||||
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<T>(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; (i<expression->nChildren()) && !inputNode; ++i) {
|
||||
if (strcmp(expression->getChild(i)->getName(), "entry") == 0) {
|
||||
if (expression->getChild(i)->getNameString() == "entry") {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user