2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_OBJECTURI_H
20 #define GNASH_OBJECTURI_H
23 #include "gnashconfig.h" // GNASH_STATS_OBJECT_URI_NOCASE
26 #include "string_table.h"
27 #include "namedStrings.h"
33 //#define GNASH_STATS_OBJECT_URI_NOCASE 1
35 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
41 /// A URI for describing as_objects.
43 /// This is used as a unique identifier for any object member, especially
44 /// prototypes, class, constructors.
48 /// Comparison taking case into account (or not).
51 /// Simple, case-sensitive less-than comparison for containers.
54 /// Case-sensitive equality
60 /// Default constructor.
62 /// This must be equivalent to an empty string.
69 /// Construct an ObjectURI from name
70 ObjectURI(NSV::NamedStrings name
)
81 const std::string
& toString(string_table
& st
) const {
82 return st
.value(name
);
85 string_table::key
noCase(string_table
& st
) const {
90 nameNoCase
= st
.noCase(name
);
91 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
92 static stats::KeyLookup
statNonSkip("ObjectURI::noCase non-skips",
94 statNonSkip
.check(name
);
97 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
99 static stats::KeyLookup
stat("ObjectURI::noCase skips",
108 string_table::key name
;
112 mutable string_table::key nameNoCase
;
115 /// Get the name element of an ObjectURI
116 inline string_table::key
117 getName(const ObjectURI
& o
)
122 class ObjectURI::LessThan
125 bool operator()(const ObjectURI
& a
, const ObjectURI
& b
) const {
126 return a
.name
< b
.name
;
130 class ObjectURI::CaseLessThan
133 CaseLessThan(string_table
& st
, bool caseless
= false)
138 bool operator()(const ObjectURI
& a
, const ObjectURI
& b
) const {
139 if (_caseless
) return a
.noCase(_st
) < b
.noCase(_st
);
140 return a
.name
< b
.name
;
144 const bool _caseless
;
147 class ObjectURI::CaseEquals
150 CaseEquals(string_table
& st
, bool caseless
= false)
155 bool operator()(const ObjectURI
& a
, const ObjectURI
& b
) const {
156 if (_caseless
) return a
.noCase(_st
) == b
.noCase(_st
);
157 return a
.name
== b
.name
;
161 const bool _caseless
;
164 class ObjectURI::Logger
167 Logger(string_table
& st
) : _st(st
) {}
169 std::string
operator()(const ObjectURI
& uri
) const {
170 const string_table::key name
= getName(uri
);
171 return _st
.value(name
);
174 std::string
debug(const ObjectURI
& uri
) const {
175 std::stringstream ss
;
176 const string_table::key name
= getName(uri
);
177 const string_table::key nameNoCase
= uri
.noCase(_st
);
178 ss
<< _st
.value(name
)
179 << "(" << name
<< ")/"
180 << _st
.value(nameNoCase
)
181 << "(" << nameNoCase
<< ")";