PrintVisitor 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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 OSGUTIL_PRINTVISITOR
  14. #define OSGUTIL_PRINTVISITOR 1
  15. #include <osg/NodeVisitor>
  16. #include <osgUtil/Export>
  17. #include <ostream>
  18. namespace osgUtil {
  19. class OSGUTIL_EXPORT PrintVisitor : public osg::NodeVisitor
  20. {
  21. public:
  22. PrintVisitor(std::ostream& out, int indent=0, int step=2);
  23. void apply(osg::Node& node);
  24. std::ostream& output()
  25. {
  26. for(unsigned int i=0;i<_indent; ++i) _out<<" ";
  27. return _out;
  28. }
  29. void enter() { _indent += _step; }
  30. void leave() { _indent -= _step; }
  31. protected:
  32. PrintVisitor& operator = (const PrintVisitor&) { return *this; }
  33. std::ostream& _out;
  34. unsigned int _indent;
  35. unsigned int _step;
  36. };
  37. }
  38. #endif