Loading...
Searching...
No Matches
spec.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_SPEC_H
25#define PXR_USD_SDF_SPEC_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/sdf/api.h"
31#include "pxr/usd/sdf/abstractData.h"
32#include "pxr/usd/sdf/identity.h"
33#include "pxr/usd/sdf/declareSpec.h"
34#include "pxr/usd/sdf/schema.h"
35#include "pxr/usd/sdf/types.h"
36#include "pxr/base/vt/value.h"
37#include "pxr/base/tf/hash.h"
38#include "pxr/base/tf/token.h"
39#include "pxr/base/tf/type.h"
40
41#include <iosfwd>
42
43PXR_NAMESPACE_OPEN_SCOPE
44
49class SdfSpec
50{
51 SDF_DECLARE_BASE_SPEC(SdfSpec);
52
53public:
54 SDF_API
55 SdfSpec &operator=(const SdfSpec &other);
56
57 SDF_API
58 ~SdfSpec();
59
63
65 SDF_API
66 const SdfSchemaBase& GetSchema() const;
67
70 SDF_API
72
74 SDF_API
75 bool IsDormant() const;
76
78 SDF_API
79 SdfLayerHandle GetLayer() const;
80
82 SDF_API
84
86 SDF_API
87 bool PermissionToEdit() const;
88
91 SDF_API
92 std::vector<TfToken> ListInfoKeys() const;
93
102 SDF_API
103 std::vector<TfToken> GetMetaDataInfoKeys() const;
104
107 SDF_API
109
114 SDF_API
115 VtValue GetInfo(const TfToken &key) const;
116
124 SDF_API
125 void SetInfo(const TfToken &key, const VtValue &value);
126
129 SDF_API
130 void SetInfoDictionaryValue(const TfToken &dictionaryKey,
131 const TfToken &entryKey, const VtValue &value);
132
149 SDF_API
150 bool HasInfo(const TfToken &key) const;
151
160 SDF_API
161 void ClearInfo(const TfToken &key);
162
164 SDF_API
165 TfType GetTypeForInfo(const TfToken &key) const;
166
168 SDF_API
169 const VtValue& GetFallbackForInfo(const TfToken &key) const;
170
172 SDF_API
173 bool WriteToStream(std::ostream&, size_t indent = 0) const;
174
183 SDF_API
184 bool IsInert(bool ignoreChildren = false) const;
185
187
190
192 SDF_API
193 std::vector<TfToken> ListFields() const;
194
197 SDF_API
198 bool HasField(const TfToken &name) const;
199
203 template <class T>
204 bool HasField(const TfToken &name, T* value) const
205 {
206 if (!value) {
207 return HasField(name);
208 }
209
210 SdfAbstractDataTypedValue<T> outValue(value);
211 return _HasField(name, &outValue);
212 }
213
215 SDF_API
216 VtValue GetField(const TfToken &name) const;
217
221 template <typename T>
222 T GetFieldAs(const TfToken & name, const T& defaultValue = T()) const
223 {
224 VtValue v = GetField(name);
225 if (v.IsEmpty() || !v.IsHolding<T>())
226 return defaultValue;
227 return v.UncheckedGet<T>();
228 }
229
231 SDF_API
232 bool SetField(const TfToken & name, const VtValue& value);
233
235 template <typename T>
236 bool SetField(const TfToken & name, const T& value)
237 {
238 return SetField(name, VtValue(value));
239 }
240
242 SDF_API
243 bool ClearField(const TfToken & name);
244
246
249
250 SDF_API bool operator==(const SdfSpec& rhs) const;
251 SDF_API bool operator<(const SdfSpec& rhs) const;
252
254
256 template <class HashState>
257 friend void TfHashAppend(HashState &h, const SdfSpec& x);
258
259private:
260 SDF_API
261 bool _HasField(const TfToken& name, SdfAbstractDataValue* value) const;
262
263protected:
264 bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath) const;
265 bool _DeleteSpec(const SdfPath &path);
266
267private:
268 Sdf_IdentityRefPtr _id;
269};
270
271template <class HashState>
272void TfHashAppend(HashState &h, const SdfSpec& x) {
273 h.Append(x._id.get());
274}
275
276inline size_t hash_value(const SdfSpec &x) {
277 return TfHash()(x);
278}
279
280PXR_NAMESPACE_CLOSE_SCOPE
281
282#endif // PXR_USD_SDF_SPEC_H
The fully-typed container for a field value in an SdfAbstractData.
Definition: abstractData.h:467
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:416
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
Generic class that provides information about scene description fields but doesn't actually provide a...
Definition: schema.h:62
Base class for all Sdf spec classes.
Definition: spec.h:50
T GetFieldAs(const TfToken &name, const T &defaultValue=T()) const
Returns a field value by name.
Definition: spec.h:222
SDF_API bool HasField(const TfToken &name) const
Returns true if the spec has a non-empty value with field name name.
SDF_API bool IsDormant() const
Returns true if this object is invalid or expired.
friend void TfHashAppend(HashState &h, const SdfSpec &x)
Hash.
Definition: spec.h:272
SDF_API bool IsInert(bool ignoreChildren=false) const
Returns whether this object has no significant data.
SDF_API const VtValue & GetFallbackForInfo(const TfToken &key) const
Returns the fallback for the info with the given key.
SDF_API VtValue GetField(const TfToken &name) const
Returns a field value by name.
SDF_API const SdfSchemaBase & GetSchema() const
Returns the SdfSchemaBase for the layer that owns this spec.
SDF_API std::vector< TfToken > ListFields() const
Returns all fields with values.
SDF_API bool WriteToStream(std::ostream &, size_t indent=0) const
Writes this spec to the given stream.
bool SetField(const TfToken &name, const T &value)
Sets a field value of type T.
Definition: spec.h:236
SDF_API SdfLayerHandle GetLayer() const
Returns the layer that this object belongs to.
bool HasField(const TfToken &name, T *value) const
Returns true if the object has a non-empty value with name name and type T.
Definition: spec.h:204
SDF_API bool ClearField(const TfToken &name)
Clears a field.
SDF_API TfToken GetMetaDataDisplayGroup(TfToken const &key) const
Returns this metadata key's displayGroup.
SDF_API std::vector< TfToken > GetMetaDataInfoKeys() const
Returns the list of metadata info keys for this object.
SDF_API SdfPath GetPath() const
Returns the scene path of this object.
SDF_API bool SetField(const TfToken &name, const VtValue &value)
Sets a field value as a boxed VtValue.
SDF_API SdfSpecType GetSpecType() const
Returns the SdfSpecType specifying the spec type this object represents.
SDF_API VtValue GetInfo(const TfToken &key) const
Gets the value for the given metadata key.
SDF_API TfType GetTypeForInfo(const TfToken &key) const
Returns the data type for the info with the given key.
SDF_API bool PermissionToEdit() const
Returns whether this object's layer can be edited.
SDF_API void SetInfoDictionaryValue(const TfToken &dictionaryKey, const TfToken &entryKey, const VtValue &value)
Sets the value for entryKey to value within the dictionary with the given metadata key dictionaryKey.
SDF_API std::vector< TfToken > ListInfoKeys() const
Returns the full list of info keys currently set on this object.
SDF_API void SetInfo(const TfToken &key, const VtValue &value)
Sets the value for the given metadata key.
SDF_API void ClearInfo(const TfToken &key)
Clears the value for scene spec info with the given key.
SDF_API bool HasInfo(const TfToken &key) const
Returns whether there is a setting for the scene spec info with the given key.
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:477
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
TfType represents a dynamic runtime type.
Definition: type.h:65
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:165
bool IsEmpty() const
Returns true iff this value is empty.
Definition: value.h:1300
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1081
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1121
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
Basic Sdf data types.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:84