Include program counter on action limit notification log
[gnash.git] / libcore / ObjectURI.h
bloba16af858caf53df32f623ef8375c2850e82c90d3
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
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.
9 //
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.
14 //
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
22 #ifdef HAVE_CONFIG_H
23 #include "gnashconfig.h" // GNASH_STATS_OBJECT_URI_NOCASE
24 #endif
26 #include "string_table.h"
27 #include "namedStrings.h"
29 #include <string>
30 #include <ostream>
31 #include <sstream>
33 //#define GNASH_STATS_OBJECT_URI_NOCASE 1
35 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
36 # include "Stats.h"
37 #endif
39 namespace gnash {
41 /// A URI for describing as_objects.
43 /// This is used as a unique identifier for any object member, especially
44 /// prototypes, class, constructors.
45 struct ObjectURI
48 /// Comparison taking case into account (or not).
49 class CaseLessThan;
51 /// Simple, case-sensitive less-than comparison for containers.
52 class LessThan;
54 /// Case-sensitive equality
55 class CaseEquals;
57 /// Log strings.
58 class Logger;
60 /// Default constructor.
62 /// This must be equivalent to an empty string.
63 ObjectURI()
65 name(0),
66 nameNoCase(0)
69 /// Construct an ObjectURI from name
70 ObjectURI(NSV::NamedStrings name)
72 name(name),
73 nameNoCase(0)
77 bool empty() const {
78 return (name == 0);
81 const std::string& toString(string_table& st) const {
82 return st.value(name);
85 string_table::key noCase(string_table& st) const {
87 if (!name) return 0;
89 if (!nameNoCase) {
90 nameNoCase = st.noCase(name);
91 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
92 static stats::KeyLookup statNonSkip("ObjectURI::noCase non-skips",
93 st, 0, 0, 0);
94 statNonSkip.check(name);
95 #endif
97 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
98 else {
99 static stats::KeyLookup stat("ObjectURI::noCase skips",
100 st, 0, 0, 0);
101 stat.check(name);
103 #endif
105 return nameNoCase;
108 string_table::key name;
110 private:
112 mutable string_table::key nameNoCase;
115 /// Get the name element of an ObjectURI
116 inline string_table::key
117 getName(const ObjectURI& o)
119 return o.name;
122 class ObjectURI::LessThan
124 public:
125 bool operator()(const ObjectURI& a, const ObjectURI& b) const {
126 return a.name < b.name;
130 class ObjectURI::CaseLessThan
132 public:
133 CaseLessThan(string_table& st, bool caseless = false)
135 _st(st),
136 _caseless(caseless)
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;
142 private:
143 string_table& _st;
144 const bool _caseless;
147 class ObjectURI::CaseEquals
149 public:
150 CaseEquals(string_table& st, bool caseless = false)
152 _st(st),
153 _caseless(caseless)
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;
159 private:
160 string_table& _st;
161 const bool _caseless;
164 class ObjectURI::Logger
166 public:
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 << ")";
182 return ss.str();
185 private:
186 string_table& _st;
189 } // namespace gnash
190 #endif