HDK
|
#include <registry.h>
Static Public Member Functions | |
static USDVALIDATION_API UsdValidationRegistry & | GetInstance () |
Friends | |
class | TfSingleton< UsdValidationRegistry > |
UsdValidationRegistry manages and provides access to UsdValidationValidator / UsdValidationValidatorSuite for USD Validation.
UsdValidationRegistry is a singleton class, which serves as a central registry to hold / own all validators and validatorSuites by their names. UsdValidationRegistry is also immortal and its singleton instance is never destroyed. This is to ensure that all validators and suites registered with the registry are available throughout the lifetime of the application.
Both Core USD and client-provided validators are registered with the registry. Validators can be registered and retrieved dynamically, supporting complex validation scenarios across different modules or plugins.
Clients of USD can register validators either via plugin infrastructure, which results in lazy loading of the validators, or explicitly register validators in their code via appropriate APIs.
As discussed in UsdValidationValidator, validators are associated with UsdValidateLayerTaskFn, UsdValidateStageTaskFn or UsdValidatePrimTaskFn, which govern how a layer, stage or a prim needs to be validated. UsdValidationValidator / UsdValidationValidatorSuite also have metadata, which can either be provided in the plugInfo.json when registering the validators via plugin mechanism, or by providing metadata field when registering validators.
Example of registering a validator named "StageMetadataValidator" with doc metadata using plufInfo.json:
The above example can then be registered in the plugin:
```cpp TF_REGISTRY_FUNCTION(UsdValidationRegistry) { UsdValidationRegistry& registry = UsdValidationRegistry::GetInstance(); const TfToken validatorName("usdValidation:StageMetadataValidator"); const UsdValidateStageTaskFn stageTaskFn = [](const UsdStagePtr &usdStage, const UsdValidationTimeRange &timeRange) { UsdValidationErrorVector errors; if (!usdStage->GetDefaultPrim()) { errors.emplace_back(UsdValidationErrorType::Error, {UsdValidationErrorSite(usdStage, SdfPath("/"))}, "Stage has missing or invalid defaultPrim."); } if (!usdStage->HasAuthoredMetadata( UsdGeomTokens->metersPerUnit)) { errors.emplace_back(UsdValidationErrorType::Error, {UsdValidationErrorSite(usdStage, SdfPath("/"))}, "Stage does not specify its linear scale in " "metersPerUnit."); } if (!usdStage->HasAuthoredMetadata( UsdGeomTokens->upAxis)) { errors.emplace_back(UsdValidationErrorType::Error, {UsdValidationErrorSite(usdStage, SdfPath("/"))}, "Stage does not specify an upAxis."); } return errors; }; registry.RegisterPluginValidator(validatorName, stageTaskFn); } ```
Clients can also register validators by explicitly providing UsdValidationValidatorMetadata, instead of relying on plugInfo.json for the same. Though its recommended to use appropriate APIs when validator metadata is being provided in the plugInfo.json.
Example of validator registration by explicitly providing metadata, when its not available in the plugInfo.json:
```cpp { UsdValidationRegistry& registry = UsdValidationRegistry::GetInstance(); const UsdValidationValidatorMetadata &metadata = GetMetadataToBeRegistered(); const UsdValidateLayerTaskFn &layerTask = GetLayerTaskForValidator(); registry.RegisterValidator(metadata, layerTask); } ```
Usage:
As shown above, UsdValidationValidator or UsdValidationValidatorSuite can be registered using specific metadata or names, and retrieved by their name. The registry also provides functionality to check the existence of a validator / suite, load validators / suites dynamically if they are not in the registry.
Clients can also retrieve metadata for validators associated with a specific plugin, keywords or schemaTypes, this can help clients filter out relevant validators they need to validate their context / scene.
Note that this class is designed to be thread-safe: Querying of validator metadata, registering new validator (hence mutating the registry) or retrieving previously registered validator are designed to be thread-safe.
Definition at line 150 of file registry.h.
USDVALIDATION_API UsdValidationValidatorMetadataVector UsdValidationRegistry::GetAllValidatorMetadata | ( | ) | const |
Return vector of all UsdValidationValidatorMetadata known to the registry
|
inlinestatic |
Definition at line 157 of file registry.h.
USDVALIDATION_API std::vector<const UsdValidationValidator *> UsdValidationRegistry::GetOrLoadAllValidators | ( | ) |
Returns a vector of const pointer to UsdValidationValidator corresponding to all validators registered in the UsdValidationRegistry.
If a validator is not found in the registry, this method will load appropriate plugins, if the validator is made available via a plugin.
Note that this call will load in many plugins which provide a UsdValidationValidator, if not already loaded. Also note that returned validators will only include validators defined in plugins or any explicitly registered validators before this call.
USDVALIDATION_API std::vector<const UsdValidationValidatorSuite *> UsdValidationRegistry::GetOrLoadAllValidatorSuites | ( | ) |
Returns a vector of const pointer to UsdValidationValidatorSuite corresponding to all validator suites registered in the UsdValidationRegistry.
If a suite is not found in the registry, this method will load appropriate plugins, if the suite is made available via a plugin.
Note that this call might load in many plugins which provide a UsdValidationValidatorSuite, if not already loaded. Also note that returned suites will only include suites defined in plugins or any explicitly registered suites before this call.
USDVALIDATION_API const UsdValidationValidator* UsdValidationRegistry::GetOrLoadValidatorByName | ( | const TfToken & | validatorName | ) |
Returns a const pointer to UsdValidationValidator if validatorName
is found in the registry.
If a validator is not found in the registry, this method will load appropriate plugins, if the validator is made available via a plugin.
Returns a nullptr if no validator is found.
USDVALIDATION_API std::vector<const UsdValidationValidator *> UsdValidationRegistry::GetOrLoadValidatorsByName | ( | const TfTokenVector & | validatorNames | ) |
Returns a vector of const pointer to UsdValidationValidator corresponding to validatorNames
found in the registry.
If a validator is not found in the registry, this method will load appropriate plugins, if the validator is made available via a plugin.
Size of returned vector might be less than the size of the input validatorNames, in case of missing validators.
USDVALIDATION_API const UsdValidationValidatorSuite* UsdValidationRegistry::GetOrLoadValidatorSuiteByName | ( | const TfToken & | suiteName | ) |
Returns a const pointer to UsdValidationValidatorSuite if suiteName
is found in the registry.
If a suite is not found in the registry, this method will load appropriate plugins, if the suite is made available via a plugin.
Returns a nullptr if no validator is found.
USDVALIDATION_API std::vector<const UsdValidationValidatorSuite *> UsdValidationRegistry::GetOrLoadValidatorSuitesByName | ( | const TfTokenVector & | suiteNames | ) |
Returns a vector of const pointer to UsdValidationValidatorSuite corresponding to suiteNames
found in the registry.
If a suite is not found in the registry, this method will load appropriate plugins, if the suite is made available via a plugin.
Size of returned vector might be less than the size of the input suiteNames, in case of missing validators.
USDVALIDATION_API bool UsdValidationRegistry::GetValidatorMetadata | ( | const TfToken & | name, |
UsdValidationValidatorMetadata * | metadata | ||
) | const |
Returns true if metadata is found in the _validatorNameToMetadata for a validator/suite name, false otherwise.
metadata
parameter is used as an out parameter here.
USDVALIDATION_API UsdValidationValidatorMetadataVector UsdValidationRegistry::GetValidatorMetadataForKeyword | ( | const TfToken & | keyword | ) | const |
Returns vector of UsdValidationValidatorMetadata associated with the Validators which has the keyword
.
This API can be used to curate a vector of validator metadata, that clients may want to load and use in their validation context.
Note that this method does not result in any plugins to be loaded.
USDVALIDATION_API UsdValidationValidatorMetadataVector UsdValidationRegistry::GetValidatorMetadataForKeywords | ( | const TfTokenVector & | keywords | ) | const |
Returns vector of UsdValidationValidatorMetadata associated with the Validators which has at least one of the keywords
.
The returned vector is a union of all UsdValidationValidatorMetadata associated with the keywords.
This API can be used to curate a vector of validator metadata, that clients may want to load and use in their validation context.
Note that this method does not result in any plugins to be loaded.
USDVALIDATION_API UsdValidationValidatorMetadataVector UsdValidationRegistry::GetValidatorMetadataForPlugin | ( | const TfToken & | pluginName | ) | const |
Returns vector of UsdValidationValidatorMetadata associated with the Validators which belong to the pluginName
.
This API can be used to curate a vector of validator metadata, that clients may want to load and use in their validation context.
Note that this method does not result in any plugins to be loaded.
USDVALIDATION_API UsdValidationValidatorMetadataVector UsdValidationRegistry::GetValidatorMetadataForPlugins | ( | const TfTokenVector & | pluginNames | ) | const |
Returns vector of UsdValidationValidatorMetadata associated with the Validators which belong to the pluginNames
.
The returned vector is a union of all UsdValidationValidatorMetadata associated with the plugins.
This API can be used to curate a vector of validator metadata, that clients may want to load and use in their validation context.
Note that this method does not result in any plugins to be loaded.
USDVALIDATION_API UsdValidationValidatorMetadataVector UsdValidationRegistry::GetValidatorMetadataForSchemaType | ( | const TfToken & | schemaType | ) | const |
Returns vector of UsdValidationValidatorMetadata associated with the Validators which has the schemaType
.
This API can be used to curate a vector of validator metadata, that clients may want to load and use in their validation context.
Note that this method does not result in any plugins to be loaded.
USDVALIDATION_API UsdValidationValidatorMetadataVector UsdValidationRegistry::GetValidatorMetadataForSchemaTypes | ( | const TfTokenVector & | schemaTypes | ) | const |
Returns vector of UsdValidationValidatorMetadata associated with the Validators which has at least one of the schameTypes
.
The returned vector is a union of all UsdValidationValidatorMetadata associated with the schemaTypes.
This API can be used to curate a vector of validator metadata, that clients may want to load and use in their validation context.
Note that this method does not result in any plugins to be loaded.
USDVALIDATION_API bool UsdValidationRegistry::HasValidator | ( | const TfToken & | validatorName | ) | const |
Return true if a UsdValidationValidator is registered with the name validatorName
; false otherwise.
USDVALIDATION_API bool UsdValidationRegistry::HasValidatorSuite | ( | const TfToken & | suiteName | ) | const |
Return true if a UsdValidationValidatorSuite is registered with the name validatorSuiteName
; false otherwise.
USDVALIDATION_API void UsdValidationRegistry::RegisterPluginValidator | ( | const TfToken & | validatorName, |
const UsdValidateLayerTaskFn & | layerTaskFn | ||
) |
Register UsdValidationValidator defined in a plugin using validatorName
and layerTaskFn
with the UsdValidationRegistry.
Here validatorName
should include the name of the plugin the validator belongs to, delimited by ":".
Note calling RegisterPluginValidator with a validatorName which is already registered will result in a coding error. HasValidator can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
USDVALIDATION_API void UsdValidationRegistry::RegisterPluginValidator | ( | const TfToken & | validatorName, |
const UsdValidateStageTaskFn & | stageTaskFn | ||
) |
Register UsdValidationValidator defined in a plugin using validatorName
and stageTaskFn
with the UsdValidationRegistry.
Here validatorName
should include the name of the plugin the validator belongs to, delimited by ":".
Note calling RegisterPluginValidator with a validatorName which is already registered will result in a coding error. HasValidator can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
USDVALIDATION_API void UsdValidationRegistry::RegisterPluginValidator | ( | const TfToken & | validatorName, |
const UsdValidatePrimTaskFn & | primTaskFn | ||
) |
Register UsdValidationValidator defined in a plugin using validatorName
and primTaskFn
with the UsdValidationRegistry.
Here validatorName
should include the name of the plugin the validator belongs to, delimited by ":".
Note calling RegisterPluginValidator with a validatorName which is already registered will result in a coding error. HasValidator can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
USDVALIDATION_API void UsdValidationRegistry::RegisterPluginValidatorSuite | ( | const TfToken & | validatorSuiteName, |
const std::vector< const UsdValidationValidator * > & | containedValidators | ||
) |
Register UsdValidationValidatorSuite defined in a plugin using validatorSuiteName
and containedValidators
with the UsdValidationRegistry.
Here validatorSuiteName
should include the name of the plugin the validator belongs to, delimited by ":".
Note UsdValidationValidatorMetadata::isSuite must be set to true in the plugInfo, else the validatorSuite will not be registered.
Note calling RegisterPluginValidatorSuite with a validatorSuiteName which is already registered will result in a coding error. HasValidatorSuite can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
USDVALIDATION_API void UsdValidationRegistry::RegisterValidator | ( | const UsdValidationValidatorMetadata & | metadata, |
const UsdValidateLayerTaskFn & | layerTaskFn | ||
) |
Register UsdValidationValidator using metadata
and layerTaskFn
with the UsdValidationRegistry.
Clients can explicitly provide validator metadata, which is then used to register a validator and associate it with name metadata. The metadata here is not specified in a plugInfo.
Note calling RegisterValidator with a validator name which is already registered will result in a coding error. HasValidator can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
USDVALIDATION_API void UsdValidationRegistry::RegisterValidator | ( | const UsdValidationValidatorMetadata & | metadata, |
const UsdValidateStageTaskFn & | stageTaskFn | ||
) |
Register UsdValidationValidator using metadata
and stageTaskFn
with the UsdValidationRegistry.
Clients can explicitly provide validator metadata, which is then used to register a validator and associate it with name metadata. The metadata here is not specified in a plugInfo.
Note calling RegisterValidator with a validator name which is already registered will result in a coding error. HasValidator can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
USDVALIDATION_API void UsdValidationRegistry::RegisterValidator | ( | const UsdValidationValidatorMetadata & | metadata, |
const UsdValidatePrimTaskFn & | primTaskFn | ||
) |
Register UsdValidationValidator using metadata
and primTaskFn
with the UsdValidationRegistry.
Clients can explicitly provide validator metadata, which is then used to register a validator and associate it with name metadata. The metadata here is not specified in a plugInfo.
Note calling RegisterValidator with a validator name which is already registered will result in a coding error. HasValidator can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
USDVALIDATION_API void UsdValidationRegistry::RegisterValidatorSuite | ( | const UsdValidationValidatorMetadata & | metadata, |
const std::vector< const UsdValidationValidator * > & | containedValidators | ||
) |
Register UsdValidationValidatorSuite using metadata
and containedValidators
with the UsdValidationRegistry.
Clients can explicitly provide validator metadata, which is then used to register a suite and associate it with name metadata. The metadata here is not specified in a plugInfo.
Note UsdValidationValidatorMetadata::isSuite must be set to true in the plugInfo, else the validatorSuite will not be registered.
Note calling RegisterPluginValidatorSuite with a validatorSuiteName which is already registered will result in a coding error. HasValidatorSuite can be used to determine if a validator is already registered and associated with validatorName.
Also note any other failure to register a validator results in a coding error.
|
friend |
Definition at line 500 of file registry.h.