Loading...
Searching...
No Matches
spec.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_SDF_SPEC_H
8#define PXR_USD_SDF_SPEC_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
14#include "pxr/usd/sdf/abstractData.h"
15#include "pxr/usd/sdf/identity.h"
16#include "pxr/usd/sdf/declareSpec.h"
17#include "pxr/usd/sdf/schema.h"
18#include "pxr/usd/sdf/types.h"
19#include "pxr/base/vt/value.h"
20#include "pxr/base/tf/hash.h"
21#include "pxr/base/tf/token.h"
22#include "pxr/base/tf/type.h"
23
24#include <iosfwd>
25
26PXR_NAMESPACE_OPEN_SCOPE
27
32class SdfSpec
33{
34 SDF_DECLARE_BASE_SPEC(SdfSpec);
35
36public:
37 SDF_API
38 SdfSpec &operator=(const SdfSpec &other);
39
40 SDF_API
41 ~SdfSpec();
42
46
48 SDF_API
49 const SdfSchemaBase& GetSchema() const;
50
53 SDF_API
55
57 SDF_API
58 bool IsDormant() const;
59
61 SDF_API
62 SdfLayerHandle GetLayer() const;
63
65 SDF_API
67
69 SDF_API
70 bool PermissionToEdit() const;
71
74 SDF_API
75 std::vector<TfToken> ListInfoKeys() const;
76
85 SDF_API
86 std::vector<TfToken> GetMetaDataInfoKeys() const;
87
90 SDF_API
92
97 SDF_API
98 VtValue GetInfo(const TfToken &key) const;
99
107 SDF_API
108 void SetInfo(const TfToken &key, const VtValue &value);
109
112 SDF_API
113 void SetInfoDictionaryValue(const TfToken &dictionaryKey,
114 const TfToken &entryKey, const VtValue &value);
115
132 SDF_API
133 bool HasInfo(const TfToken &key) const;
134
143 SDF_API
144 void ClearInfo(const TfToken &key);
145
147 SDF_API
148 TfType GetTypeForInfo(const TfToken &key) const;
149
151 SDF_API
152 const VtValue& GetFallbackForInfo(const TfToken &key) const;
153
155 SDF_API
156 bool WriteToStream(std::ostream&, size_t indent = 0) const;
157
166 SDF_API
167 bool IsInert(bool ignoreChildren = false) const;
168
170
173
175 SDF_API
176 std::vector<TfToken> ListFields() const;
177
180 SDF_API
181 bool HasField(const TfToken &name) const;
182
186 template <class T>
187 bool HasField(const TfToken &name, T* value) const
188 {
189 if (!value) {
190 return HasField(name);
191 }
192
193 SdfAbstractDataTypedValue<T> outValue(value);
194 return _HasField(name, &outValue);
195 }
196
198 SDF_API
199 VtValue GetField(const TfToken &name) const;
200
204 template <typename T>
205 T GetFieldAs(const TfToken & name, const T& defaultValue = T()) const
206 {
207 VtValue v = GetField(name);
208 if (v.IsEmpty() || !v.IsHolding<T>())
209 return defaultValue;
210 return v.UncheckedGet<T>();
211 }
212
214 SDF_API
215 bool SetField(const TfToken & name, const VtValue& value);
216
218 template <typename T>
219 bool SetField(const TfToken & name, const T& value)
220 {
221 return SetField(name, VtValue(value));
222 }
223
225 SDF_API
226 bool ClearField(const TfToken & name);
227
229
232
233 SDF_API bool operator==(const SdfSpec& rhs) const;
234 SDF_API bool operator<(const SdfSpec& rhs) const;
235
237
239 template <class HashState>
240 friend void TfHashAppend(HashState &h, const SdfSpec& x);
241
242private:
243 SDF_API
244 bool _HasField(const TfToken& name, SdfAbstractDataValue* value) const;
245
246protected:
247 bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath) const;
248 bool _DeleteSpec(const SdfPath &path);
249
250private:
252};
253
254template <class HashState>
255void TfHashAppend(HashState &h, const SdfSpec& x) {
256 h.Append(x._id.get());
257}
258
259inline size_t hash_value(const SdfSpec &x) {
260 return TfHash()(x);
261}
262
263PXR_NAMESPACE_CLOSE_SCOPE
264
265#endif // PXR_USD_SDF_SPEC_H
The fully-typed container for a field value in an SdfAbstractData.
Definition: abstractData.h:493
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:428
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:281
Generic class that provides information about scene description fields but doesn't actually provide a...
Definition: schema.h:45
Base class for all Sdf spec classes.
Definition: spec.h:33
T GetFieldAs(const TfToken &name, const T &defaultValue=T()) const
Returns a field value by name.
Definition: spec.h:205
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:255
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:219
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:187
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:472
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
bool IsEmpty() const
Returns true iff this value is empty.
Definition: value.h:1227
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1002
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1046
Basic Sdf data types.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:71
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...