Loading...
Searching...
No Matches
schemaRegistry.h
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_USD_SCHEMA_REGISTRY_H
25#define PXR_USD_USD_SCHEMA_REGISTRY_H
26
27#include "pxr/pxr.h"
28#include "pxr/usd/usd/api.h"
29#include "pxr/usd/usd/common.h"
30
31#include "pxr/usd/sdf/layer.h"
33
34#include "pxr/base/tf/hash.h"
36
37#include <unordered_map>
38#include <vector>
39
40PXR_NAMESPACE_OPEN_SCOPE
41
42SDF_DECLARE_HANDLES(SdfAttributeSpec);
43SDF_DECLARE_HANDLES(SdfRelationshipSpec);
44
45class UsdSchemaBase;
47
49using UsdSchemaVersion = unsigned int;
50
71 UsdSchemaRegistry(const UsdSchemaRegistry&) = delete;
72 UsdSchemaRegistry& operator=(const UsdSchemaRegistry&) = delete;
73public:
74 using TokenToTokenVectorMap =
75 std::unordered_map<TfToken, TfTokenVector, TfHash>;
76
79 struct SchemaInfo {
80
85
90
96
98 UsdSchemaVersion version;
99
102 };
103
104 USD_API
105 static UsdSchemaRegistry& GetInstance() {
107 }
108
121 USD_API
122 static TfToken
124 const TfToken &schemaFamily,
125 UsdSchemaVersion schemaVersion);
126
144 USD_API
145 static std::pair<TfToken, UsdSchemaVersion>
147
155 USD_API
156 static bool
157 IsAllowedSchemaFamily(const TfToken &schemaFamily);
158
168 USD_API
169 static bool
170 IsAllowedSchemaIdentifier(const TfToken &schemaIdentifier);
171
175 USD_API
176 static const SchemaInfo *
177 FindSchemaInfo(const TfType &schemaType);
178
187 template <class SchemaType>
188 static const SchemaInfo *
190 static_assert(std::is_base_of<UsdSchemaBase, SchemaType>::value,
191 "Provided type must derive UsdSchemaBase.");
192 return FindSchemaInfo(SchemaType::_GetStaticTfType());
193 }
194
198 USD_API
199 static const SchemaInfo *
200 FindSchemaInfo(const TfToken &schemaIdentifier);
201
205 USD_API
206 static const SchemaInfo *
207 FindSchemaInfo(const TfToken &schemaFamily, UsdSchemaVersion schemaVersion);
208
211 enum class VersionPolicy {
212 All,
213 GreaterThan,
214 GreaterThanOrEqual,
215 LessThan,
216 LessThanOrEqual
217 };
218
221 USD_API
222 static const std::vector<const SchemaInfo *> &
224 const TfToken &schemaFamily);
225
229 USD_API
230 static std::vector<const SchemaInfo *>
232 const TfToken &schemaFamily,
233 UsdSchemaVersion schemaVersion,
234 VersionPolicy versionPolicy);
235
238 USD_API
239 static TfToken GetSchemaTypeName(const TfType &schemaType);
240
243 template <class SchemaType>
244 static
246 return GetSchemaTypeName(SchemaType::_GetStaticTfType());
247 }
248
251 USD_API
252 static TfToken GetConcreteSchemaTypeName(const TfType &schemaType);
253
256 USD_API
257 static TfToken GetAPISchemaTypeName(const TfType &schemaType);
258
261 USD_API
262 static TfType GetTypeFromSchemaTypeName(const TfToken &typeName);
263
266 USD_API
268
271 USD_API
273
281 USD_API
282 static bool IsDisallowedField(const TfToken &fieldName);
283
285 USD_API
286 static bool IsTyped(const TfType& primType);
287
293 USD_API
294 static UsdSchemaKind GetSchemaKind(const TfType &schemaType);
295
301 USD_API
302 static UsdSchemaKind GetSchemaKind(const TfToken &typeName);
303
306 USD_API
307 static bool IsConcrete(const TfType& primType);
308
311 USD_API
312 static bool IsConcrete(const TfToken& primType);
313
316 USD_API
317 static bool IsAbstract(const TfType& primType);
318
321 USD_API
322 static bool IsAbstract(const TfToken& primType);
323
325 USD_API
326 static bool IsAppliedAPISchema(const TfType& apiSchemaType);
327
329 USD_API
330 static bool IsAppliedAPISchema(const TfToken& apiSchemaType);
331
333 USD_API
334 static bool IsMultipleApplyAPISchema(const TfType& apiSchemaType);
335
337 USD_API
338 static bool IsMultipleApplyAPISchema(const TfToken& apiSchemaType);
339
362 USD_API
363 static TfType GetTypeFromName(const TfToken& typeName);
364
385 USD_API
386 static std::pair<TfToken, TfToken> GetTypeNameAndInstance(
387 const TfToken &apiSchemaName);
388
398 USD_API
400 const TfToken &apiSchemaName,
401 const TfToken &instanceName);
402
415 USD_API
417 const TfToken &apiSchemaName,
418 const TfToken &instanceName = TfToken());
419
428 USD_API
429 static const TokenToTokenVectorMap &GetAutoApplyAPISchemas();
430
442 USD_API
444 TokenToTokenVectorMap *autoApplyAPISchemas);
445
463 USD_API
465 const std::string &namespacePrefix,
466 const std::string &baseName);
467
482 USD_API
484 const std::string &nameTemplate,
485 const std::string &instanceName);
486
496 USD_API
498 const std::string &nameTemplate);
499
508 USD_API
510 const std::string &nameTemplate);
511
516 const TfToken &typeName) const {
517 const auto it = _concreteTypedPrimDefinitions.find(typeName);
518 return it != _concreteTypedPrimDefinitions.end() ?
519 it->second.get() : nullptr;
520 }
521
526 const TfToken &typeName) const {
527 const auto it = _appliedAPIPrimDefinitions.find(typeName);
528 return it != _appliedAPIPrimDefinitions.end() ?
529 it->second.primDef.get() : nullptr;
530 }
531
534 return _emptyPrimDefinition;
535 }
536
541 USD_API
542 std::unique_ptr<UsdPrimDefinition>
544 const TfToken &primType, const TfTokenVector &appliedAPISchemas) const;
545
558 return _fallbackPrimTypes;
559 }
560
561private:
562 friend class TfSingleton<UsdSchemaRegistry>;
563
565
566 using _FamilyAndInstanceToVersionMap =
567 std::unordered_map<std::pair<TfToken, TfToken>, UsdSchemaVersion, TfHash>;
568
569 void _ComposeAPISchemasIntoPrimDefinition(
570 UsdPrimDefinition *primDef,
571 const TfTokenVector &appliedAPISchemas,
572 _FamilyAndInstanceToVersionMap *seenSchemaFamilyVersions) const;
573
574 // Private class for helping initialize the schema registry. Defined
575 // entirely in the implementation. Declared here for private access to the
576 // registry.
577 class _SchemaDefInitHelper;
578
579 std::vector<SdfLayerRefPtr> _schematicsLayers;
580
581 std::unordered_map<TfToken, const std::unique_ptr<UsdPrimDefinition>,
582 TfHash> _concreteTypedPrimDefinitions;
583
584 struct _APISchemaDefinitionInfo {
585 std::unique_ptr<UsdPrimDefinition> primDef;
586 bool applyExpectsInstanceName;
587 };
588 std::unordered_map<TfToken, const _APISchemaDefinitionInfo, TfHash>
589 _appliedAPIPrimDefinitions;
590
591 UsdPrimDefinition *_emptyPrimDefinition;
592
593 VtDictionary _fallbackPrimTypes;
594
595 friend class UsdPrimDefinition;
596};
597
598USD_API_TEMPLATE_CLASS(TfSingleton<UsdSchemaRegistry>);
599
600// Utility function for extracting the metadata about applying API schemas from
601// the plugin metadata for the schema's type. It is useful for certain clients
602// to be able to access this plugin data in the same way that the
603// UsdSchemaRegistry does.
604void Usd_GetAPISchemaPluginApplyToInfoForType(
605 const TfType &apiSchemaType,
606 const TfToken &apiSchemaName,
607 UsdSchemaRegistry::TokenToTokenVectorMap *autoApplyAPISchemasMap,
608 UsdSchemaRegistry::TokenToTokenVectorMap *canOnlyApplyAPISchemasMap,
609 TfHashMap<TfToken, TfToken::Set, TfHash> *allowedInstanceNamesMap);
610
611// Utility for sorting a list of auto-applied API schemas. It is useful for
612// certain clients to be able to make sure they can perform this type of sort
613// in the exact same way as UsdSchemaRegistry does.
614void Usd_SortAutoAppliedAPISchemas(
615 TfTokenVector *autoAppliedAPISchemas);
616
617PXR_NAMESPACE_CLOSE_SCOPE
618
619#endif //PXR_USD_USD_SCHEMA_REGISTRY_H
A subclass of SdfPropertySpec that holds typed data.
Definition: attributeSpec.h:57
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:477
Manage a single instance of an object (see.
Definition: singleton.h:122
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:137
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
TfType represents a dynamic runtime type.
Definition: type.h:65
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
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:56
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:60
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:129
Manage a single instance of an object.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457