Gnash  0.8.11dev
ObjectURI.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software 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
18 
19 #ifndef GNASH_OBJECTURI_H
20 #define GNASH_OBJECTURI_H
21 
22 #ifdef HAVE_CONFIG_H
23 #include "gnashconfig.h" // GNASH_STATS_OBJECT_URI_NOCASE
24 #endif
25 
26 #include "string_table.h"
27 #include "namedStrings.h"
28 
29 #include <string>
30 #include <sstream>
31 
32 //#define GNASH_STATS_OBJECT_URI_NOCASE 1
33 
34 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
35 # include "Stats.h"
36 #endif
37 
38 namespace gnash {
39 
41 //
44 struct ObjectURI
45 {
46 
48  class CaseLessThan;
49 
51  class LessThan;
52 
54  class CaseEquals;
55 
57  class Logger;
58 
60  //
63  :
64  name(0),
65  nameNoCase(0)
66  {}
67 
70  :
71  name(name),
72  nameNoCase(0)
73  {}
74 
75 
76  bool empty() const {
77  return (name == 0);
78  }
79 
80  const std::string& toString(string_table& st) const {
81  return st.value(name);
82  }
83 
85 
86  if (!name) return 0;
87 
88  if (!nameNoCase) {
89  nameNoCase = st.noCase(name);
90 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
91  static stats::KeyLookup statNonSkip("ObjectURI::noCase non-skips",
92  st, 0, 0, 0);
93  statNonSkip.check(name);
94 #endif
95  }
96 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
97  else {
98  static stats::KeyLookup stat("ObjectURI::noCase skips",
99  st, 0, 0, 0);
100  stat.check(name);
101  }
102 #endif
103 
104  return nameNoCase;
105  }
106 
108 
109 private:
110 
111  mutable string_table::key nameNoCase;
112 };
113 
115 inline string_table::key
117 {
118  return o.name;
119 }
120 
122 {
123 public:
124  bool operator()(const ObjectURI& a, const ObjectURI& b) const {
125  return a.name < b.name;
126  }
127 };
128 
130 {
131 public:
132  CaseLessThan(string_table& st, bool caseless = false)
133  :
134  _st(st),
135  _caseless(caseless)
136  {}
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;
140  }
141 private:
142  string_table& _st;
143  const bool _caseless;
144 };
145 
147 {
148 public:
149  CaseEquals(string_table& st, bool caseless = false)
150  :
151  _st(st),
152  _caseless(caseless)
153  {}
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;
157  }
158 private:
159  string_table& _st;
160  const bool _caseless;
161 };
162 
164 {
165 public:
166  Logger(string_table& st) : _st(st) {}
167 
168  std::string operator()(const ObjectURI& uri) const {
169  const string_table::key name = getName(uri);
170  return _st.value(name);
171  }
172 
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 << ")";
181  return ss.str();
182  }
183 
184 private:
185  string_table& _st;
186 };
187 
188 } // namespace gnash
189 #endif
Definition: GnashKey.h:147
key noCase(key a) const
Return a caseless equivalent of the passed key.
Definition: string_table.cpp:144
string_table::key getName(const ObjectURI &o)
Get the name element of an ObjectURI.
Definition: ObjectURI.h:116
bool operator()(const ObjectURI &a, const ObjectURI &b) const
Definition: ObjectURI.h:154
const std::string & value(key to_find) const
Find a string by its key.
Definition: string_table.h:102
uri
Definition: test.py:12
CaseLessThan(string_table &st, bool caseless=false)
Definition: ObjectURI.h:132
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void check(string_table::key k)
Definition: Stats.h:61
Definition: GnashKey.h:161
string_table::key name
Definition: ObjectURI.h:107
A general use string table.
Definition: string_table.h:41
A URI for describing as_objects.
Definition: ObjectURI.h:44
NamedStrings
Definition: namedStrings.h:57
CaseEquals(string_table &st, bool caseless=false)
Definition: ObjectURI.h:149
Definition: Stats.h:33
bool operator()(const ObjectURI &a, const ObjectURI &b) const
Definition: ObjectURI.h:124
string_table::key noCase(string_table &st) const
Definition: ObjectURI.h:84
Definition: GnashKey.h:148
ObjectURI(NSV::NamedStrings name)
Construct an ObjectURI from name.
Definition: ObjectURI.h:69
std::string debug(const ObjectURI &uri) const
Definition: ObjectURI.h:173
Definition: ObjectURI.h:129
bool empty() const
Definition: ObjectURI.h:76
bool caseless(const as_object &o)
Return whether property matching is caseless.
Definition: as_object.h:924
const std::string & toString(string_table &st) const
Definition: ObjectURI.h:80
std::string operator()(const ObjectURI &uri) const
Definition: ObjectURI.h:168
bool operator()(const ObjectURI &a, const ObjectURI &b) const
Definition: ObjectURI.h:137
std::size_t key
Definition: string_table.h:83
ObjectURI()
Default constructor.
Definition: ObjectURI.h:62
Logger(string_table &st)
Definition: ObjectURI.h:166
Definition: ObjectURI.h:146
Definition: ObjectURI.h:163
Definition: ObjectURI.h:121