All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
schemaBase.h
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_USD_SCHEMA_BASE_H
8#define PXR_USD_USD_SCHEMA_BASE_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usd/api.h"
12#include "pxr/usd/usd/prim.h"
13#include "pxr/usd/usd/attribute.h"
14#include "pxr/usd/usd/relationship.h"
15#include "pxr/usd/usd/references.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
19
40public:
44 static const UsdSchemaKind schemaKind = UsdSchemaKind::AbstractBase;
45
50 bool IsConcrete() const {
51 return GetSchemaKind() == UsdSchemaKind::ConcreteTyped;
52 }
53
56 bool IsTyped() const {
57 return GetSchemaKind() == UsdSchemaKind::ConcreteTyped
58 || GetSchemaKind() == UsdSchemaKind::AbstractTyped;
59 }
60
62 bool IsAPISchema() const {
63 return GetSchemaKind() == UsdSchemaKind::NonAppliedAPI
64 || GetSchemaKind() == UsdSchemaKind::SingleApplyAPI
65 || GetSchemaKind() == UsdSchemaKind::MultipleApplyAPI;
66 }
67
70 bool IsAppliedAPISchema() const {
71 return GetSchemaKind() == UsdSchemaKind::SingleApplyAPI
72 || GetSchemaKind() == UsdSchemaKind::MultipleApplyAPI;
73 }
74
79 return GetSchemaKind() == UsdSchemaKind::MultipleApplyAPI;
80 }
81
84 return _GetSchemaKind();
85 }
86
88 USD_API
89 explicit UsdSchemaBase(const UsdPrim& prim = UsdPrim());
90
92 USD_API
93 explicit UsdSchemaBase(const UsdSchemaBase& otherSchema);
94
96 USD_API
97 virtual ~UsdSchemaBase();
98
100
101
103 UsdPrim GetPrim() const { return UsdPrim(_primData, _proxyPrimPath); }
104
106 SdfPath GetPath() const {
107 if (!_proxyPrimPath.IsEmpty()) {
108 return _proxyPrimPath;
109 }
110 else if (Usd_PrimDataConstPtr p = get_pointer(_primData)) {
111 return p->GetPath();
112 }
113 return SdfPath::EmptyPath();
114 }
115
117
119
120
125 USD_API
127
129
130 static const TfTokenVector &
131 GetSchemaAttributeNames(bool includeInherited=true)
132 {
133 /* This only exists for consistency */
134 static TfTokenVector names;
135 return names;
136 }
137
147 USD_API
148 explicit operator bool() const {
149 return _primData && _IsCompatible();
150 }
151
152protected:
157 return schemaKind;
158 }
159
169 return schemaKind;
170 }
171
172 // Helper for subclasses to get the TfType for this schema object's dynamic
173 // C++ type.
174 const TfType &_GetType() const {
175 return _GetTfType();
176 }
177
178 USD_API
179 UsdAttribute _CreateAttr(TfToken const &attrName,
180 SdfValueTypeName const & typeName,
181 bool custom, SdfVariability variability,
182 VtValue const &defaultValue,
183 bool writeSparsely) const;
184
189 USD_API
190 virtual bool _IsCompatible() const;
191
192private:
193 // needs to invoke _GetStaticTfType.
194 friend class UsdSchemaRegistry;
195 USD_API
196 static const TfType &_GetStaticTfType();
197
198 // Subclasses should not override _GetTfType. It is implemented by the
199 // schema class code generator.
200 USD_API
201 virtual const TfType &_GetTfType() const;
202
203 // The held prim and proxy prim path.
204 Usd_PrimDataHandle _primData;
205 SdfPath _proxyPrimPath;
206};
207
208
209PXR_NAMESPACE_CLOSE_SCOPE
210
211#endif //PXR_USD_USD_SCHEMA_BASE_H
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:398
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
Represents a value type name, i.e.
Definition: valueTypeName.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:160
Class representing the builtin definition of a prim given the schemas registered in the schema regist...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
The base class for all schema types in Usd.
Definition: schemaBase.h:39
USD_API UsdSchemaBase(const UsdPrim &prim=UsdPrim())
Construct and store prim as the held prim.
static const UsdSchemaKind schemaKind
Compile time constant representing what kind of schema this class is.
Definition: schemaBase.h:44
virtual USD_API ~UsdSchemaBase()
Destructor.
USD_API const UsdPrimDefinition * GetSchemaClassPrimDefinition() const
Return the prim definition associated with this schema instance if one exists, otherwise return null.
UsdPrim GetPrim() const
Return this schema object's held prim.
Definition: schemaBase.h:103
virtual USD_API bool _IsCompatible() const
Subclasses may override _IsCompatible to do specific compatibility checking with the given prim,...
bool IsAppliedAPISchema() const
Returns whether this is an applied API schema or not.
Definition: schemaBase.h:70
virtual UsdSchemaKind _GetSchemaType() const
Definition: schemaBase.h:168
USD_API UsdSchemaBase(const UsdSchemaBase &otherSchema)
Construct and store for the same prim held by otherSchema.
SdfPath GetPath() const
Shorthand for GetPrim()->GetPath().
Definition: schemaBase.h:106
bool IsAPISchema() const
Returns whether this is an API schema or not.
Definition: schemaBase.h:62
bool IsConcrete() const
Returns whether or not this class corresponds to a concrete instantiable prim type in scene descripti...
Definition: schemaBase.h:50
virtual UsdSchemaKind _GetSchemaKind() const
Returns the kind of schema this class is.
Definition: schemaBase.h:156
UsdSchemaKind GetSchemaKind() const
Returns the kind of schema this class is.
Definition: schemaBase.h:83
bool IsMultipleApplyAPISchema() const
Returns whether this is an applied API schema or not.
Definition: schemaBase.h:78
bool IsTyped() const
Returns whether or not this class inherits from UsdTyped.
Definition: schemaBase.h:56
Singleton registry that provides access to schema type information and the prim definitions for regis...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:112
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
SdfVariability
An enum that identifies variability types for attributes.
Definition: types.h:156