preserve get_key() after a remove_node() operation

This commit is contained in:
David Rose 2003-10-27 23:36:54 +00:00
parent 8a45c38537
commit 9ccec9bb73
5 changed files with 38 additions and 3 deletions

View File

@ -41,6 +41,7 @@ NodePath(const string &top_node_name) :
{
PandaNode *top_node = new PandaNode(top_node_name);
_head = top_node->get_generic_component(false);
_backup_key = 0;
}
////////////////////////////////////////////////////////////////////
@ -61,6 +62,7 @@ NodePath(PandaNode *node) :
if (node != (PandaNode *)NULL) {
_head = node->get_generic_component(false);
}
_backup_key = 0;
}
////////////////////////////////////////////////////////////////////
@ -100,6 +102,7 @@ NodePath(const NodePath &parent, PandaNode *child_node) :
if (_head != (NodePathComponent *)NULL) {
_error_type = ET_ok;
}
_backup_key = 0;
}
////////////////////////////////////////////////////////////////////
@ -110,6 +113,7 @@ NodePath(const NodePath &parent, PandaNode *child_node) :
INLINE NodePath::
NodePath(const NodePath &copy) :
_head(copy._head),
_backup_key(copy._backup_key),
_error_type(copy._error_type)
{
}
@ -122,6 +126,7 @@ NodePath(const NodePath &copy) :
INLINE void NodePath::
operator = (const NodePath &copy) {
_head = copy._head;
_backup_key = copy._backup_key;
_error_type = copy._error_type;
}
@ -266,7 +271,7 @@ node() const {
INLINE int NodePath::
get_key() const {
if (is_empty()) {
return 0;
return _backup_key;
}
return _head->get_key();
}

View File

@ -473,7 +473,16 @@ remove_node() {
PandaNode::detach(_head);
}
(*this) = NodePath::removed();
if (is_empty() || _head->has_key()) {
// Preserve the key we had on the node before we removed it.
int key = get_key();
(*this) = NodePath::removed();
_backup_key = key;
} else {
// We didn't have a key; just clear the NodePath.
(*this) = NodePath::removed();
}
}
////////////////////////////////////////////////////////////////////

View File

@ -111,8 +111,13 @@ class GlobPattern;
// +h Do return hidden nodes.
// -s Do not return stashed nodes unless explicitly referenced with @@.
// +s Return stashed nodes even without any explicit @@ characters.
// -i Node name comparisons are not case insensitive: case must match
// exactly.
// +i Node name comparisons are case insensitive: case is not important.
// This affects matches against the node name only; node type
// and tag strings are always case sensitive.
//
// The default flags are +h-s.
// The default flags are +h-s-i.
//
@ -630,6 +635,7 @@ private:
GraphicsStateGuardianBase *gsg, bool do_retained_mode);
PT(NodePathComponent) _head;
int _backup_key;
ErrorType _error_type;
static int _max_search_depth;

View File

@ -105,6 +105,20 @@ get_node() const {
return _node;
}
////////////////////////////////////////////////////////////////////
// Function: NodePathComponent::has_key
// Access: Public
// Description: Returns true if the key for this component has
// already been generated, false otherwise. Even if
// this returns false, calling get_key() will still
// return a valid key; that will simply cause the key to
// be generated on-the-fly.
////////////////////////////////////////////////////////////////////
INLINE bool NodePathComponent::
has_key() const {
return (_key != 0);
}
INLINE ostream &operator << (ostream &out, const NodePathComponent &comp) {
comp.output(out);
return out;

View File

@ -54,6 +54,7 @@ public:
INLINE ~NodePathComponent();
INLINE PandaNode *get_node() const;
INLINE bool has_key() const;
int get_key() const;
bool is_top_node() const;