24 #ifndef PXR_BASE_VT_DICTIONARY_H
25 #define PXR_BASE_VT_DICTIONARY_H
35 #include "pxr/base/tf/mallocTag.h"
37 #include <initializer_list>
61 typedef std::map<std::string, VtValue, std::less<>> _Map;
62 std::unique_ptr<_Map> _dictMap;
74 template<
class UnderlyingMapPtr,
class UnderlyingIterator>
89 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
91 OtherUnderlyingIterator>
const &other)
92 : _underlyingIterator(other._underlyingIterator),
93 _underlyingMap(other._underlyingMap) {}
110 --_underlyingIterator;
116 --_underlyingIterator;
120 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
122 OtherUnderlyingIterator>& other)
const {
126 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
128 OtherUnderlyingIterator>& other)
const {
129 return !equal(other);
136 Iterator(UnderlyingMapPtr m, UnderlyingIterator i)
137 : _underlyingIterator(i),
139 if (m && i == m->end())
140 _underlyingMap =
nullptr;
145 UnderlyingIterator GetUnderlyingIterator(UnderlyingMapPtr map)
147 TF_AXIOM(!_underlyingMap || _underlyingMap == map);
148 return (!_underlyingMap) ? map->end() : _underlyingIterator;
158 if (!_underlyingMap) {
160 "VtDictionary iterator");
163 if (++_underlyingIterator == _underlyingMap->end()) {
164 _underlyingMap =
nullptr;
175 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
177 OtherUnderlyingIterator>
const& other)
const {
178 if (_underlyingMap == other._underlyingMap)
179 if (!_underlyingMap ||
180 (_underlyingIterator == other._underlyingIterator))
185 UnderlyingIterator _underlyingIterator;
186 UnderlyingMapPtr _underlyingMap =
nullptr;
207 template<
class _InputIterator>
209 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::VtDictionary (range)");
316 return TfHash()(*dict._dictMap);
320 template<
class _InputIterator>
321 void insert(_InputIterator
f, _InputIterator l) {
322 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::insert (range)");
324 _CreateDictIfNeeded();
325 _dictMap->insert(f, l);
341 char const *delimiters =
":")
const;
375 char const *delimiters =
":");
385 _SetValueAtPathImpl(std::vector<std::string>::const_iterator curKeyElem,
386 std::vector<std::string>::const_iterator keyElemEnd,
389 void _EraseValueAtPathImpl(
390 std::vector<std::string>::const_iterator curKeyElem,
391 std::vector<std::string>::const_iterator keyElemEnd);
393 void _CreateDictIfNeeded();
414 template <
typename T>
420 if ( i == dictionary.
end() ) {
424 return i->second.IsHolding<
T>();
428 template <
typename T>
434 if ( i == dictionary.
end() ) {
438 return i->second.IsHolding<
T>();
452 template <
typename T>
460 "', which is not in the dictionary.");
463 return i->second.Get<
T>();
467 template <
typename T>
475 "which is not in the dictionary.", key);
478 return i->second.Get<
T>();
516 template <
class T,
class U>
522 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
524 return i->second.UncheckedGet<
T>();
528 template <
class T,
class U>
534 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
536 return i->second.UncheckedGet<
T>();
554 bool coerceToWeakerOpinionType =
false);
569 bool coerceToWeakerOpinionType =
false);
584 bool coerceToWeakerOpinionType =
false);
606 bool coerceToWeakerOpinionType =
false);
627 bool coerceToWeakerOpinionType =
false);
651 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 GLchar *const * string
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)