HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
data.h
Go to the documentation of this file.
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"
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 
39 
41 
42 /// \class SdfData
43 ///
44 /// SdfData provides concrete scene description data storage.
45 ///
46 /// An SdfData is an implementation of SdfAbstractData that simply
47 /// stores specs and fields in a map keyed by path.
48 ///
49 class SdfData : public SdfAbstractData
50 {
51 public:
52  SdfData() {}
53  SDF_API
54  virtual ~SdfData();
55 
56  /// SdfAbstractData overrides
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,
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,
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
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 
186 
187 #endif // PXR_USD_SDF_DATA_H
virtual SDF_API bool HasSpec(const SdfPath &path) const
Return true if this data has a spec for path.
virtual SDF_API bool GetBracketingTimeSamples(double time, double *tLower, double *tUpper) const
GT_API const UT_StringHolder time
virtual SDF_API SdfSpecType GetSpecType(const SdfPath &path) const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual SDF_API void EraseSpec(const SdfPath &path)
virtual SDF_API ~SdfData()
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_AND_REF_PTRS(SdfData)
Definition: token.h:87
virtual SDF_API size_t GetNumTimeSamplesForPath(const SdfPath &path) const
SdfData()
Definition: data.h:52
virtual SDF_API bool StreamsData() const
SdfAbstractData overrides.
virtual SDF_API bool QueryTimeSample(const SdfPath &path, double time, SdfAbstractDataValue *optionalValue) const
Definition: data.h:49
virtual SDF_API std::set< double > ListAllTimeSamples() const
Definition: path.h:291
virtual SDF_API void _VisitSpecs(SdfAbstractDataSpecVisitor *visitor) const
#define SDF_API
Definition: api.h:40
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 void CreateSpec(const SdfPath &path, SdfSpecType specType)
virtual SDF_API void MoveSpec(const SdfPath &oldPath, const SdfPath &newPath)
virtual SDF_API bool Has(const SdfPath &path, const TfToken &fieldName, SdfAbstractDataValue *value) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual SDF_API VtValue Get(const SdfPath &path, const TfToken &fieldName) const
SdfSpecType
Definition: types.h:90
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: core.h:1131
virtual SDF_API void Erase(const SdfPath &path, const TfToken &fieldName)
Remove the field at path and fieldName, if one exists.
virtual SDF_API bool GetBracketingTimeSamplesForPath(const SdfPath &path, double time, double *tLower, double *tUpper) const
virtual SDF_API std::set< double > ListTimeSamplesForPath(const SdfPath &path) const
virtual SDF_API void EraseTimeSample(const SdfPath &path, double time)
virtual SDF_API void SetTimeSample(const SdfPath &path, double time, const VtValue &value)
virtual SDF_API bool IsDetached() const
Definition: value.h:167
virtual SDF_API bool HasSpecAndField(const SdfPath &path, const TfToken &fieldName, SdfAbstractDataValue *value, SdfSpecType *specType) const
virtual SDF_API void Set(const SdfPath &path, const TfToken &fieldName, const VtValue &value)