7#ifndef PXR_USD_SDF_MAP_EDITOR_H
8#define PXR_USD_SDF_MAP_EDITOR_H
14#include "pxr/base/vt/value.h"
22PXR_NAMESPACE_OPEN_SCOPE
31class Sdf_MapEditorBase {
35 SDF_API std::string GetLocation()
const;
38 SDF_API SdfSpecHandle GetOwner()
const;
41 SDF_API
bool IsExpired()
const;
44 SDF_API Sdf_MapEditorBase(
const SdfSpecHandle& owner,
const TfToken& field);
48 SDF_API
void _WriteToSpec(
const VtValueRef& value);
58template <
class MapType>
59class Sdf_MapEditor :
public Sdf_MapEditorBase {
61 typedef typename MapType::key_type key_type;
62 typedef typename MapType::mapped_type mapped_type;
63 typedef typename MapType::value_type value_type;
64 typedef typename MapType::iterator iterator;
66 Sdf_MapEditor(
const SdfSpecHandle& owner,
const TfToken& field)
67 : Sdf_MapEditorBase(owner, field)
69 const VtValue& dataVal = _owner->GetField(_field);
71 if (dataVal.IsHolding<MapType>()) {
72 _data = dataVal.Get<MapType>();
75 TF_CODING_ERROR(
"%s does not hold value of expected type.",
76 GetLocation().c_str());
81 const MapType* GetData()
const {
return &_data; }
82 MapType* GetData() {
return &_data; }
87 void Copy(
const MapType& other)
93 void Set(
const key_type& key,
const mapped_type& other)
99 std::pair<iterator, bool> Insert(
const value_type& value)
101 const std::pair<iterator, bool> insertStatus = _data.insert(value);
102 if (insertStatus.second) {
108 bool Erase(
const key_type& key)
110 const bool didErase = (_data.erase(key) != 0);
117 SdfAllowed IsValidKey(
const key_type& key)
const
122 SdfAllowed IsValidValue(
const mapped_type& value)
const
130 void _UpdateDataInSpec()
139std::unique_ptr<Sdf_MapEditor<T>>
140Sdf_CreateMapEditor(
const SdfSpecHandle& owner,
const TfToken& field)
142 return std::make_unique<Sdf_MapEditor<T>>(owner, field);
145PXR_NAMESPACE_CLOSE_SCOPE
Indicates if an operation is allowed and, if not, why not.
Token for efficient comparison, assignment, and hashing of known strings.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
bool IsEmpty() const
Returns true iff this value is empty.
A non-owning type-erased view of a value, interoperating with VtValue.
Stripped down version of diagnostic.h that doesn't define std::string.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...