24 #ifndef PXR_BASE_VT_DICTIONARY_H
25 #define PXR_BASE_VT_DICTIONARY_H
35 #include "pxr/base/tf/mallocTag.h"
37 #include <hboost/iterator/iterator_adaptor.hpp>
39 #include <initializer_list>
63 typedef std::map<std::string, VtValue, std::less<>> _Map;
64 std::unique_ptr<_Map> _dictMap;
76 template<
class UnderlyingMapPtr,
class UnderlyingIterator>
77 class Iterator :
public hboost::iterator_adaptor<Iterator<UnderlyingMapPtr,
78 UnderlyingIterator>, UnderlyingIterator> {
83 :
Iterator::iterator_adaptor_(UnderlyingIterator())
84 , _underlyingMap(0) {}
87 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
89 OtherUnderlyingIterator>
const &other)
90 :
Iterator::iterator_adaptor_(other.base())
91 , _underlyingMap(other._underlyingMap) {}
96 Iterator(UnderlyingMapPtr m, UnderlyingIterator i)
99 if (m && i == m->end())
106 UnderlyingIterator GetUnderlyingIterator(UnderlyingMapPtr map)
108 TF_AXIOM(!_underlyingMap || _underlyingMap == map);
109 return (!_underlyingMap) ? map->end() : this->base();
119 if (!_underlyingMap) {
121 "VtDictionary iterator");
124 if (++this->base_reference() == _underlyingMap->end()) {
136 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
138 OtherUnderlyingIterator>
const& i)
const {
139 if (_underlyingMap == i._underlyingMap)
140 if (!_underlyingMap || this->base() == i.base())
145 UnderlyingMapPtr _underlyingMap;
166 template<
class _InputIterator>
168 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::VtDictionary (range)");
275 return TfHash()(*dict._dictMap);
279 template<
class _InputIterator>
280 void insert(_InputIterator
f, _InputIterator l) {
281 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::insert (range)");
283 _CreateDictIfNeeded();
284 _dictMap->insert(f, l);
300 char const *delimiters =
":")
const;
334 char const *delimiters =
":");
344 _SetValueAtPathImpl(std::vector<std::string>::const_iterator curKeyElem,
345 std::vector<std::string>::const_iterator keyElemEnd,
348 void _EraseValueAtPathImpl(
349 std::vector<std::string>::const_iterator curKeyElem,
350 std::vector<std::string>::const_iterator keyElemEnd);
352 void _CreateDictIfNeeded();
373 template <
typename T>
379 if ( i == dictionary.
end() ) {
383 return i->second.IsHolding<
T>();
387 template <
typename T>
393 if ( i == dictionary.
end() ) {
397 return i->second.IsHolding<
T>();
411 template <
typename T>
419 "', which is not in the dictionary.");
422 return i->second.Get<
T>();
426 template <
typename T>
434 "which is not in the dictionary.", key);
437 return i->second.Get<
T>();
475 template <
class T,
class U>
481 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
483 return i->second.UncheckedGet<
T>();
487 template <
class T,
class U>
493 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
495 return i->second.UncheckedGet<
T>();
513 bool coerceToWeakerOpinionType =
false);
528 bool coerceToWeakerOpinionType =
false);
543 bool coerceToWeakerOpinionType =
false);
565 bool coerceToWeakerOpinionType =
false);
586 bool coerceToWeakerOpinionType =
false);
610 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)
GLsizei const GLchar *const * string
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)
VtDictionary()
Creates an empty VtDictionary.
_Map::allocator_type allocator_type
const T & VtDictionaryGet(const VtDictionary &dictionary, const std::string &key)
Vt_DefaultHolder(T const &t)
TF_MALLOC_TAG_NEW("Vt","VtDictionary")
Iterator< _Map *, _Map::iterator > iterator
VT_API iterator find(const std::string &key)
Finds an element whose key is key.
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.
friend class hboost::iterator_core_access
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.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
VT_API iterator begin()
Returns an iterator pointing to the beginning of the VtDictionary.
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.
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
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)