24 #ifndef PXR_BASE_TF_TYPE_INFO_MAP_H
25 #define PXR_BASE_TF_TYPE_INFO_MAP_H
61 template <
class VALUE>
72 bool Exists(
const std::type_info& key)
const {
73 return Find(key) != NULL;
80 return Find(key) != NULL;
85 VALUE*
Find(
const std::type_info& key)
const {
87 if (i != _typeInfoCache.
end())
88 return &i->second->value;
89 else if (VALUE*
v =
Find(key.name())) {
100 template <
class Upgrader>
101 VALUE*
Find(
const std::type_info& key, Upgrader& upgrader) {
103 if (i != _typeInfoCache.
end())
104 return &i->second->value;
105 else if (VALUE*
v =
Find(key.name())) {
107 _CreateAlias(key, key.name());
119 return (i == _stringCache.
end()) ? NULL : &i->second->value;
128 void Set(
const std::type_info& key,
const VALUE&
value) {
129 if (VALUE*
v =
Find(key))
133 _CreateAlias(key, key.name());
145 if (i != _stringCache.
end())
146 i->second->value = value;
148 _Entry* e = &_nameMap[key];
152 _stringCache[key] = e;
153 e->stringAliases.push_back(key);
166 if (i != _stringCache.end())
167 return (_CreateAlias(alias, i->second),
true);
175 if (i != _typeInfoCache.end())
176 return (_CreateAlias(alias, i->second),
true);
189 if (i == _stringCache.end())
192 _Entry* e = i->second;
195 _typeInfoCache.erase(*
j);
198 for (
TfIterator<std::list<std::string> >
j = e->stringAliases;
j; ++
j) {
199 _stringCache.erase(*
j);
207 const std::string primaryKey = std::move(e->primaryKey);
208 _nameMap.erase(primaryKey);
212 typedef std::list<const std::type_info*> _TypeInfoList;
215 mutable _TypeInfoList typeInfoAliases;
216 mutable std::list<std::string> stringAliases;
221 void _CreateAlias(
const std::type_info& alias,
const std::string& key) {
222 typename _StringCache::iterator i = _stringCache.find(key);
223 if (i != _stringCache.end())
224 _CreateAlias(alias, i->second);
227 void _CreateAlias(
const std::type_info& alias, _Entry* e) {
228 if (_typeInfoCache.find(&alias) == _typeInfoCache.end()) {
229 _typeInfoCache[&alias] = e;
230 e->typeInfoAliases.push_back(&alias);
234 void _CreateAlias(
const std::string& alias, _Entry* e) {
235 if (_stringCache.find(alias) == _stringCache.end()) {
236 _stringCache[alias] = e;
237 e->stringAliases.push_back(alias);
248 _TypeInfoCache _typeInfoCache;
249 _StringCache _stringCache;
254 #endif // PXR_BASE_TF_TYPE_INFO_MAP_H
_Base::const_iterator const_iterator
void Remove(const std::string &key)
Remove this key (and any aliases associated with it).
bool Exists(const std::string &key) const
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
VALUE * Find(const std::type_info &key, Upgrader &upgrader)
bool Exists(const std::type_info &key) const
Return true if the given key is present in the map.
bool CreateAlias(const std::string &alias, const std::type_info &key)
VALUE * Find(const std::string &key) const
void Set(const std::type_info &key, const VALUE &value)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
VALUE * Find(const std::type_info &key) const
bool CreateAlias(const std::string &alias, const std::string &key)
#define PXR_NAMESPACE_CLOSE_SCOPE
void Remove(const std::type_info &key)
Remove this key (and any aliases associated with it).
void Set(const std::string &key, const VALUE &value)