Loading...
Searching...
No Matches
data.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_SDF_DATA_H
8#define PXR_USD_SDF_DATA_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/sdf/api.h"
12#include "pxr/usd/sdf/abstractData.h"
13#include "pxr/usd/sdf/path.h"
15#include "pxr/base/tf/hashmap.h"
16#include "pxr/base/tf/token.h"
17#include "pxr/base/vt/value.h"
18
19#include <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
24
33{
34public:
35 SdfData() {}
36 SDF_API
37 virtual ~SdfData();
38
40
41 SDF_API
42 virtual bool StreamsData() const;
43
44 SDF_API
45 virtual bool IsDetached() const;
46
47 SDF_API
48 virtual void CreateSpec(const SdfPath& path,
49 SdfSpecType specType);
50 SDF_API
51 virtual bool HasSpec(const SdfPath& path) const;
52 SDF_API
53 virtual void EraseSpec(const SdfPath& path);
54 SDF_API
55 virtual void MoveSpec(const SdfPath& oldPath,
56 const SdfPath& newPath);
57 SDF_API
58 virtual SdfSpecType GetSpecType(const SdfPath& path) const;
59
60 SDF_API
61 virtual bool Has(const SdfPath& path, const TfToken &fieldName,
62 SdfAbstractDataValue* value) const;
63 SDF_API
64 virtual bool Has(const SdfPath& path, const TfToken& fieldName,
65 VtValue *value = NULL) const;
66 SDF_API
67 virtual bool
68 HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
69 SdfAbstractDataValue *value, SdfSpecType *specType) const;
70
71 SDF_API
72 virtual bool
73 HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
74 VtValue *value, SdfSpecType *specType) const;
75
76 SDF_API
77 virtual VtValue Get(const SdfPath& path,
78 const TfToken& fieldName) const;
79 SDF_API
80 virtual void Set(const SdfPath& path, const TfToken& fieldName,
81 const VtValue & value);
82 SDF_API
83 virtual void Set(const SdfPath& path, const TfToken& fieldName,
84 const SdfAbstractDataConstValue& value);
85 SDF_API
86 virtual void Erase(const SdfPath& path,
87 const TfToken& fieldName);
88 SDF_API
89 virtual std::vector<TfToken> List(const SdfPath& path) const;
90
91 SDF_API
92 virtual std::set<double>
93 ListAllTimeSamples() const;
94
95 SDF_API
96 virtual std::set<double>
97 ListTimeSamplesForPath(const SdfPath& path) const;
98
99 SDF_API
100 virtual bool
101 GetBracketingTimeSamples(double time, double* tLower, double* tUpper) const;
102
103 SDF_API
104 virtual size_t
105 GetNumTimeSamplesForPath(const SdfPath& path) const;
106
107 SDF_API
108 virtual bool
109 GetBracketingTimeSamplesForPath(const SdfPath& path,
110 double time,
111 double* tLower, double* tUpper) const;
112
113 SDF_API
114 virtual bool
115 GetPreviousTimeSampleForPath(const SdfPath& path, double time,
116 double* tPrevious) const;
117
118 SDF_API
119 virtual bool
120 QueryTimeSample(const SdfPath& path, double time,
121 SdfAbstractDataValue *optionalValue) const;
122 SDF_API
123 virtual bool
124 QueryTimeSample(const SdfPath& path, double time,
125 VtValue *value) const;
126
127 SDF_API
128 virtual void
129 SetTimeSample(const SdfPath& path, double time,
130 const VtValue & value);
131
132 SDF_API
133 virtual void
134 EraseTimeSample(const SdfPath& path, double time);
135
136protected:
137 // SdfAbstractData overrides
138 SDF_API
139 virtual void _VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const;
140
141private:
142 const VtValue* _GetSpecTypeAndFieldValue(const SdfPath& path,
143 const TfToken& field,
144 SdfSpecType* specType) const;
145
146 const VtValue* _GetFieldValue(const SdfPath& path,
147 const TfToken& field) const;
148
149 VtValue* _GetMutableFieldValue(const SdfPath& path,
150 const TfToken& field);
151
152 VtValue* _GetOrCreateFieldValue(const SdfPath& path,
153 const TfToken& field);
154
155private:
156 // Backing storage for a single "spec" -- prim, property, etc.
157 typedef std::pair<TfToken, VtValue> _FieldValuePair;
158 struct _SpecData {
159 _SpecData() : specType(SdfSpecTypeUnknown) {}
160
161 SdfSpecType specType;
162 std::vector<_FieldValuePair> fields;
163 };
164
165 // Hashtable storing _SpecData.
166 typedef SdfPath _Key;
167 typedef SdfPath::Hash _KeyHash;
168 typedef TfHashMap<_Key, _SpecData, _KeyHash> _HashTable;
169
170 _HashTable _data;
171};
172
173PXR_NAMESPACE_CLOSE_SCOPE
174
175#endif // PXR_USD_SDF_DATA_H
A type-erased container for a const field value in an SdfAbstractData.
Definition: abstractData.h:544
Interface for scene description data storage.
Definition: abstractData.h:57
Base class for objects used to visit specs in an SdfAbstractData object.
Definition: abstractData.h:649
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:417
SdfData provides concrete scene description data storage.
Definition: data.h:33
virtual SDF_API bool Has(const SdfPath &path, const TfToken &fieldName, SdfAbstractDataValue *value) const
Returns whether a value exists for the given path and fieldName.
virtual SDF_API bool HasSpec(const SdfPath &path) const
Return true if this data has a spec for path.
virtual SDF_API void EraseSpec(const SdfPath &path)
Erase the spec at path and any fields that are on it.
virtual SDF_API void Set(const SdfPath &path, const TfToken &fieldName, const VtValue &value)
Set the value of 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 void Set(const SdfPath &path, const TfToken &fieldName, const SdfAbstractDataConstValue &value)
Set the value of the given path and fieldName.
virtual SDF_API void Erase(const SdfPath &path, const TfToken &fieldName)
Remove the field at path and fieldName, if one exists.
virtual SDF_API VtValue Get(const SdfPath &path, const TfToken &fieldName) const
Return the value for the given path and fieldName.
virtual SDF_API std::vector< TfToken > List(const SdfPath &path) const
Return the names of all the fields that are set at path.
virtual SDF_API bool StreamsData() const
SdfAbstractData overrides.
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 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 CreateSpec(const SdfPath &path, SdfSpecType specType)
Create a new spec at path with the given specType.
virtual SDF_API void MoveSpec(const SdfPath &oldPath, const SdfPath &newPath)
Move the spec at oldPath to newPath, including all the fields that are on it.
virtual SDF_API bool Has(const SdfPath &path, const TfToken &fieldName, VtValue *value=NULL) const
Return whether a value exists for the given path and fieldName.
virtual SDF_API SdfSpecType GetSpecType(const SdfPath &path) const
Return the spec type for the spec at path.
virtual SDF_API void _VisitSpecs(SdfAbstractDataSpecVisitor *visitor) const
Visits every spec in this SdfAbstractData object with the given visitor.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
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.
Definition: types.h:68