24#ifndef PXR_BASE_TF_TYPE_INFO_MAP_H
25#define PXR_BASE_TF_TYPE_INFO_MAP_H
36#include "pxr/base/tf/hashmap.h"
42PXR_NAMESPACE_OPEN_SCOPE
72 bool Exists(
const std::type_info& key)
const {
73 return Find(key) != NULL;
79 bool Exists(
const std::string& key)
const {
80 return Find(key) != NULL;
85 VALUE*
Find(
const std::type_info& key)
const {
86 typename _TypeInfoCache::const_iterator i = _typeInfoCache.find(&key);
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) {
102 typename _TypeInfoCache::const_iterator i = _typeInfoCache.find(&key);
103 if (i != _typeInfoCache.end())
104 return &i->second->value;
105 else if (VALUE* v =
Find(key.name())) {
107 _CreateAlias(key, key.name());
117 VALUE*
Find(
const std::string& key)
const {
118 typename _StringCache::const_iterator i = _stringCache.find(key);
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))
132 Set(key.name(), value);
133 _CreateAlias(key, key.name());
142 void Set(
const std::string& key,
const VALUE& value) {
143 typename _StringCache::iterator i = _stringCache.find(key);
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);
164 bool CreateAlias(
const std::string& alias,
const std::string& key) {
165 typename _StringCache::iterator i = _stringCache.find(key);
166 if (i != _stringCache.end())
167 return (_CreateAlias(alias, i->second),
true);
173 bool CreateAlias(
const std::string& alias,
const std::type_info& key) {
174 typename _TypeInfoCache::iterator i = _typeInfoCache.find(&key);
175 if (i != _typeInfoCache.end())
176 return (_CreateAlias(alias, i->second),
true);
188 typename _StringCache::iterator i = _stringCache.find(key);
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;
217 std::string primaryKey;
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);
241 typedef TfHashMap<std::string, _Entry, TfHash> _NameMap;
242 typedef TfHashMap<const std::type_info*, _Entry*, TfHash>
244 typedef TfHashMap<std::string, _Entry*, TfHash> _StringCache;
248 _TypeInfoCache _typeInfoCache;
249 _StringCache _stringCache;
252PXR_NAMESPACE_CLOSE_SCOPE
A simple iterator adapter for STL containers.
A simple iterator adapter for STL containers.
A map whose key is a const std::type_info&, or a string alias.
void Set(const std::type_info &key, const VALUE &value)
Set the value for a given key.
void Remove(const std::type_info &key)
Remove this key (and any aliases associated with it).
bool Exists(const std::type_info &key) const
Return true if the given key is present in the map.
void Remove(const std::string &key)
Remove this key (and any aliases associated with it).
VALUE * Find(const std::string &key) const
Return a pointer to the value stored under key, and NULL if key is not a key in the map.
void Set(const std::string &key, const VALUE &value)
Set the value for a given key.
VALUE * Find(const std::type_info &key) const
Return a pointer to the value stored under key, and NULL if key is not a key in the map.
VALUE * Find(const std::type_info &key, Upgrader &upgrader)
Return a pointer to the value stored under key, and NULL if key is not a key in the map.
bool CreateAlias(const std::string &alias, const std::type_info &key)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool Exists(const std::string &key) const
Return true if the given key is present in the map.
bool CreateAlias(const std::string &alias, const std::string &key)
Create an alias for a key.