Identifier 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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_IDENTIFER_H
  14. #define OSG_IDENTIFER_H
  15. #include <osg/Referenced>
  16. #include <osg/Observer>
  17. #include <string>
  18. #include <cctype>
  19. #define OSG_HAS_IDENTIFIER
  20. namespace osg
  21. {
  22. /** helper function for doing a case insenstive compare of two strings.*/
  23. inline bool iequals(const std::string& lhs, const std::string& rhs)
  24. {
  25. if (lhs.size()!=rhs.size()) return false;
  26. for(std::string::size_type i=0; i<lhs.size(); ++i)
  27. {
  28. if (std::tolower(lhs[i])!=std::tolower(rhs[i])) return false;
  29. }
  30. return true;
  31. }
  32. /** Unique Identifier class to help with efficiently comparing
  33. * road classification or region via pointers.*/
  34. class OSG_EXPORT Identifier : public osg::Referenced, public osg::Observer
  35. {
  36. public:
  37. static Identifier* get(const std::string& name, int number=0, osg::Referenced* first=0, osg::Referenced* second=0);
  38. static Identifier* get(int number, osg::Referenced* first=0, osg::Referenced* second=0);
  39. static Identifier* get(osg::Referenced* first, osg::Referenced* second=0);
  40. const std::string& name() const { return _name; }
  41. const int& number() const { return _number; }
  42. protected:
  43. Identifier(const std::string& name, int number, osg::Referenced* f, osg::Referenced* s);
  44. virtual ~Identifier();
  45. virtual void objectDeleted(void* ptr);
  46. std::string _name;
  47. int _number;
  48. osg::Referenced* _first;
  49. osg::Referenced* _second;
  50. };
  51. }
  52. #endif