Refactored Observer/ObserverNodePath and DatabasePager to improve their robustness.

This commit is contained in:
Robert Osfield
2010-05-14 12:24:13 +00:00
parent 2b2ea4487a
commit 554adfc8e6
5 changed files with 88 additions and 151 deletions

View File

@@ -15,17 +15,16 @@
#define OSG_OBSERVERNODEPATH 1
#include <osg/Node>
#include <osg/Observer>
#include <osg/ref_ptr>
#include <list>
#include <osg/observer_ptr>
#include <vector>
namespace osg {
typedef std::list< osg::ref_ptr<osg::Node> > RefNodePath;
typedef std::vector< osg::ref_ptr<osg::Node> > RefNodePath;
/** ObserverNodePath is an observer class for tracking changes to a NodePath,
* that automatically invalidates it when nodes are deleted.*/
class OSG_EXPORT ObserverNodePath : public osg::Observer
class OSG_EXPORT ObserverNodePath
{
public:
ObserverNodePath();
@@ -38,9 +37,6 @@ class OSG_EXPORT ObserverNodePath : public osg::Observer
ObserverNodePath& operator = (const ObserverNodePath& rhs);
bool valid() const { return _valid; }
/** get the NodePath from the first parental chain back to root, plus the specified node.*/
void setNodePathTo(osg::Node* node);
@@ -61,21 +57,18 @@ class OSG_EXPORT ObserverNodePath : public osg::Observer
bool empty() const
{
if (!_valid) return true;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getObserverMutex());
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return _nodePath.empty();
}
protected:
void _setNodePath(const osg::NodePath& nodePath);
void _clearNodePath();
virtual bool objectUnreferenced(void* ptr);
osg::NodePath _nodePath;
bool _valid;
typedef std::vector< osg::observer_ptr<osg::Node> > ObsNodePath;
mutable OpenThreads::Mutex _mutex;
ObsNodePath _nodePath;
};
}