Add PropertyList typedef for vectors of property list nodes.

This commit is contained in:
timoore 2009-07-15 23:08:30 +00:00 committed by Tim Moore
parent 58417e78e5
commit abd4aa2e6b
2 changed files with 29 additions and 17 deletions

View File

@ -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<SGPropertyNode_ptr>& 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<SGPropertyNode_ptr>& node
* Locate the child node with the highest index of the same name
*/
static int
find_last_child (const char * name, const vector<SGPropertyNode_ptr>& 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<SGPropertyNode_ptr>::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<SGPropertyNode_ptr>
PropertyList
SGPropertyNode::getChildren (const char * name) const
{
vector<SGPropertyNode_ptr> 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<SGPropertyNode_ptr>::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<SGPropertyNode_ptr>
PropertyList
SGPropertyNode::removeChildren (const char * name, bool keep)
{
vector<SGPropertyNode_ptr> children;
PropertyList children;
for (int pos = _children.size() - 1; pos >= 0; pos--)
if (compare_strings(_children[pos]->getName(), name))

View File

@ -697,6 +697,11 @@ class SGPropertyNode;
typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
namespace simgear
{
typedef std::vector<SGPropertyNode_ptr> PropertyList;
}
/**
* The property change listener interface.
@ -892,12 +897,12 @@ public:
/**
* Get a vector of all children with the specified name.
*/
std::vector<SGPropertyNode_ptr> getChildren (const char * name) const;
simgear::PropertyList getChildren (const char * name) const;
/**
* Get a vector of all children with the specified name.
*/
std::vector<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> _children;
std::vector<SGPropertyNode_ptr> _removedChildren;
simgear::PropertyList _children;
simgear::PropertyList _removedChildren;
std::vector<hash_table *> _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