2 #ifndef GNASH_OBJECTURI_H
3 #define GNASH_OBJECTURI_H
5 #include "string_table.h"
10 #define GNASH_DEBUG_OBJECT_URI_NOCASE 1
12 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
18 /// A URI for describing as_objects.
20 /// This is used as a unique identifier for any object member, especially
21 /// prototypes, class, constructors.
27 /// Default constructor, no name, no caseless name
34 /// Construct an ObjectURI from name and namespace.
35 ObjectURI(string_table::key name
)
41 operator const void*() const {
42 return (name
== 0) ? 0 : this;
46 toString(string_table
& st
) const
48 return st
.value(name
);
52 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
54 Counter(): skips(0), dos(0) {}
57 void skip() { ++skips
; }
58 void doit() { ++dos
; }
60 std::cerr
<< "Skipped " << skips
<< "/" << (skips
+dos
)
61 << " (" << (double(skips
)/double(skips
+dos
))
62 << ") calls to noCase "<< std::endl
;
67 string_table::key
noCase(string_table
& st
) const {
68 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
72 nameNoCase
= st
.noCase(name
);
73 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
77 #ifdef GNASH_DEBUG_OBJECT_URI_NOCASE
83 string_table::key name
;
85 mutable string_table::key nameNoCase
;
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
96 operator==(const ObjectURI
& a
, const ObjectURI
& b
)
98 return a
.name
== b
.name
;
102 equals(string_table
& st
, const ObjectURI
& a
, const ObjectURI
& b
, bool caseless
)
104 if ( caseless
) return equalsNoCase(st
, a
, b
);
108 /// Comparator for ObjectURI so it can serve as a key in stdlib containers.
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
)
122 class ObjectURI::Logger
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
<< ")";