openscenegraph
ObserverNodePath
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_OBSERVERNODEPATH
15#define OSG_OBSERVERNODEPATH 1
16
17#include <osg/Node>
18#include <osg/observer_ptr>
19#include <vector>
20
21namespace osg {
22
23typedef std::vector< osg::ref_ptr<osg::Node> > RefNodePath;
24
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
28{
29 public:
30 ObserverNodePath();
31
32 ObserverNodePath(const ObserverNodePath& rhs);
33
34 ObserverNodePath(const osg::NodePath& nodePath);
35
36 ~ObserverNodePath();
37
38 ObserverNodePath& operator = (const ObserverNodePath& rhs);
39
40 /** get the NodePath from the first parental chain back to root, plus the specified node.*/
41 void setNodePathTo(osg::Node* node);
42
43 void setNodePath(const osg::RefNodePath& nodePath);
44
45 void setNodePath(const osg::NodePath& nodePath);
46
47 void clearNodePath();
48
49 /** Get a thread safe RefNodePath, return true if NodePath is valid.*/
50 bool getRefNodePath(RefNodePath& refNodePath) const;
51
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;
57
58 bool empty() const
59 {
60 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
61 return _nodePath.empty();
62 }
63
64 protected:
65
66 void _setNodePath(const osg::NodePath& nodePath);
67 void _clearNodePath();
68
69 typedef std::vector< osg::observer_ptr<osg::Node> > ObsNodePath;
70 mutable OpenThreads::Mutex _mutex;
71 ObsNodePath _nodePath;
72};
73
74}
75
76#endif