Added osg::RefNodePath class for handling node paths.
This commit is contained in:
101
include/osg/RefNodePath
Normal file
101
include/osg/RefNodePath
Normal file
@@ -0,0 +1,101 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_REFNODEPATH
|
||||
#define OSG_REFNODEPATH 1
|
||||
|
||||
#include <osg/Group>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class RefNodePath : public NodeList
|
||||
{
|
||||
public :
|
||||
|
||||
inline RefNodePath() {}
|
||||
|
||||
inline RefNodePath(const RefNodePath& refNodePath):
|
||||
NodeList(refNodePath) {}
|
||||
|
||||
inline explicit RefNodePath(const NodePath& nodePath)
|
||||
{
|
||||
for(osg::NodePath::const_iterator itr=nodePath.begin();
|
||||
itr != nodePath.end();
|
||||
++itr)
|
||||
{
|
||||
push_back(*itr);
|
||||
}
|
||||
}
|
||||
|
||||
inline operator NodePath () const
|
||||
{
|
||||
NodePath nodePath;
|
||||
for(NodeList::const_iterator itr=begin();
|
||||
itr != end();
|
||||
++itr)
|
||||
{
|
||||
nodePath.push_back(const_cast<Node*>(itr->get()));
|
||||
}
|
||||
|
||||
return nodePath;
|
||||
}
|
||||
|
||||
/** Check the validity of the RefNodePath to ensure that the parent path
|
||||
* matches those availble in the leaf node of the path.*/
|
||||
bool valid() const
|
||||
{
|
||||
// an empty NodePaath is invalid.
|
||||
if (empty()) return false;
|
||||
|
||||
// check to make sure that this RefNodeList isn't the only
|
||||
// place that the nodes are referenced, if one node has
|
||||
// a ref count of 1 then nodes must have been removed
|
||||
// from the scene graph elsewhere invalidating this RefNodePath.
|
||||
for(const_iterator itr=begin();
|
||||
itr != end();
|
||||
++itr)
|
||||
{
|
||||
if ((*itr)->referenceCount()<=1) return false;
|
||||
}
|
||||
|
||||
const_reverse_iterator ritr=rbegin();
|
||||
const osg::Node* node = ritr->get();
|
||||
++ritr;
|
||||
while (ritr!=rend())
|
||||
{
|
||||
const osg::Node* parent = ritr->get();
|
||||
// search of parent in current nodes parent list
|
||||
const osg::Node::ParentList& parents = node->getParents();
|
||||
osg::Node::ParentList::const_iterator pitr=parents.begin();
|
||||
for(; pitr!=parents.end() && parent!=*pitr; ++pitr) {}
|
||||
if (pitr==parents.end())
|
||||
{
|
||||
// original parent not found, so linkage must have changed
|
||||
// invalidating this RefNodePath.
|
||||
return false;
|
||||
}
|
||||
|
||||
node = parent;
|
||||
++ritr;
|
||||
}
|
||||
|
||||
// we've passed all the test that could invalidate this RefNodePath
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user