* 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++) {
* 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;
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);
/**
* 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++)
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);
/**
* 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))
typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
+namespace simgear
+{
+typedef std::vector<SGPropertyNode_ptr> PropertyList;
+}
+
\f
/**
* The property change listener interface.
/**
* 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()); }
/**
/**
* 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); }
//
/// 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;
{
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