7#ifndef PXR_USD_SDF_ABSTRACT_DATA_H
8#define PXR_USD_SDF_ABSTRACT_DATA_H
11#include "pxr/usd/sdf/path.h"
14#include "pxr/base/vt/value.h"
26PXR_NAMESPACE_OPEN_SCOPE
34#define SDF_DATA_TOKENS \
35 ((TimeSamples, "timeSamples"))
69 virtual void CopyFrom(
const SdfAbstractDataConstPtr& source);
117 virtual bool Equals(
const SdfAbstractDataRefPtr &rhs)
const;
176 VtValue *value = NULL)
const = 0;
212 const TfToken& fieldName)
const = 0;
223 virtual std::type_info
const &
254 const T& defaultValue = T())
const;
268 virtual bool HasDictKey(
const SdfPath& path,
273 virtual bool HasDictKey(
const SdfPath& path,
290 virtual void SetDictValueByKey(
const SdfPath& path,
295 virtual void SetDictValueByKey(
const SdfPath& path,
304 virtual void EraseDictValueByKey(
const SdfPath& path,
312 virtual std::vector<TfToken> ListDictKeys(
const SdfPath& path,
331 virtual std::set<double>
332 ListAllTimeSamples()
const = 0;
335 virtual std::set<double>
336 ListTimeSamplesForPath(
const SdfPath& path)
const = 0;
340 GetBracketingTimeSamples(
double time,
double* tLower,
341 double* tUpper)
const = 0;
345 GetNumTimeSamplesForPath(
const SdfPath& path)
const = 0;
349 GetBracketingTimeSamplesForPath(
const SdfPath& path,
351 double* tLower,
double* tUpper)
const = 0;
368 double* tPrevious)
const;
372 QueryTimeSample(
const SdfPath& path,
double time,
373 VtValue *optionalValue = NULL)
const = 0;
376 QueryTimeSample(
const SdfPath& path,
double time,
387 virtual const std::type_info &
392 SetTimeSample(
const SdfPath& path,
double time,
397 EraseTimeSample(
const SdfPath& path,
double time) = 0;
414 const TfToken& field,
const T& defaultVal)
const
432 bool StoreValue(T &&v)
435 using Type = std::remove_cv_t<std::remove_reference_t<T>>;
437 if constexpr (std::is_same_v<Type, VtValue>) {
438 return _StoreVtValue(std::forward<T>(v));
441 isValueBlock =
false;
442 isAnimationBlock =
false;
443 typeMismatch =
false;
444 if constexpr (std::is_same_v<Type, SdfValueBlock>) {
447 }
else if constexpr (std::is_same_v<Type, SdfAnimationBlock>) {
448 isAnimationBlock =
true;
452 *
static_cast<Type*
>(value) = std::forward<T>(v);
460 const std::type_info& valueType;
462 bool isAnimationBlock;
468 , valueType(valueType_)
469 , isValueBlock(
false)
470 , isAnimationBlock(
false)
471 , typeMismatch(
false)
475 virtual bool _StoreVtValue(
const VtValue& value) = 0;
476 virtual bool _StoreVtValue(
VtValue &&value) = 0;
501 T
const &_Get(
const VtValue &v) {
509 template <
class Value>
510 bool _StoreVtValueImpl(Value &&v) {
511 typeMismatch =
false;
512 isValueBlock =
false;
513 isAnimationBlock =
false;
514 if (ARCH_LIKELY(std::forward<Value>(v).
template IsHolding<T>())) {
515 *
static_cast<T*
>(value) = _Get(std::forward<Value>(v));
516 if constexpr (std::is_same_v<T, SdfValueBlock>) {
518 }
else if constexpr (std::is_same_v<T, SdfAnimationBlock>) {
519 isAnimationBlock =
true;
524 if (std::forward<Value>(v).
template IsHolding<SdfValueBlock>()) {
528 else if (std::forward<Value>(v).
template IsHolding<SdfAnimationBlock>())
530 isAnimationBlock =
true;
540 _StoreVtValue(
const VtValue& v)
override {
541 return _StoreVtValueImpl(v);
545 _StoreVtValue(
VtValue &&v)
override {
546 return _StoreVtValueImpl(v);
558 virtual bool GetValue(
VtValue* value)
const = 0;
560 template <
class T>
bool GetValue(T* v)
const
563 *v = *
static_cast<const T*
>(value);
569 virtual bool IsEqual(
const VtValue& value)
const = 0;
572 const std::type_info& valueType;
573 const bool isArrayEdit;
574 const std::type_info& elementValueType;
578 const std::type_info& valueType_,
579 const bool isArrayEdit_,
580 const std::type_info& elementValueType_)
582 , valueType(valueType_)
583 , isArrayEdit(isArrayEdit_)
584 , elementValueType(elementValueType_)
606 static std::type_info
const &_GetElementType() {
608 return typeid(
typename T::ElementType);
620 virtual bool GetValue(
VtValue* v)
const
626 virtual bool IsEqual(
const VtValue& v)
const
632 const T& _GetValue()
const
634 return *
static_cast<const T*
>(value);
645 typedef char CharArray[N];
679PXR_NAMESPACE_CLOSE_SCOPE
The fully-typed container for a field value in an SdfAbstractData.
A type-erased container for a const field value in an SdfAbstractData.
Interface for scene description data storage.
virtual SDF_API void Set(const SdfPath &path, const TfToken &fieldName, const SdfAbstractDataConstValue &value)=0
Set the value of the given path and fieldName.
virtual SDF_API const std::type_info & QueryTimeSampleTypeid(const SdfPath &path, double time) const
If there is a time sample authored at time, return its value's typeid(), otherwise return typeid(void...
virtual SDF_API bool HasSpec(const SdfPath &path) const =0
Return true if this data has a spec for path.
virtual SDF_API bool Has(const SdfPath &path, const TfToken &fieldName, SdfAbstractDataValue *value) const =0
Returns whether a value exists for the given path and fieldName.
virtual SDF_API bool Has(const SdfPath &path, const TfToken &fieldName, VtValue *value=NULL) const =0
Return whether a value exists for the given path and fieldName.
virtual SDF_API bool IsDetached() const
Returns true if this data object is detached from its serialized data store, false otherwise.
virtual SDF_API bool GetPreviousTimeSampleForPath(const SdfPath &path, double time, double *tPrevious) const
Returns the previous time sample authored just before the querying time.
virtual SDF_API std::type_info const & GetTypeid(const SdfPath &path, const TfToken &fieldName) const
Return the type of the value for fieldName on spec path.
virtual SDF_API bool IsEmpty() const
Returns true if this data object has no specs, false otherwise.
virtual SDF_API bool Equals(const SdfAbstractDataRefPtr &rhs) const
Returns true if this data object contains the same specs and fields as lhs, false otherwise.
virtual SDF_API void CopyFrom(const SdfAbstractDataConstPtr &source)
Copy the data in source into this data object.
virtual SDF_API VtValue Get(const SdfPath &path, const TfToken &fieldName) const =0
Return the value for the given path and fieldName.
virtual SDF_API void CreateSpec(const SdfPath &path, SdfSpecType specType)=0
Create a new spec at path with the given specType.
virtual SDF_API bool HasSpecAndField(const SdfPath &path, const TfToken &fieldName, VtValue *value, SdfSpecType *specType) const
Fill specType (which cannot be nullptr) as if by a call to GetSpecType(path).
virtual SDF_API void EraseSpec(const SdfPath &path)=0
Erase the spec at path and any fields that are on it.
virtual SDF_API void WriteToStream(std::ostream &out) const
Writes the contents of this data object to out.
virtual SDF_API std::vector< TfToken > List(const SdfPath &path) const =0
Return the names of all the fields that are set at path.
virtual SDF_API void Set(const SdfPath &path, const TfToken &fieldName, const VtValue &value)=0
Set the value of the given path and fieldName.
virtual SDF_API bool StreamsData() const =0
Returns true if this data object streams its data to and from its serialized data store on demand.
virtual SDF_API bool HasSpecAndField(const SdfPath &path, const TfToken &fieldName, SdfAbstractDataValue *value, SdfSpecType *specType) const
Fill specType (which cannot be nullptr) as if by a call to GetSpecType(path).
virtual SDF_API void _VisitSpecs(SdfAbstractDataSpecVisitor *visitor) const =0
Visits every spec in this SdfAbstractData object with the given visitor.
SDF_API void VisitSpecs(SdfAbstractDataSpecVisitor *visitor) const
Visits every spec in this SdfAbstractData object with the given visitor.
virtual SDF_API void MoveSpec(const SdfPath &oldPath, const SdfPath &newPath)=0
Move the spec at oldPath to newPath, including all the fields that are on it.
T GetAs(const SdfPath &path, const TfToken &fieldName, const T &defaultValue=T()) const
Return the value for the given path and fieldName.
virtual SDF_API void Erase(const SdfPath &path, const TfToken &fieldName)=0
Remove the field at path and fieldName, if one exists.
virtual SdfSpecType GetSpecType(const SdfPath &path) const =0
Return the spec type for the spec at path.
Base class for objects used to visit specs in an SdfAbstractData object.
virtual SDF_API bool VisitSpec(const SdfAbstractData &data, const SdfPath &path)=0
SdfAbstractData::VisitSpecs calls this function for every entry it contains, passing itself as data a...
virtual SDF_API void Done(const SdfAbstractData &data)=0
SdfAbstractData::VisitSpecs will call this after visitation is complete, even if some VisitSpec() ret...
The fully-typed container for a field value in an SdfAbstractData.
A type-erased container for a field value in an SdfAbstractData.
A path value used to locate objects in layers or scenegraphs.
Enable a concrete base class for use with TfRefPtr.
Token for efficient comparison, assignment, and hashing of known strings.
Enable a concrete base class for use with TfWeakPtr.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
T UncheckedRemove()
Make this value empty and return the held T instance.
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
Safely compare std::type_info structures.
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
A trait to detect instantiations of VtArrayEdit, specialized in arrayEdit.h.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
SdfSpecType
An enum that specifies the type of an object.