24 #ifndef PXR_BASE_VT_DICTIONARY_H
25 #define PXR_BASE_VT_DICTIONARY_H
35 #include "pxr/base/tf/mallocTag.h"
37 #include <hboost/functional/hash.hpp>
38 #include <hboost/iterator/iterator_adaptor.hpp>
40 #include <initializer_list>
64 typedef std::map<std::string, VtValue, std::less<>> _Map;
65 std::unique_ptr<_Map> _dictMap;
77 template<
class UnderlyingMapPtr,
class UnderlyingIterator>
78 class Iterator :
public hboost::iterator_adaptor<Iterator<UnderlyingMapPtr,
79 UnderlyingIterator>, UnderlyingIterator> {
84 :
Iterator::iterator_adaptor_(UnderlyingIterator())
85 , _underlyingMap(0) {}
88 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
90 OtherUnderlyingIterator>
const &other)
91 :
Iterator::iterator_adaptor_(other.base())
92 , _underlyingMap(other._underlyingMap) {}
97 Iterator(UnderlyingMapPtr
m, UnderlyingIterator i)
100 if (m && i == m->end())
107 UnderlyingIterator GetUnderlyingIterator(UnderlyingMapPtr map)
109 TF_AXIOM(!_underlyingMap || _underlyingMap == map);
110 return (!_underlyingMap) ? map->end() : this->base();
120 if (!_underlyingMap) {
122 "VtDictionary iterator");
125 if (++this->base_reference() == _underlyingMap->end()) {
137 template <
class OtherUnderlyingMapPtr,
class OtherUnderlyingIterator>
139 OtherUnderlyingIterator>
const& i)
const {
140 if (_underlyingMap == i._underlyingMap)
141 if (!_underlyingMap || this->base() == i.base())
146 UnderlyingMapPtr _underlyingMap;
167 template<
class _InputIterator>
169 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::VtDictionary (range)");
280 template<
class _InputIterator>
282 TfAutoMallocTag2 tag(
"Vt",
"VtDictionary::insert (range)");
284 _CreateDictIfNeeded();
285 _dictMap->insert(f, l);
301 char const *delimiters =
":")
const;
335 char const *delimiters =
":");
345 _SetValueAtPathImpl(std::vector<std::string>::const_iterator curKeyElem,
346 std::vector<std::string>::const_iterator keyElemEnd,
349 void _EraseValueAtPathImpl(
350 std::vector<std::string>::const_iterator curKeyElem,
351 std::vector<std::string>::const_iterator keyElemEnd);
353 void _CreateDictIfNeeded();
374 template <
typename T>
380 if ( i == dictionary.
end() ) {
384 return i->second.IsHolding<
T>();
388 template <
typename T>
394 if ( i == dictionary.
end() ) {
398 return i->second.IsHolding<
T>();
412 template <
typename T>
420 "', which is not in the dictionary.");
423 return i->second.Get<
T>();
427 template <
typename T>
435 "which is not in the dictionary.", key);
438 return i->second.Get<
T>();
476 template <
class T,
class U>
482 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
484 return i->second.UncheckedGet<
T>();
488 template <
class T,
class U>
494 if (i == dictionary.
end() || !i->second.IsHolding<
T>())
496 return i->second.UncheckedGet<
T>();
514 bool coerceToWeakerOpinionType =
false);
529 bool coerceToWeakerOpinionType =
false);
544 bool coerceToWeakerOpinionType =
false);
566 bool coerceToWeakerOpinionType =
false);
587 bool coerceToWeakerOpinionType =
false);
611 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)
VT_API VtValue & operator[](const std::string &key)
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.
GLsizei const GLchar *const * string
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=":")
GLsizei const GLfloat * value
bool equal(T1 a, T2 b, T3 t)
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)