All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 void CreateSpec(const SdfPath& path,
63  SdfSpecType specType);
64  SDF_API
65  virtual bool HasSpec(const SdfPath& path) const;
66  SDF_API
67  virtual void EraseSpec(const SdfPath& path);
68  SDF_API
69  virtual void MoveSpec(const SdfPath& oldPath,
70  const SdfPath& newPath);
71  SDF_API
72  virtual SdfSpecType GetSpecType(const SdfPath& path) const;
73 
74  SDF_API
75  virtual bool Has(const SdfPath& path, const TfToken &fieldName,
76  SdfAbstractDataValue* value) const;
77  SDF_API
78  virtual bool Has(const SdfPath& path, const TfToken& fieldName,
79  VtValue *value = NULL) const;
80  SDF_API
81  virtual bool
82  HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
83  SdfAbstractDataValue *value, SdfSpecType *specType) const;
84 
85  SDF_API
86  virtual bool
87  HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
88  VtValue *value, SdfSpecType *specType) const;
89 
90  SDF_API
91  virtual VtValue Get(const SdfPath& path,
92  const TfToken& fieldName) const;
93  SDF_API
94  virtual void Set(const SdfPath& path, const TfToken& fieldName,
95  const VtValue & value);
96  SDF_API
97  virtual void Set(const SdfPath& path, const TfToken& fieldName,
98  const SdfAbstractDataConstValue& value);
99  SDF_API
100  virtual void Erase(const SdfPath& path,
101  const TfToken& fieldName);
102  SDF_API
103  virtual std::vector<TfToken> List(const SdfPath& path) const;
104 
105  SDF_API
106  virtual std::set<double>
107  ListAllTimeSamples() const;
108 
109  SDF_API
110  virtual std::set<double>
111  ListTimeSamplesForPath(const SdfPath& path) const;
112 
113  SDF_API
114  virtual bool
115  GetBracketingTimeSamples(double time, double* tLower, double* tUpper) const;
116 
117  SDF_API
118  virtual size_t
119  GetNumTimeSamplesForPath(const SdfPath& path) const;
120 
121  SDF_API
122  virtual bool
123  GetBracketingTimeSamplesForPath(const SdfPath& path,
124  double time,
125  double* tLower, double* tUpper) const;
126 
127  SDF_API
128  virtual bool
129  QueryTimeSample(const SdfPath& path, double time,
130  SdfAbstractDataValue *optionalValue) const;
131  SDF_API
132  virtual bool
133  QueryTimeSample(const SdfPath& path, double time,
134  VtValue *value) const;
135 
136  SDF_API
137  virtual void
138  SetTimeSample(const SdfPath& path, double time,
139  const VtValue & value);
140 
141  SDF_API
142  virtual void
143  EraseTimeSample(const SdfPath& path, double time);
144 
145 protected:
146  // SdfAbstractData overrides
147  SDF_API
148  virtual void _VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const;
149 
150 private:
151  const VtValue* _GetSpecTypeAndFieldValue(const SdfPath& path,
152  const TfToken& field,
153  SdfSpecType* specType) const;
154 
155  const VtValue* _GetFieldValue(const SdfPath& path,
156  const TfToken& field) const;
157 
158  VtValue* _GetMutableFieldValue(const SdfPath& path,
159  const TfToken& field);
160 
161  VtValue* _GetOrCreateFieldValue(const SdfPath& path,
162  const TfToken& field);
163 
164 private:
165  // Backing storage for a single "spec" -- prim, property, etc.
166  typedef std::pair<TfToken, VtValue> _FieldValuePair;
167  struct _SpecData {
168  _SpecData() : specType(SdfSpecTypeUnknown) {}
169 
170  SdfSpecType specType;
171  std::vector<_FieldValuePair> fields;
172  };
173 
174  // Hashtable storing _SpecData.
175  typedef SdfPath _Key;
176  typedef SdfPath::Hash _KeyHash;
177  typedef TfHashMap<_Key, _SpecData, _KeyHash> _HashTable;
178 
179  _HashTable _data;
180 };
181 
182 PXR_NAMESPACE_CLOSE_SCOPE
183 
184 #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 _VisitSpecs(SdfAbstractDataSpecVisitor *visitor) const
Visits every spec in this SdfAbstractData object with the given visitor.
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:566
A type-erased container for a const field value in an SdfAbstractData.
Definition: abstractData.h:477
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:394
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 SdfSpecType GetSpecType(const SdfPath &path) const
Return the spec type for the spec at path.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
virtual SDF_API VtValue Get(const SdfPath &path, const TfToken &fieldName) const
Return the value for the given path and fieldName.
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.
SdfData provides concrete scene description data storage.
Definition: data.h:49
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).
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
virtual SDF_API bool HasSpec(const SdfPath &path) const
Return true if this data has a spec for path.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:91
virtual SDF_API bool StreamsData() const
SdfAbstractData overrides.
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 std::vector< TfToken > List(const SdfPath &path) const
Return the names of all the fields that are set at path.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:168
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