24 #ifndef PXR_BASE_TF_TYPE_INFO_MAP_H
25 #define PXR_BASE_TF_TYPE_INFO_MAP_H
36 #include <boost/noncopyable.hpp>
37 #include "pxr/base/tf/hashmap.h"
43 PXR_NAMESPACE_OPEN_SCOPE
62 template <
class VALUE>
71 bool Exists(
const std::type_info& key)
const {
72 return Find(key) != NULL;
78 bool Exists(
const std::string& key)
const {
79 return Find(key) != NULL;
84 VALUE*
Find(
const std::type_info& key)
const {
85 typename _TypeInfoCache::const_iterator i = _typeInfoCache.find(&key);
86 if (i != _typeInfoCache.end())
87 return &i->second->value;
88 else if (VALUE* v =
Find(key.name())) {
99 template <
class Upgrader>
100 VALUE*
Find(
const std::type_info& key, Upgrader& upgrader) {
101 typename _TypeInfoCache::const_iterator i = _typeInfoCache.find(&key);
102 if (i != _typeInfoCache.end())
103 return &i->second->value;
104 else if (VALUE* v =
Find(key.name())) {
106 _CreateAlias(key, key.name());
116 VALUE*
Find(
const std::string& key)
const {
117 typename _StringCache::const_iterator i = _stringCache.find(key);
118 return (i == _stringCache.end()) ? NULL : &i->second->value;
127 void Set(
const std::type_info& key,
const VALUE& value) {
128 if (VALUE* v =
Find(key))
131 Set(key.name(), value);
132 _CreateAlias(key, key.name());
141 void Set(
const std::string& key,
const VALUE& value) {
142 typename _StringCache::iterator i = _stringCache.find(key);
144 if (i != _stringCache.end())
145 i->second->value = value;
147 _Entry* e = &_nameMap[key];
151 _stringCache[key] = e;
152 e->stringAliases.push_back(key);
163 bool CreateAlias(
const std::string& alias,
const std::string& key) {
164 typename _StringCache::iterator i = _stringCache.find(key);
165 if (i != _stringCache.end())
166 return (_CreateAlias(alias, i->second),
true);
172 bool CreateAlias(
const std::string& alias,
const std::type_info& key) {
173 typename _TypeInfoCache::iterator i = _typeInfoCache.find(&key);
174 if (i != _typeInfoCache.end())
175 return (_CreateAlias(alias, i->second),
true);
187 typename _StringCache::iterator i = _stringCache.find(key);
188 if (i == _stringCache.end())
191 _Entry* e = i->second;
194 _typeInfoCache.erase(*j);
197 for (
TfIterator<std::list<std::string> > j = e->stringAliases; j; ++j) {
198 _stringCache.erase(*j);
201 _nameMap.erase(e->primaryKey);
205 typedef std::list<const std::type_info*> _TypeInfoList;
208 mutable _TypeInfoList typeInfoAliases;
209 mutable std::list<std::string> stringAliases;
210 std::string primaryKey;
214 void _CreateAlias(
const std::type_info& alias,
const std::string& key) {
215 typename _StringCache::iterator i = _stringCache.find(key);
216 if (i != _stringCache.end())
217 _CreateAlias(alias, i->second);
220 void _CreateAlias(
const std::type_info& alias, _Entry* e) {
221 if (_typeInfoCache.find(&alias) == _typeInfoCache.end()) {
222 _typeInfoCache[&alias] = e;
223 e->typeInfoAliases.push_back(&alias);
227 void _CreateAlias(
const std::string& alias, _Entry* e) {
228 if (_stringCache.find(alias) == _stringCache.end()) {
229 _stringCache[alias] = e;
230 e->stringAliases.push_back(alias);
234 typedef TfHashMap<std::string, _Entry, TfHash> _NameMap;
235 typedef TfHashMap<const std::type_info*, _Entry*, TfHash>
237 typedef TfHashMap<std::string, _Entry*, TfHash> _StringCache;
241 _TypeInfoCache _typeInfoCache;
242 _StringCache _stringCache;
245 PXR_NAMESPACE_CLOSE_SCOPE
247 #endif // PXR_BASE_TF_TYPE_INFO_MAP_H
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...
A simple iterator adapter for STL containers.
bool Exists(const std::type_info &key) const
Return true if the given key is present in the map.
void Remove(const std::type_info &key)
Remove this key (and any aliases associated with it).
A map whose key is a const std::type_info&, or a string alias.
void Remove(const std::string &key)
Remove this key (and any aliases associated with it).
void Set(const std::string &key, const VALUE &value)
Set the value for a given key.
void Set(const std::type_info &key, const VALUE &value)
Set the value for a given key.
A simple iterator adapter for STL containers.
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...
bool CreateAlias(const std::string &alias, const std::string &key)
Create an alias for a 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...
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::type_info &key)
void if(!TfPyIsInitialized())
Invokes wrapFunc to wrap type T if T is not already wrapped.