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