ObserverNodePath 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifndef OSG_OBSERVERNODEPATH
  14. #define OSG_OBSERVERNODEPATH 1
  15. #include <osg/Node>
  16. #include <osg/observer_ptr>
  17. #include <vector>
  18. namespace osg {
  19. typedef std::vector< osg::ref_ptr<osg::Node> > RefNodePath;
  20. /** ObserverNodePath is an observer class for tracking changes to a NodePath,
  21. * that automatically invalidates it when nodes are deleted.*/
  22. class OSG_EXPORT ObserverNodePath
  23. {
  24. public:
  25. ObserverNodePath();
  26. ObserverNodePath(const ObserverNodePath& rhs);
  27. ObserverNodePath(const osg::NodePath& nodePath);
  28. ~ObserverNodePath();
  29. ObserverNodePath& operator = (const ObserverNodePath& rhs);
  30. /** get the NodePath from the first parental chain back to root, plus the specified node.*/
  31. void setNodePathTo(osg::Node* node);
  32. void setNodePath(const osg::RefNodePath& nodePath);
  33. void setNodePath(const osg::NodePath& nodePath);
  34. void clearNodePath();
  35. /** Get a thread safe RefNodePath, return true if NodePath is valid.*/
  36. bool getRefNodePath(RefNodePath& refNodePath) const;
  37. /** Get a lightweight NodePath that isn't thread safe but
  38. * may be safely used in single threaded applications, or when
  39. * its known that the NodePath won't be invalidated during usage
  40. * of the NodePath. return true if NodePath is valid.*/
  41. bool getNodePath(NodePath& nodePath) const;
  42. bool empty() const
  43. {
  44. OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
  45. return _nodePath.empty();
  46. }
  47. protected:
  48. void _setNodePath(const osg::NodePath& nodePath);
  49. void _clearNodePath();
  50. typedef std::vector< osg::observer_ptr<osg::Node> > ObsNodePath;
  51. mutable OpenThreads::Mutex _mutex;
  52. ObsNodePath _nodePath;
  53. };
  54. }
  55. #endif