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" 31 #include "pxr/base/tf/declarePtrs.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 40 TF_DECLARE_WEAK_AND_REF_PTRS(SdfData); 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: SdfData()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 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 { _SpecData_SpecData168 _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 185