7 #ifndef PXR_BASE_VT_DICTIONARY_H
8 #define PXR_BASE_VT_DICTIONARY_H
18 #include "pxr/base/tf/mallocTag.h"
20 #include <initializer_list>
44 typedef std::map<std::string, VtValue, std::less<>> _Map;
45 std::unique_ptr<_Map> _dictMap;
57 template<
class UnderlyingMapPtr,
class UnderlyingIterator>
72 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
74 OtherUnderlyingIterator>
const &other)
75 : _underlyingIterator(other._underlyingIterator),
76 _underlyingMap(other._underlyingMap) {}
93 --_underlyingIterator;
99 --_underlyingIterator;
103 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
105 OtherUnderlyingIterator>& other)
const {
109 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
111 OtherUnderlyingIterator>& other)
const {
112 return !equal(other);
119 Iterator(UnderlyingMapPtr m, UnderlyingIterator i)
120 : _underlyingIterator(i),
122 if (m && i == m->end())
123 _underlyingMap =
nullptr;
128 UnderlyingIterator GetUnderlyingIterator(UnderlyingMapPtr map)
130 TF_AXIOM(!_underlyingMap || _underlyingMap == map);
131 return (!_underlyingMap) ? map->end() : _underlyingIterator;
141 if (!_underlyingMap) {
143 "VtDictionary iterator");
146 if (++_underlyingIterator == _underlyingMap->end()) {
147 _underlyingMap =
nullptr;
158 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
160 OtherUnderlyingIterator>
const& other)
const {
161 if (_underlyingMap == other._underlyingMap)
162 if (!_underlyingMap ||
163 (_underlyingIterator == other._underlyingIterator))
168 UnderlyingIterator _underlyingIterator;
169 UnderlyingMapPtr _underlyingMap =
nullptr;
190 template<
class _InputIterator>
192 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::VtDictionary (range)");
299 return TfHash()(*dict._dictMap);
303 template<
class _InputIterator>
304 void insert(_InputIterator
f, _InputIterator l) {
305 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::insert (range)");
307 _CreateDictIfNeeded();
308 _dictMap->insert(f, l);
324 char const *delimiters =
":")
const;
358 char const *delimiters =
":");
368 _SetValueAtPathImpl(std::vector<std::string>::const_iterator curKeyElem,
369 std::vector<std::string>::const_iterator keyElemEnd,
372 void _EraseValueAtPathImpl(
373 std::vector<std::string>::const_iterator curKeyElem,
374 std::vector<std::string>::const_iterator keyElemEnd);
376 void _CreateDictIfNeeded();
397 template <
typename T>
400 const std::string &key )
403 if ( i == dictionary.
end() ) {
407 return i->second.IsHolding<
T>();
411 template <
typename T>
417 if ( i == dictionary.
end() ) {
421 return i->second.IsHolding<
T>();
435 template <
typename T>
438 const std::string &key )
443 "', which is not in the dictionary.");
446 return i->second.Get<
T>();
450 template <
typename T>
458 "which is not in the dictionary.", key);
461 return i->second.Get<
T>();
499 template <
class T,
class U>
501 const std::string &key,
505 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
507 return i->second.UncheckedGet<
T>();
511 template <
class T,
class U>
517 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
519 return i->second.UncheckedGet<
T>();
537 bool coerceToWeakerOpinionType =
false);
552 bool coerceToWeakerOpinionType =
false);
567 bool coerceToWeakerOpinionType =
false);
589 bool coerceToWeakerOpinionType =
false);
610 bool coerceToWeakerOpinionType =
false);
634 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)
VT_API VtDictionary VtDictionaryOverRecursive(const VtDictionary &strong, const VtDictionary &weak, bool coerceToWeakerOpinionType=false)
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)
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.
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
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
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)