7#ifndef PXR_BASE_TF_TYPE_INFO_MAP_H
8#define PXR_BASE_TF_TYPE_INFO_MAP_H
19#include "pxr/base/tf/hashmap.h"
25PXR_NAMESPACE_OPEN_SCOPE
55 bool Exists(
const std::type_info& key)
const {
56 return Find(key) != NULL;
62 bool Exists(
const std::string& key)
const {
63 return Find(key) != NULL;
68 VALUE*
Find(
const std::type_info& key)
const {
69 typename _TypeInfoCache::const_iterator i = _typeInfoCache.find(&key);
70 if (i != _typeInfoCache.end())
71 return &i->second->value;
72 else if (VALUE* v =
Find(key.name())) {
83 template <
class Upgrader>
84 VALUE*
Find(
const std::type_info& key, Upgrader& upgrader) {
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())) {
90 _CreateAlias(key, key.name());
100 VALUE*
Find(
const std::string& key)
const {
101 typename _StringCache::const_iterator i = _stringCache.find(key);
102 return (i == _stringCache.end()) ? NULL : &i->second->value;
111 void Set(
const std::type_info& key,
const VALUE& value) {
112 if (VALUE* v =
Find(key))
115 Set(key.name(), value);
116 _CreateAlias(key, key.name());
125 void Set(
const std::string& key,
const VALUE& value) {
126 typename _StringCache::iterator i = _stringCache.find(key);
128 if (i != _stringCache.end())
129 i->second->value = value;
131 _Entry* e = &_nameMap[key];
135 _stringCache[key] = e;
136 e->stringAliases.push_back(key);
147 bool CreateAlias(
const std::string& alias,
const std::string& key) {
148 typename _StringCache::iterator i = _stringCache.find(key);
149 if (i != _stringCache.end())
150 return (_CreateAlias(alias, i->second),
true);
156 bool CreateAlias(
const std::string& alias,
const std::type_info& key) {
157 typename _TypeInfoCache::iterator i = _typeInfoCache.find(&key);
158 if (i != _typeInfoCache.end())
159 return (_CreateAlias(alias, i->second),
true);
171 typename _StringCache::iterator i = _stringCache.find(key);
172 if (i == _stringCache.end())
175 _Entry* e = i->second;
178 _typeInfoCache.erase(*j);
181 for (
TfIterator<std::list<std::string> > j = e->stringAliases; j; ++j) {
182 _stringCache.erase(*j);
190 const std::string primaryKey = std::move(e->primaryKey);
191 _nameMap.erase(primaryKey);
195 typedef std::list<const std::type_info*> _TypeInfoList;
198 mutable _TypeInfoList typeInfoAliases;
199 mutable std::list<std::string> stringAliases;
200 std::string primaryKey;
204 void _CreateAlias(
const std::type_info& alias,
const std::string& key) {
205 typename _StringCache::iterator i = _stringCache.find(key);
206 if (i != _stringCache.end())
207 _CreateAlias(alias, i->second);
210 void _CreateAlias(
const std::type_info& alias, _Entry* e) {
211 if (_typeInfoCache.find(&alias) == _typeInfoCache.end()) {
212 _typeInfoCache[&alias] = e;
213 e->typeInfoAliases.push_back(&alias);
217 void _CreateAlias(
const std::string& alias, _Entry* e) {
218 if (_stringCache.find(alias) == _stringCache.end()) {
219 _stringCache[alias] = e;
220 e->stringAliases.push_back(alias);
224 typedef TfHashMap<std::string, _Entry, TfHash> _NameMap;
225 typedef TfHashMap<const std::type_info*, _Entry*, TfHash>
227 typedef TfHashMap<std::string, _Entry*, TfHash> _StringCache;
231 _TypeInfoCache _typeInfoCache;
232 _StringCache _stringCache;
235PXR_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.