2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
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"
32 //#define GNASH_STATS_OBJECT_URI_NOCASE 1
34 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
40 /// A URI for describing as_objects.
42 /// This is used as a unique identifier for any object member, especially
43 /// prototypes, class, constructors.
47 /// Comparison taking case into account (or not).
50 /// Simple, case-sensitive less-than comparison for containers.
53 /// Case-sensitive equality
59 /// Default constructor.
61 /// This must be equivalent to an empty string.
68 /// Construct an ObjectURI from name
69 ObjectURI(NSV::NamedStrings name
)
80 const std::string
& toString(string_table
& st
) const {
81 return st
.value(name
);
84 string_table::key
noCase(string_table
& st
) const {
89 nameNoCase
= st
.noCase(name
);
90 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
91 static stats::KeyLookup
statNonSkip("ObjectURI::noCase non-skips",
93 statNonSkip
.check(name
);
96 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
98 static stats::KeyLookup
stat("ObjectURI::noCase skips",
107 string_table::key name
;
111 mutable string_table::key nameNoCase
;
114 /// Get the name element of an ObjectURI
115 inline string_table::key
116 getName(const ObjectURI
& o
)
121 class ObjectURI::LessThan
124 bool operator()(const ObjectURI
& a
, const ObjectURI
& b
) const {
125 return a
.name
< b
.name
;
129 class ObjectURI::CaseLessThan
132 CaseLessThan(string_table
& st
, bool caseless
= false)
137 bool operator()(const ObjectURI
& a
, const ObjectURI
& b
) const {
138 if (_caseless
) return a
.noCase(_st
) < b
.noCase(_st
);
139 return a
.name
< b
.name
;
143 const bool _caseless
;
146 class ObjectURI::CaseEquals
149 CaseEquals(string_table
& st
, bool caseless
= false)
154 bool operator()(const ObjectURI
& a
, const ObjectURI
& b
) const {
155 if (_caseless
) return a
.noCase(_st
) == b
.noCase(_st
);
156 return a
.name
== b
.name
;
160 const bool _caseless
;
163 class ObjectURI::Logger
166 Logger(string_table
& st
) : _st(st
) {}
168 std::string
operator()(const ObjectURI
& uri
) const {
169 const string_table::key name
= getName(uri
);
170 return _st
.value(name
);
173 std::string
debug(const ObjectURI
& uri
) const {
174 std::stringstream ss
;
175 const string_table::key name
= getName(uri
);
176 const string_table::key nameNoCase
= uri
.noCase(_st
);
177 ss
<< _st
.value(name
)
178 << "(" << name
<< ")/"
179 << _st
.value(nameNoCase
)
180 << "(" << nameNoCase
<< ")";