24 #ifndef PXR_USD_SDF_ACCESSOR_HELPERS_H
25 #define PXR_USD_SDF_ACCESSOR_HELPERS_H
34 #include <type_traits>
57 #define _GET_KEY_(key_) key_
58 #define SDF_NO_PREDICATE true
60 #define _GET_WITH_FALLBACK(key_, heldType_) \
62 typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
63 const VtValue& value = _Helper::GetField(this, key_); \
64 if (value.IsEmpty() || !value.IsHolding<heldType_>()) { \
65 const SdfSchemaBase& schema = _Helper::GetSchema(this); \
66 return schema.GetFallback(_GET_KEY_(key_)).Get<heldType_>(); \
69 return value.Get<heldType_>(); \
76 #define SDF_DEFINE_GET(name_, key_, heldType_) \
78 SDF_ACCESSOR_CLASS::Get ## name_() const \
80 if (SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_))) { \
84 _GET_WITH_FALLBACK(key_, heldType_); \
87 #define SDF_DEFINE_IS(name_, key_) \
89 SDF_ACCESSOR_CLASS::Is ## name_() const \
91 if (!SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_))) { \
95 _GET_WITH_FALLBACK(key_, bool); \
98 #define SDF_DEFINE_SET(name_, key_, argType_) \
100 SDF_ACCESSOR_CLASS::Set ## name_(argType_ value) \
102 if (SDF_ACCESSOR_WRITE_PREDICATE(_GET_KEY_(key_))) { \
103 typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
104 _Helper::SetField(this, _GET_KEY_(key_), value); \
108 #define SDF_DEFINE_HAS(name_, key_) \
110 SDF_ACCESSOR_CLASS::Has ## name_() const \
112 typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
113 return SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_)) ? \
114 _Helper::HasField(this, _GET_KEY_(key_)) : false; \
117 #define SDF_DEFINE_CLEAR(name_, key_) \
119 SDF_ACCESSOR_CLASS::Clear ## name_() \
121 typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
122 if (SDF_ACCESSOR_WRITE_PREDICATE(_GET_KEY_(key_))) { \
123 _Helper::ClearField(this, _GET_KEY_(key_)); \
130 #define SDF_DEFINE_GET_PRIVATE(name_, key_, heldType_) \
132 SDF_ACCESSOR_CLASS::_Get ## name_() const \
134 if (SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_))) { \
138 _GET_WITH_FALLBACK(key_, heldType_); \
144 #define SDF_DEFINE_DICTIONARY_GET(name_, key_) \
146 SDF_ACCESSOR_CLASS::name_() const \
148 typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
149 return SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_)) ? \
150 SdfDictionaryProxy(_Helper::GetSpecHandle(this), _GET_KEY_(key_)) : \
151 SdfDictionaryProxy(); \
154 #define SDF_DEFINE_DICTIONARY_SET(name_, key_) \
156 SDF_ACCESSOR_CLASS::name_( \
157 const std::string& name, \
158 const VtValue& value) \
160 typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
161 if (SDF_ACCESSOR_WRITE_PREDICATE(_GET_KEY_(key_))) { \
162 SdfDictionaryProxy proxy( \
163 _Helper::GetSpecHandle(this), _GET_KEY_(key_)); \
164 if (value.IsEmpty()) { \
168 proxy[name] = value; \
177 template <
typename T>
180 std::add_lvalue_reference_t<std::add_const_t<T>>>;
182 #define SDF_DEFINE_TYPED_GET_SET(name_, key_, getType_, setType_) \
183 SDF_DEFINE_GET(name_, key_, getType_) \
184 SDF_DEFINE_SET(name_, key_, setType_)
186 #define SDF_DEFINE_TYPED_GET_SET_HAS_CLEAR(name_, key_, getType_, setType_) \
187 SDF_DEFINE_TYPED_GET_SET(name_, key_, getType_, setType_) \
188 SDF_DEFINE_HAS(name_, key_) \
189 SDF_DEFINE_CLEAR(name_, key_)
191 #define SDF_DEFINE_GET_SET(name_, key_, type_) \
192 SDF_DEFINE_TYPED_GET_SET(name_, key_, type_, \
193 Sdf_SetParameter<type_>::type)
195 #define SDF_DEFINE_GET_SET_HAS_CLEAR(name_, key_, type_) \
196 SDF_DEFINE_TYPED_GET_SET_HAS_CLEAR(name_, key_, type_, \
197 Sdf_SetParameter<type_>::type)
199 #define SDF_DEFINE_IS_SET(name_, key_) \
200 SDF_DEFINE_IS(name_, key_) \
201 SDF_DEFINE_SET(name_, key_, bool)
203 #define SDF_DEFINE_DICTIONARY_GET_SET(getName_, setName_, key_) \
204 SDF_DEFINE_DICTIONARY_GET(getName_, key_) \
205 SDF_DEFINE_DICTIONARY_SET(setName_, key_)
222 {
return spec->GetSchema(); }
225 {
return spec->GetField(key); }
229 {
return spec->SetField(key, value); }
232 {
return spec->HasField(key); }
235 { spec->ClearField(key); }
245 {
return spec->_GetSpec().GetSchema(); }
248 {
return spec->_GetSpec().GetField(key); }
252 {
return spec->_GetSpec().SetField(key, value); }
255 {
return spec->_GetSpec().HasField(key); }
258 { spec->_GetSpec().ClearField(key); }
266 #endif // #ifndef PXR_USD_SDF_ACCESSOR_HELPERS_H
static SdfSpecHandle GetSpecHandle(const T *spec)
static VtValue GetField(const T *spec, const TfToken &key)
static bool HasField(const T *spec, const TfToken &key)
static const SdfSchemaBase & GetSchema(const T *spec)
GLsizei const GLfloat * value
static void ClearField(T *spec, const TfToken &key)
static void ClearField(T *spec, const TfToken &key)
static VtValue GetField(const T *spec, const TfToken &key)
static bool SetField(T *spec, const TfToken &key, const V &value)
static SdfSpecHandle GetSpecHandle(const T *spec)
static bool SetField(T *spec, const TfToken &key, const V &value)
static bool HasField(const T *spec, const TfToken &key)
static const SdfSchemaBase & GetSchema(const T *spec)
std::conditional< std::is_arithmetic< T >::value, std::add_const_t< T >, std::add_lvalue_reference_t< std::add_const_t< T >>> Sdf_SetParameter
SdfHandleTo< T >::Handle SdfCreateNonConstHandle(T const *p)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE