diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index 6d6c2ede..9191d4fb 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -252,7 +252,7 @@ compare_strings (const char * s1, const char * s2) * Locate a child node by name and index. */ static int -find_child (const char * name, int index, const vector& nodes) +find_child (const char * name, int index, const PropertyList& nodes) { int nNodes = nodes.size(); for (int i = 0; i < nNodes; i++) { @@ -270,7 +270,7 @@ find_child (const char * name, int index, const vector& node * Locate the child node with the highest index of the same name */ static int -find_last_child (const char * name, const vector& nodes) +find_last_child (const char * name, const PropertyList& nodes) { int nNodes = nodes.size(); int index = 0; @@ -854,7 +854,7 @@ SGPropertyNode::getChild (const char * name, int index, bool create) SGPropertyNode_ptr node; pos = find_child(name, index, _removedChildren); if (pos >= 0) { - vector::iterator it = _removedChildren.begin(); + PropertyList::iterator it = _removedChildren.begin(); it += pos; node = _removedChildren[pos]; _removedChildren.erase(it); @@ -888,10 +888,10 @@ SGPropertyNode::getChild (const char * name, int index) const /** * Get all children with the same name (but different indices). */ -vector +PropertyList SGPropertyNode::getChildren (const char * name) const { - vector children; + PropertyList children; int max = _children.size(); for (int i = 0; i < max; i++) @@ -929,7 +929,7 @@ SGPropertyNode::removeChild (int pos, bool keep) if (pos < 0 || pos >= (int)_children.size()) return node; - vector::iterator it = _children.begin(); + PropertyList::iterator it = _children.begin(); it += pos; node = _children[pos]; _children.erase(it); @@ -962,10 +962,10 @@ SGPropertyNode::removeChild (const char * name, int index, bool keep) /** * Remove all children with the specified name. */ -vector +PropertyList SGPropertyNode::removeChildren (const char * name, bool keep) { - vector children; + PropertyList children; for (int pos = _children.size() - 1; pos >= 0; pos--) if (compare_strings(_children[pos]->getName(), name)) diff --git a/simgear/props/props.hxx b/simgear/props/props.hxx index 44a56147..dc7a5878 100644 --- a/simgear/props/props.hxx +++ b/simgear/props/props.hxx @@ -697,6 +697,11 @@ class SGPropertyNode; typedef SGSharedPtr SGPropertyNode_ptr; typedef SGSharedPtr SGConstPropertyNode_ptr; +namespace simgear +{ +typedef std::vector PropertyList; +} + /** * The property change listener interface. @@ -892,12 +897,12 @@ public: /** * Get a vector of all children with the specified name. */ - std::vector getChildren (const char * name) const; + simgear::PropertyList getChildren (const char * name) const; /** * Get a vector of all children with the specified name. */ - std::vector getChildren (const std::string& name) const + simgear::PropertyList getChildren (const std::string& name) const { return getChildren(name.c_str()); } /** @@ -922,15 +927,13 @@ public: /** * Remove all children with the specified name. */ - std::vector removeChildren (const char * name, - bool keep = true); - + simgear::PropertyList removeChildren (const char * name, bool keep = true); /** * Remove all children with the specified name. */ - std::vector removeChildren (const std::string& name, - bool keep = true) + simgear::PropertyList removeChildren (const std::string& name, + bool keep = true) { return removeChildren(name.c_str(), keep); } // @@ -1649,8 +1652,8 @@ private: /// To avoid cyclic reference counting loops this shall not be a reference /// counted pointer SGPropertyNode * _parent; - std::vector _children; - std::vector _removedChildren; + simgear::PropertyList _children; + simgear::PropertyList _removedChildren; std::vector _linkedNodes; mutable std::string _path; mutable std::string _buffer; @@ -1901,6 +1904,15 @@ inline bool SGPropertyNode::setValue(const T& val, { return ::setValue(this, val); } + +/** + * Utility function for creation of a child property node + */ +inline SGPropertyNode* makeChild(SGPropertyNode* parent, const char* name, + int index = 0) +{ + return parent->getChild(name, index, true); +} #endif // __PROPS_HXX // end of props.hxx