1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSG_OBSERVERNODEPATH
15#define OSG_OBSERVERNODEPATH 1
18#include <osg/observer_ptr>
23typedef std::vector< osg::ref_ptr<osg::Node> > RefNodePath;
25/** ObserverNodePath is an observer class for tracking changes to a NodePath,
26 * that automatically invalidates it when nodes are deleted.*/
27class OSG_EXPORT ObserverNodePath
32 ObserverNodePath(const ObserverNodePath& rhs);
34 ObserverNodePath(const osg::NodePath& nodePath);
38 ObserverNodePath& operator = (const ObserverNodePath& rhs);
40 /** get the NodePath from the first parental chain back to root, plus the specified node.*/
41 void setNodePathTo(osg::Node* node);
43 void setNodePath(const osg::RefNodePath& nodePath);
45 void setNodePath(const osg::NodePath& nodePath);
49 /** Get a thread safe RefNodePath, return true if NodePath is valid.*/
50 bool getRefNodePath(RefNodePath& refNodePath) const;
52 /** Get a lightweight NodePath that isn't thread safe but
53 * may be safely used in single threaded applications, or when
54 * its known that the NodePath won't be invalidated during usage
55 * of the NodePath. return true if NodePath is valid.*/
56 bool getNodePath(NodePath& nodePath) const;
60 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
61 return _nodePath.empty();
66 void _setNodePath(const osg::NodePath& nodePath);
67 void _clearNodePath();
69 typedef std::vector< osg::observer_ptr<osg::Node> > ObsNodePath;
70 mutable OpenThreads::Mutex _mutex;
71 ObsNodePath _nodePath;