mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
get template elements by name
This commit is contained in:
parent
2ed895f54f
commit
b9b7ddec00
@ -247,5 +247,9 @@ get_element(int n) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
const XFileDataObject *XFileDataNodeTemplate::
|
||||
get_element(const string &name) const {
|
||||
int child_index = _template->find_child_index(name);
|
||||
if (child_index >= 0) {
|
||||
return get_element(child_index);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -57,12 +57,29 @@ find_child(const string &name) const {
|
||||
ChildrenByName::const_iterator ni;
|
||||
ni = _children_by_name.find(name);
|
||||
if (ni != _children_by_name.end()) {
|
||||
return (*ni).second;
|
||||
return get_child((*ni).second);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileNode::find_child_index
|
||||
// Access: Public
|
||||
// Description: Returns the index number of the child with the
|
||||
// indicated name, if any, or -1 if none.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileNode::
|
||||
find_child_index(const string &name) const {
|
||||
ChildrenByName::const_iterator ni;
|
||||
ni = _children_by_name.find(name);
|
||||
if (ni != _children_by_name.end()) {
|
||||
return (*ni).second;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileNode::find_descendent
|
||||
// Access: Public
|
||||
@ -117,13 +134,13 @@ get_guid() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void XFileNode::
|
||||
add_child(XFileNode *node) {
|
||||
_children.push_back(node);
|
||||
if (node->has_name()) {
|
||||
_children_by_name[node->get_name()] = node;
|
||||
_children_by_name[node->get_name()] = (int)_children.size();
|
||||
}
|
||||
if (node->has_guid()) {
|
||||
_x_file->_nodes_by_guid[node->get_guid()] = node;
|
||||
}
|
||||
_children.push_back(node);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
INLINE int get_num_children() const;
|
||||
INLINE XFileNode *get_child(int n) const;
|
||||
XFileNode *find_child(const string &name) const;
|
||||
int find_child_index(const string &name) const;
|
||||
XFileNode *find_descendent(const string &name) const;
|
||||
|
||||
virtual bool has_guid() const;
|
||||
@ -73,7 +74,7 @@ protected:
|
||||
typedef pvector< PT(XFileNode) > Children;
|
||||
Children _children;
|
||||
|
||||
typedef pmap<string, XFileNode *> ChildrenByName;
|
||||
typedef pmap<string, int> ChildrenByName;
|
||||
ChildrenByName _children_by_name;
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user