data.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_SDF_DATA_H
25 #define PXR_USD_SDF_DATA_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/api.h"
29 #include "pxr/usd/sdf/abstractData.h"
30 #include "pxr/usd/sdf/path.h"
32 #include "pxr/base/tf/hashmap.h"
33 #include "pxr/base/tf/token.h"
34 #include "pxr/base/vt/value.h"
35 
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
41 
49 class SdfData : public SdfAbstractData
50 {
51 public:
52  SdfData() {}
53  SDF_API
54  virtual ~SdfData();
55 
57 
58  SDF_API
59  virtual bool StreamsData() const;
60 
61  SDF_API
62  virtual bool IsDetached() const;
63 
64  SDF_API
65  virtual void CreateSpec(const SdfPath& path,
66  SdfSpecType specType);
67  SDF_API
68  virtual bool HasSpec(const SdfPath& path) const;
69  SDF_API
70  virtual void EraseSpec(const SdfPath& path);
71  SDF_API
72  virtual void MoveSpec(const SdfPath& oldPath,
73  const SdfPath& newPath);
74  SDF_API
75  virtual SdfSpecType GetSpecType(const SdfPath& path) const;
76 
77  SDF_API
78  virtual bool Has(const SdfPath& path, const TfToken &fieldName,
79  SdfAbstractDataValue* value) const;
80  SDF_API
81  virtual bool Has(const SdfPath& path, const TfToken& fieldName,
82  VtValue *value = NULL) const;
83  SDF_API
84  virtual bool
85  HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
86  SdfAbstractDataValue *value, SdfSpecType *specType) const;
87 
88  SDF_API
89  virtual bool
90  HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
91  VtValue *value, SdfSpecType *specType) const;
92 
93  SDF_API
94  virtual VtValue Get(const SdfPath& path,
95  const TfToken& fieldName) const;
96  SDF_API
97  virtual void Set(const SdfPath& path, const TfToken& fieldName,
98  const VtValue & value);
99  SDF_API
100  virtual void Set(const SdfPath& path, const TfToken& fieldName,
101  const SdfAbstractDataConstValue& value);
102  SDF_API
103  virtual void Erase(const SdfPath& path,
104  const TfToken& fieldName);
105  SDF_API
106  virtual std::vector<TfToken> List(const SdfPath& path) const;
107 
108  SDF_API
109  virtual std::set<double>
110  ListAllTimeSamples() const;
111 
112  SDF_API
113  virtual std::set<double>
114  ListTimeSamplesForPath(const SdfPath& path) const;
115 
116  SDF_API
117  virtual bool
118  GetBracketingTimeSamples(double time, double* tLower, double* tUpper) const;
119 
120  SDF_API
121  virtual size_t
122  GetNumTimeSamplesForPath(const SdfPath& path) const;
123 
124  SDF_API
125  virtual bool
126  GetBracketingTimeSamplesForPath(const SdfPath& path,
127  double time,
128  double* tLower, double* tUpper) const;
129 
130  SDF_API
131  virtual bool
132  QueryTimeSample(const SdfPath& path, double time,
133  SdfAbstractDataValue *optionalValue) const;
134  SDF_API
135  virtual bool
136  QueryTimeSample(const SdfPath& path, double time,
137  VtValue *value) const;
138 
139  SDF_API
140  virtual void
141  SetTimeSample(const SdfPath& path, double time,
142  const VtValue & value);
143 
144  SDF_API
145  virtual void
146  EraseTimeSample(const SdfPath& path, double time);
147 
148 protected:
149  // SdfAbstractData overrides
150  SDF_API
151  virtual void _VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const;
152 
153 private:
154  const VtValue* _GetSpecTypeAndFieldValue(const SdfPath& path,
155  const TfToken& field,
156  SdfSpecType* specType) const;
157 
158  const VtValue* _GetFieldValue(const SdfPath& path,
159  const TfToken& field) const;
160 
161  VtValue* _GetMutableFieldValue(const SdfPath& path,
162  const TfToken& field);
163 
164  VtValue* _GetOrCreateFieldValue(const SdfPath& path,
165  const TfToken& field);
166 
167 private:
168  // Backing storage for a single "spec" -- prim, property, etc.
169  typedef std::pair<TfToken, VtValue> _FieldValuePair;
170  struct _SpecData {
171  _SpecData() : specType(SdfSpecTypeUnknown) {}
172 
173  SdfSpecType specType;
174  std::vector<_FieldValuePair> fields;
175  };
176 
177  // Hashtable storing _SpecData.
178  typedef SdfPath _Key;
179  typedef SdfPath::Hash _KeyHash;
180  typedef TfHashMap<_Key, _SpecData, _KeyHash> _HashTable;
181 
182  _HashTable _data;
183 };
184 
185 PXR_NAMESPACE_CLOSE_SCOPE
186 
187 #endif // PXR_USD_SDF_DATA_H
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 void EraseSpec(const SdfPath &path)
Erase the spec at path and any fields that are on it.
Standard pointer typedefs.
virtual SDF_API void Erase(const SdfPath &path, const TfToken &fieldName)
Remove the field at path and fieldName, if one exists.
Base class for objects used to visit specs in an SdfAbstractData object.
Definition: abstractData.h:608
A type-erased container for a const field value in an SdfAbstractData.
Definition: abstractData.h:519
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:415
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.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
virtual SDF_API SdfSpecType GetSpecType(const SdfPath &path) const
Return the spec type for the spec at path.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
virtual SDF_API void CreateSpec(const SdfPath &path, SdfSpecType specType)
Create a new spec at path with the given specType.
virtual SDF_API VtValue Get(const SdfPath &path, const TfToken &fieldName) const
Return the value for the given path and fieldName.
SdfData provides concrete scene description data storage.
Definition: data.h:49
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
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 bool StreamsData() const
SdfAbstractData overrides.
virtual SDF_API bool IsDetached() const
Returns true if this data object is detached from its serialized data store, false otherwise.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:90
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.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
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 HasSpec(const SdfPath &path) const
Return true if this data has a spec for path.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
Interface for scene description data storage.
Definition: abstractData.h:73
virtual SDF_API void _VisitSpecs(SdfAbstractDataSpecVisitor *visitor) const
Visits every spec in this SdfAbstractData object with the given visitor.