This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 QueryTimeSample(const SdfPath& path, double time,
116 SdfAbstractDataValue *optionalValue) const;
117 SDF_API
118 virtual bool
119 QueryTimeSample(const SdfPath& path, double time,
120 VtValue *value) const;
121
122 SDF_API
123 virtual void
124 SetTimeSample(const SdfPath& path, double time,
125 const VtValue & value);
126
127 SDF_API
128 virtual void
129 EraseTimeSample(const SdfPath& path, double time);
130
131protected:
132 // SdfAbstractData overrides
133 SDF_API
134 virtual void _VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const;
135
136private:
137 const VtValue* _GetSpecTypeAndFieldValue(const SdfPath& path,
138 const TfToken& field,
139 SdfSpecType* specType) const;
140
141 const VtValue* _GetFieldValue(const SdfPath& path,
142 const TfToken& field) const;
143
144 VtValue* _GetMutableFieldValue(const SdfPath& path,
145 const TfToken& field);
146
147 VtValue* _GetOrCreateFieldValue(const SdfPath& path,
148 const TfToken& field);
149
150private:
151 // Backing storage for a single "spec" -- prim, property, etc.
152 typedef std::pair<TfToken, VtValue> _FieldValuePair;
153 struct _SpecData {
154 _SpecData() : specType(SdfSpecTypeUnknown) {}
155
156 SdfSpecType specType;
157 std::vector<_FieldValuePair> fields;
158 };
159
160 // Hashtable storing _SpecData.
161 typedef SdfPath _Key;
162 typedef SdfPath::Hash _KeyHash;
163 typedef TfHashMap<_Key, _SpecData, _KeyHash> _HashTable;
164
165 _HashTable _data;
166};
167
168PXR_NAMESPACE_CLOSE_SCOPE
169
170#endif // PXR_USD_SDF_DATA_H
A type-erased container for a const field value in an SdfAbstractData.
Definition: abstractData.h:512
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:601
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:399
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 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:147
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