Move equals function after equality operator, or the syntetized one would be used
[gnash.git] / libcore / ObjectURI.h
blobd14a3848a642d4a8e9cb2acb1d8bcf8746bf5b86
2 #ifndef GNASH_OBJECTURI_H
3 #define GNASH_OBJECTURI_H
5 #include "string_table.h"
6 #include <string>
7 #include <ostream>
8 #include <sstream>
10 #define GNASH_DEBUG_OBJECT_URI_NOCASE 1
12 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
13 # include <iostream>
14 #endif
16 namespace gnash {
18 /// A URI for describing as_objects.
20 /// This is used as a unique identifier for any object member, especially
21 /// prototypes, class, constructors.
22 struct ObjectURI
25 class Logger;
27 /// Default constructor, no name, no caseless name
28 ObjectURI()
30 name(0),
31 nameNoCase(0)
34 /// Construct an ObjectURI from name and namespace.
35 ObjectURI(string_table::key name)
37 name(name),
38 nameNoCase(0)
41 operator const void*() const {
42 return (name == 0) ? 0 : this;
45 const std::string&
46 toString(string_table& st) const
48 return st.value(name);
52 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
53 struct Counter {
54 Counter(): skips(0), dos(0) {}
55 int skips;
56 int dos;
57 void skip() { ++skips; }
58 void doit() { ++dos; }
59 ~Counter () {
60 std::cerr << "Skipped " << skips << "/" << (skips+dos)
61 << " (" << (double(skips)/double(skips+dos))
62 << ") calls to noCase "<< std::endl;
65 #endif
67 string_table::key noCase(string_table& st) const {
68 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
69 static Counter stat;
70 #endif
71 if ( ! nameNoCase ) {
72 nameNoCase = st.noCase(name);
73 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
74 stat.doit();
75 #endif
77 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
78 else stat.skip();
79 #endif
80 return nameNoCase;
83 string_table::key name;
85 mutable string_table::key nameNoCase;
88 inline bool
89 equalsNoCase(string_table& st, const ObjectURI& a, const ObjectURI& b)
91 return a.noCase(st) == b.noCase(st);
94 /// ObjectURIs are equal if name is equal
95 inline bool
96 operator==(const ObjectURI& a, const ObjectURI& b)
98 return a.name == b.name;
101 inline bool
102 equals(string_table& st, const ObjectURI& a, const ObjectURI& b, bool caseless)
104 if ( caseless ) return equalsNoCase(st, a, b);
105 else return a == b;
108 /// Comparator for ObjectURI so it can serve as a key in stdlib containers.
109 inline bool
110 operator<(const ObjectURI& a, const ObjectURI& b)
112 return a.name < b.name;
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::Logger
124 public:
125 Logger(string_table& st) : _st(st) {}
127 std::string operator()(const ObjectURI& uri) const {
128 const string_table::key name = getName(uri);
129 return _st.value(name);
132 std::string debug(const ObjectURI& uri) const {
133 std::stringstream ss;
134 const string_table::key name = getName(uri);
135 const string_table::key nameNoCase = uri.noCase(_st);
136 ss << _st.value(name)
137 << "(" << name << ")/"
138 << _st.value(nameNoCase)
139 << "(" << nameNoCase << ")";
140 return ss.str();
143 private:
144 string_table& _st;
147 } // namespace gnash
148 #endif