7 #ifndef PXR_BASE_VT_DICTIONARY_H
8 #define PXR_BASE_VT_DICTIONARY_H
20 #include "pxr/base/tf/mallocTag.h"
22 #include <initializer_list>
53 typedef std::map<std::string, VtValue, std::less<>> _Map;
54 std::unique_ptr<_Map> _dictMap;
66 template<
class UnderlyingMapPtr,
class UnderlyingIterator>
81 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
83 OtherUnderlyingIterator>
const &other)
84 : _underlyingIterator(other._underlyingIterator),
85 _underlyingMap(other._underlyingMap) {}
102 --_underlyingIterator;
108 --_underlyingIterator;
112 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
114 OtherUnderlyingIterator>& other)
const {
118 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
120 OtherUnderlyingIterator>& other)
const {
121 return !equal(other);
128 Iterator(UnderlyingMapPtr m, UnderlyingIterator i)
129 : _underlyingIterator(i),
131 if (m && i == m->end())
132 _underlyingMap =
nullptr;
137 UnderlyingIterator GetUnderlyingIterator(UnderlyingMapPtr map)
139 TF_AXIOM(!_underlyingMap || _underlyingMap == map);
140 return (!_underlyingMap) ? map->end() : _underlyingIterator;
150 if (!_underlyingMap) {
152 "VtDictionary iterator");
155 if (++_underlyingIterator == _underlyingMap->end()) {
156 _underlyingMap =
nullptr;
167 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
169 OtherUnderlyingIterator>
const& other)
const {
170 if (_underlyingMap == other._underlyingMap)
171 if (!_underlyingMap ||
172 (_underlyingIterator == other._underlyingIterator))
177 UnderlyingIterator _underlyingIterator;
178 UnderlyingMapPtr _underlyingMap =
nullptr;
199 template<
class _InputIterator>
201 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::VtDictionary (range)");
308 return TfHash()(*dict._dictMap);
312 template<
class _InputIterator>
313 void insert(_InputIterator
f, _InputIterator l) {
314 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::insert (range)");
316 _CreateDictIfNeeded();
317 _dictMap->insert(f, l);
333 char const *delimiters =
":")
const;
367 char const *delimiters =
":");
377 _SetValueAtPathImpl(std::vector<std::string>::const_iterator curKeyElem,
378 std::vector<std::string>::const_iterator keyElemEnd,
381 void _EraseValueAtPathImpl(
382 std::vector<std::string>::const_iterator curKeyElem,
383 std::vector<std::string>::const_iterator keyElemEnd);
385 void _CreateDictIfNeeded();
406 template <
typename T>
409 const std::string &key )
412 if ( i == dictionary.
end() ) {
416 return i->second.IsHolding<
T>();
420 template <
typename T>
426 if ( i == dictionary.
end() ) {
430 return i->second.IsHolding<
T>();
444 template <
typename T>
447 const std::string &key )
452 "', which is not in the dictionary.");
455 return i->second.Get<
T>();
459 template <
typename T>
467 "which is not in the dictionary.", key);
470 return i->second.Get<
T>();
508 template <
class T,
class U>
510 const std::string &key,
514 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
516 return i->second.UncheckedGet<
T>();
520 template <
class T,
class U>
526 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
528 return i->second.UncheckedGet<
T>();
546 bool coerceToWeakerOpinionType =
false);
561 bool coerceToWeakerOpinionType =
false);
576 bool coerceToWeakerOpinionType =
false);
VT_API size_type erase(const std::string &key)
Erases the element whose key is key.
VT_API VtDictionary const & VtGetEmptyDictionary()
VtDictionary(_InputIterator f, _InputIterator l)
Creates a VtDictionary with a copy of a range.
Iterator(Iterator< OtherUnderlyingMapPtr, OtherUnderlyingIterator > const &other)
#define PXR_NAMESPACE_OPEN_SCOPE
bool operator!=(const Iterator< OtherUnderlyingMapPtr, OtherUnderlyingIterator > &other) const
GLsizei const GLfloat * value
bool operator==(const Iterator< OtherUnderlyingMapPtr, OtherUnderlyingIterator > &other) const
VT_API VtValue & operator[](const std::string &key)
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
friend size_t hash_value(VtDictionary const &dict)
**But if you need a result
VtDictionary()
Creates an empty VtDictionary.
_Map::allocator_type allocator_type
const T & VtDictionaryGet(const VtDictionary &dictionary, const std::string &key)
VT_VALUE_TYPE_CAN_COMPOSE(VtDictionary)
pointer operator->() const
typename UnderlyingIterator::reference reference
Vt_DefaultHolder(T const &t)
TF_MALLOC_TAG_NEW("Vt","VtDictionary")
reference operator*() const
Iterator< _Map *, _Map::iterator > iterator
VT_API iterator find(const std::string &key)
Finds an element whose key is key.
typename UnderlyingIterator::value_type value_type
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
VT_API std::ostream & operator<<(std::ostream &, VtDictionary const &)
VT_API bool empty() const
true if the VtDictionary's size is 0.
VT_API VtDictionary VtDictionaryOverRecursive(const VtDictionary &strong, const VtDictionary &weak)
VT_VALUE_TYPE_CAN_TRANSFORM(VtDictionary)
void insert(_InputIterator f, _InputIterator l)
Inserts a range into the VtDictionary.
VT_API VtDictionary VtDictionaryOver(const VtDictionary &strong, const VtDictionary &weak, bool coerceToWeakerOpinionType=false)
size_t operator()(VtDictionary const &dict) const
Vt_DefaultHolder< T > operator=(T const &t)
VT_API void clear()
Erases all of the elements.
std::bidirectional_iterator_tag iterator_category
VT_API iterator begin()
Returns an iterator pointing to the beginning of the VtDictionary.
typename UnderlyingIterator::pointer pointer
Iterator< _Map const *, _Map::const_iterator > const_iterator
VT_API VtDictionary & operator=(VtDictionary const &other)
Copy assignment operator.
friend void swap(VtDictionary &lhs, VtDictionary &rhs)
#define PXR_NAMESPACE_CLOSE_SCOPE
VT_API void EraseValueAtPath(std::string const &keyPath, char const *delimiters=":")
VT_API size_type count(const std::string &key) const
Counts the number of elements whose key is key.
VT_API iterator end()
Returns an iterator pointing to the end of the VtDictionary.
_Map::mapped_type mapped_type
VT_API void SetValueAtPath(std::string const &keyPath, VtValue const &value, char const *delimiters=":")
VT_API void swap(VtDictionary &dict)
Swaps the contents of two VtDictionaries.
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate and *a name There is also one special expression reference
VT_API size_type size() const
Returns the size of the VtDictionary.
size_t hash_value(const CH_ChannelRef &ref)
_Map::value_type value_type
typename UnderlyingIterator::difference_type difference_type
VT_API Vt_DefaultGenerator VtDefault
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
_Map::size_type size_type
VT_API VtValue const * GetValueAtPath(std::string const &keyPath, char const *delimiters=":") const
VtDictionary(int size)
Creates an empty VtDictionary with at least size buckets.
bool VtDictionaryIsHolding(const VtDictionary &dictionary, const std::string &key)