All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
schemaRegistry.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_REGISTRY_H
8#define PXR_USD_USD_SCHEMA_REGISTRY_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usd/api.h"
12#include "pxr/usd/usd/common.h"
13
14#include "pxr/usd/sdf/layer.h"
16
17#include "pxr/base/tf/hash.h"
19
20#include <unordered_map>
21#include <vector>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25SDF_DECLARE_HANDLES(SdfAttributeSpec);
26SDF_DECLARE_HANDLES(SdfRelationshipSpec);
27
28class UsdSchemaBase;
30
32using UsdSchemaVersion = unsigned int;
33
54 UsdSchemaRegistry(const UsdSchemaRegistry&) = delete;
55 UsdSchemaRegistry& operator=(const UsdSchemaRegistry&) = delete;
56public:
57 using TokenToTokenVectorMap =
58 std::unordered_map<TfToken, TfTokenVector, TfHash>;
59
62 struct SchemaInfo {
63
68
73
79
81 UsdSchemaVersion version;
82
85 };
86
87 USD_API
88 static UsdSchemaRegistry& GetInstance() {
90 }
91
104 USD_API
105 static TfToken
107 const TfToken &schemaFamily,
108 UsdSchemaVersion schemaVersion);
109
127 USD_API
128 static std::pair<TfToken, UsdSchemaVersion>
130
138 USD_API
139 static bool
140 IsAllowedSchemaFamily(const TfToken &schemaFamily);
141
151 USD_API
152 static bool
153 IsAllowedSchemaIdentifier(const TfToken &schemaIdentifier);
154
158 USD_API
159 static const SchemaInfo *
160 FindSchemaInfo(const TfType &schemaType);
161
170 template <class SchemaType>
171 static const SchemaInfo *
173 static_assert(std::is_base_of<UsdSchemaBase, SchemaType>::value,
174 "Provided type must derive UsdSchemaBase.");
175 return FindSchemaInfo(SchemaType::_GetStaticTfType());
176 }
177
181 USD_API
182 static const SchemaInfo *
183 FindSchemaInfo(const TfToken &schemaIdentifier);
184
188 USD_API
189 static const SchemaInfo *
190 FindSchemaInfo(const TfToken &schemaFamily, UsdSchemaVersion schemaVersion);
191
194 enum class VersionPolicy {
195 All,
196 GreaterThan,
197 GreaterThanOrEqual,
198 LessThan,
199 LessThanOrEqual
200 };
201
204 USD_API
205 static const std::vector<const SchemaInfo *> &
207 const TfToken &schemaFamily);
208
212 USD_API
213 static std::vector<const SchemaInfo *>
215 const TfToken &schemaFamily,
216 UsdSchemaVersion schemaVersion,
217 VersionPolicy versionPolicy);
218
221 USD_API
222 static TfToken GetSchemaTypeName(const TfType &schemaType);
223
226 template <class SchemaType>
227 static
229 return GetSchemaTypeName(SchemaType::_GetStaticTfType());
230 }
231
234 USD_API
235 static TfToken GetConcreteSchemaTypeName(const TfType &schemaType);
236
239 USD_API
240 static TfToken GetAPISchemaTypeName(const TfType &schemaType);
241
244 USD_API
245 static TfType GetTypeFromSchemaTypeName(const TfToken &typeName);
246
249 USD_API
251
254 USD_API
256
264 USD_API
265 static bool IsDisallowedField(const TfToken &fieldName);
266
268 USD_API
269 static bool IsTyped(const TfType& primType);
270
276 USD_API
277 static UsdSchemaKind GetSchemaKind(const TfType &schemaType);
278
284 USD_API
285 static UsdSchemaKind GetSchemaKind(const TfToken &typeName);
286
289 USD_API
290 static bool IsConcrete(const TfType& primType);
291
294 USD_API
295 static bool IsConcrete(const TfToken& primType);
296
299 USD_API
300 static bool IsAbstract(const TfType& primType);
301
304 USD_API
305 static bool IsAbstract(const TfToken& primType);
306
308 USD_API
309 static bool IsAppliedAPISchema(const TfType& apiSchemaType);
310
312 USD_API
313 static bool IsAppliedAPISchema(const TfToken& apiSchemaType);
314
316 USD_API
317 static bool IsMultipleApplyAPISchema(const TfType& apiSchemaType);
318
320 USD_API
321 static bool IsMultipleApplyAPISchema(const TfToken& apiSchemaType);
322
345 USD_API
346 static TfType GetTypeFromName(const TfToken& typeName);
347
368 USD_API
369 static std::pair<TfToken, TfToken> GetTypeNameAndInstance(
370 const TfToken &apiSchemaName);
371
381 USD_API
383 const TfToken &apiSchemaName,
384 const TfToken &instanceName);
385
398 USD_API
400 const TfToken &apiSchemaName,
401 const TfToken &instanceName = TfToken());
402
411 USD_API
412 static const TokenToTokenVectorMap &GetAutoApplyAPISchemas();
413
425 USD_API
427 TokenToTokenVectorMap *autoApplyAPISchemas);
428
446 USD_API
448 const std::string &namespacePrefix,
449 const std::string &baseName);
450
465 USD_API
467 const std::string &nameTemplate,
468 const std::string &instanceName);
469
479 USD_API
481 const std::string &nameTemplate);
482
491 USD_API
493 const std::string &nameTemplate);
494
499 const TfToken &typeName) const {
500 const auto it = _concreteTypedPrimDefinitions.find(typeName);
501 return it != _concreteTypedPrimDefinitions.end() ?
502 it->second.get() : nullptr;
503 }
504
509 const TfToken &typeName) const {
510 const auto it = _appliedAPIPrimDefinitions.find(typeName);
511 return it != _appliedAPIPrimDefinitions.end() ?
512 it->second.primDef.get() : nullptr;
513 }
514
517 return _emptyPrimDefinition;
518 }
519
524 USD_API
525 std::unique_ptr<UsdPrimDefinition>
527 const TfToken &primType, const TfTokenVector &appliedAPISchemas) const;
528
541 return _fallbackPrimTypes;
542 }
543
544private:
545 friend class TfSingleton<UsdSchemaRegistry>;
546
548
549 using _FamilyAndInstanceToVersionMap =
550 std::unordered_map<std::pair<TfToken, TfToken>, UsdSchemaVersion, TfHash>;
551
552 void _ComposeAPISchemasIntoPrimDefinition(
553 UsdPrimDefinition *primDef,
554 const TfTokenVector &appliedAPISchemas,
555 _FamilyAndInstanceToVersionMap *seenSchemaFamilyVersions) const;
556
557 // Private class for helping initialize the schema registry. Defined
558 // entirely in the implementation. Declared here for private access to the
559 // registry.
560 class _SchemaDefInitHelper;
561
562 std::vector<SdfLayerRefPtr> _schematicsLayers;
563
564 std::unordered_map<TfToken, const std::unique_ptr<UsdPrimDefinition>,
565 TfHash> _concreteTypedPrimDefinitions;
566
567 struct _APISchemaDefinitionInfo {
568 std::unique_ptr<UsdPrimDefinition> primDef;
569 bool applyExpectsInstanceName;
570 };
571 std::unordered_map<TfToken, const _APISchemaDefinitionInfo, TfHash>
572 _appliedAPIPrimDefinitions;
573
574 UsdPrimDefinition *_emptyPrimDefinition;
575
576 VtDictionary _fallbackPrimTypes;
577
578 friend class UsdPrimDefinition;
579};
580
581USD_API_TEMPLATE_CLASS(TfSingleton<UsdSchemaRegistry>);
582
583// Utility function for extracting the metadata about applying API schemas from
584// the plugin metadata for the schema's type. It is useful for certain clients
585// to be able to access this plugin data in the same way that the
586// UsdSchemaRegistry does.
587void Usd_GetAPISchemaPluginApplyToInfoForType(
588 const TfType &apiSchemaType,
589 const TfToken &apiSchemaName,
590 UsdSchemaRegistry::TokenToTokenVectorMap *autoApplyAPISchemasMap,
591 UsdSchemaRegistry::TokenToTokenVectorMap *canOnlyApplyAPISchemasMap,
592 TfHashMap<TfToken, TfToken::Set, TfHash> *allowedInstanceNamesMap);
593
594// Utility for sorting a list of auto-applied API schemas. It is useful for
595// certain clients to be able to make sure they can perform this type of sort
596// in the exact same way as UsdSchemaRegistry does.
597void Usd_SortAutoAppliedAPISchemas(
598 TfTokenVector *autoAppliedAPISchemas);
599
600PXR_NAMESPACE_CLOSE_SCOPE
601
602#endif //PXR_USD_USD_SCHEMA_REGISTRY_H
A subclass of SdfPropertySpec that holds typed data.
Definition: attributeSpec.h:40
A property that contains a reference to one or more SdfPrimSpec instances.
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:460
Manage a single instance of an object (see.
Definition: singleton.h:105
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:120
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Class representing the builtin definition of a prim given the schemas registered in the schema regist...
The base class for all schema types in Usd.
Definition: schemaBase.h:39
Singleton registry that provides access to schema type information and the prim definitions for regis...
static USD_API bool IsAllowedSchemaFamily(const TfToken &schemaFamily)
Returns whether the given schemaFamily is an allowed schema family name.
UsdSchemaVersion version
The version number of the schema within its schema family.
static USD_API std::pair< TfToken, UsdSchemaVersion > ParseSchemaFamilyAndVersionFromIdentifier(const TfToken &schemaIdentifier)
Parses and returns the schema family and version values from the given schemaIdentifier.
static const SchemaInfo * FindSchemaInfo()
Finds and returns the schema info for a registered schema with the C++ schema class SchemaType.
static USD_API TfToken GetMultipleApplyNameTemplateBaseName(const std::string &nameTemplate)
Returns the base name for the multiple apply schema name template nameTemplate.
TfType type
The schema's type as registered with the TfType registry.
const UsdPrimDefinition * FindAppliedAPIPrimDefinition(const TfToken &typeName) const
Finds the prim definition for the given typeName token if typeName is a registered applied API schema...
static USD_API TfToken MakeMultipleApplyNameInstance(const std::string &nameTemplate, const std::string &instanceName)
Returns an instance of a multiple apply schema name from the given nameTemplate for the given instanc...
static USD_API const TfTokenVector & GetAPISchemaCanOnlyApplyToTypeNames(const TfToken &apiSchemaName, const TfToken &instanceName=TfToken())
Returns a list of prim type names that the given apiSchemaName can only be applied to.
static USD_API TfType GetConcreteTypeFromSchemaTypeName(const TfToken &typeName)
Return the TfType of the schema corresponding to the given concrete prim type name typeName.
USD_API std::unique_ptr< UsdPrimDefinition > BuildComposedPrimDefinition(const TfToken &primType, const TfTokenVector &appliedAPISchemas) const
Composes and returns a new UsdPrimDefinition from the given primType and list of appliedSchemas.
const UsdPrimDefinition * GetEmptyPrimDefinition() const
Returns the empty prim definition.
TfToken family
The name of the family of schema's which the schema is a version of.
static USD_API TfToken MakeSchemaIdentifierForFamilyAndVersion(const TfToken &schemaFamily, UsdSchemaVersion schemaVersion)
Creates the schema identifier that would be used to define a schema of the given schemaFamily with th...
VersionPolicy
A policy for filtering by schema version when querying for schemas in a particular schema family.
static USD_API bool IsConcrete(const TfType &primType)
Returns true if the prim type primType is instantiable in scene description.
static USD_API bool IsAbstract(const TfType &primType)
Returns true if the prim type primType is an abstract schema type and, unlike a concrete type,...
static USD_API bool IsMultipleApplyAPISchema(const TfType &apiSchemaType)
Returns true if apiSchemaType is a multiple-apply API schema type.
static USD_API bool IsAppliedAPISchema(const TfToken &apiSchemaType)
Returns true if apiSchemaType is an applied API schema type.
TfToken identifier
The schema's identifier which is how the schema type is referred to in scene description and is also ...
static USD_API bool IsAllowedAPISchemaInstanceName(const TfToken &apiSchemaName, const TfToken &instanceName)
Returns true if the given instanceName is an allowed instance name for the multiple apply API schema ...
static USD_API bool IsAppliedAPISchema(const TfType &apiSchemaType)
Returns true if apiSchemaType is an applied API schema type.
const UsdPrimDefinition * FindConcretePrimDefinition(const TfToken &typeName) const
Finds the prim definition for the given typeName token if typeName is a registered concrete typed sch...
UsdSchemaKind kind
The schema's kind: ConcreteTyped, SingleApplyAPI, etc.
static USD_API bool IsTyped(const TfType &primType)
Returns true if the prim type primType inherits from UsdTyped.
static USD_API std::vector< const SchemaInfo * > FindSchemaInfosInFamily(const TfToken &schemaFamily, UsdSchemaVersion schemaVersion, VersionPolicy versionPolicy)
Finds all schemas in the given schemaFamily, filtered according to the given schemaVersion and versio...
static USD_API const SchemaInfo * FindSchemaInfo(const TfToken &schemaIdentifier)
Finds and returns the schema info for a registered schema with the given schemaIdentifier.
static USD_API bool IsAllowedSchemaIdentifier(const TfToken &schemaIdentifier)
Returns whether the given schemaIdentifier is an allowed schema identifier.
static USD_API TfToken GetConcreteSchemaTypeName(const TfType &schemaType)
Return the type name in the USD schema for concrete prim types only from the given registered schemaT...
static USD_API const std::vector< const SchemaInfo * > & FindSchemaInfosInFamily(const TfToken &schemaFamily)
Finds all schemas in the given schemaFamily and returns their their schema info ordered from highest ...
static TfToken GetSchemaTypeName()
Return the type name in the USD schema for prims or API schemas of the given registered SchemaType.
static USD_API const SchemaInfo * FindSchemaInfo(const TfToken &schemaFamily, UsdSchemaVersion schemaVersion)
Finds and returns the schema info for a registered schema in the given schemaFamily with the given sc...
static USD_API bool IsMultipleApplyAPISchema(const TfToken &apiSchemaType)
Returns true if apiSchemaType is a multiple-apply API schema type.
static USD_API bool IsDisallowedField(const TfToken &fieldName)
Returns true if the field fieldName cannot have fallback values specified in schemas.
const VtDictionary & GetFallbackPrimTypes() const
Returns a dictionary mapping concrete schema prim type names to a VtTokenArray of fallback prim type ...
static USD_API TfToken GetSchemaTypeName(const TfType &schemaType)
Return the type name in the USD schema for prims or API schemas of the given registered schemaType.
static USD_API TfType GetTypeFromSchemaTypeName(const TfToken &typeName)
Return the TfType of the schema corresponding to the given prim or API schema name typeName.
static USD_API std::pair< TfToken, TfToken > GetTypeNameAndInstance(const TfToken &apiSchemaName)
Returns the schema type name and the instance name parsed from the given apiSchemaName.
static USD_API const SchemaInfo * FindSchemaInfo(const TfType &schemaType)
Finds and returns the schema info for a registered schema with the given schemaType.
static USD_API bool IsMultipleApplyNameTemplate(const std::string &nameTemplate)
Returns true if nameTemplate is a multiple apply schema name template.
static USD_API bool IsConcrete(const TfToken &primType)
Returns true if the prim type primType is instantiable in scene description.
static USD_API TfType GetAPITypeFromSchemaTypeName(const TfToken &typeName)
Return the TfType of the schema corresponding to the given API schema type name typeName.
static USD_API const TokenToTokenVectorMap & GetAutoApplyAPISchemas()
Returns a map of the names of all registered auto apply API schemas to the list of type names each is...
static USD_API TfToken MakeMultipleApplyNameTemplate(const std::string &namespacePrefix, const std::string &baseName)
Creates a name template that can represent a property or API schema that belongs to a multiple apply ...
static USD_API UsdSchemaKind GetSchemaKind(const TfToken &typeName)
Returns the kind of the schema the given typeName represents.
static USD_API TfToken GetAPISchemaTypeName(const TfType &schemaType)
Return the type name in the USD schema for API schema types only from the given registered schemaType...
static USD_API TfType GetTypeFromName(const TfToken &typeName)
Finds the TfType of a schema with typeName.
static USD_API UsdSchemaKind GetSchemaKind(const TfType &schemaType)
Returns the kind of the schema the given schemaType represents.
static USD_API bool IsAbstract(const TfToken &primType)
Returns true if the prim type primType is an abstract schema type and, unlike a concrete type,...
static USD_API void CollectAddtionalAutoApplyAPISchemasFromPlugins(TokenToTokenVectorMap *autoApplyAPISchemas)
Collects all the additional auto apply schemas that can be defined in a plugin through "AutoApplyAPIS...
Structure that holds the information about a schema that is registered with the schema registry.
A map with string keys and VtValue values.
Definition: dictionary.h:43
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:112
Manage a single instance of an object.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440