Loading...
Searching...
No Matches
UsdValidationRegistry Class Reference

UsdValidationRegistry manages and provides access to UsdValidator / UsdValidatorSuite for USD Validation. More...

#include <validationRegistry.h>

Public Member Functions

USD_API void RegisterPluginValidator (const TfToken &validatorName, const UsdValidateLayerTaskFn &layerTaskFn)
 Register UsdValidator defined in a plugin using validatorName and layerTaskFn with the UsdValidationRegistry.
 
USD_API void RegisterPluginValidator (const TfToken &validatorName, const UsdValidateStageTaskFn &stageTaskFn)
 Register UsdValidator defined in a plugin using validatorName and stageTaskFn with the UsdValidationRegistry.
 
USD_API void RegisterPluginValidator (const TfToken &validatorName, const UsdValidatePrimTaskFn &primTaskFn)
 Register UsdValidator defined in a plugin using validatorName and primTaskFn with the UsdValidationRegistry.
 
USD_API void RegisterValidator (const UsdValidatorMetadata &metadata, const UsdValidateLayerTaskFn &layerTaskFn)
 Register UsdValidator using metadata and layerTaskFn with the UsdValidationRegistry.
 
USD_API void RegisterValidator (const UsdValidatorMetadata &metadata, const UsdValidateStageTaskFn &stageTaskFn)
 Register UsdValidator using metadata and stageTaskFn with the UsdValidationRegistry.
 
USD_API void RegisterValidator (const UsdValidatorMetadata &metadata, const UsdValidatePrimTaskFn &primTaskFn)
 Register UsdValidator using metadata and primTaskFn with the UsdValidationRegistry.
 
USD_API void RegisterPluginValidatorSuite (const TfToken &validatorSuiteName, const std::vector< const UsdValidator * > &containedValidators)
 Register UsdValidatorSuite defined in a plugin using validatorSuiteName and containedValidators with the UsdValidationRegistry.
 
USD_API void RegisterValidatorSuite (const UsdValidatorMetadata &metadata, const std::vector< const UsdValidator * > &containedValidators)
 Register UsdValidatorSuite using metadata and containedValidators with the UsdValidationRegistry.
 
bool HasValidator (const TfToken &validatorName) const
 Return true if a UsdValidator is registered with the name validatorName; false otherwise.
 
bool HasValidatorSuite (const TfToken &suiteName) const
 Return true if a UsdValidatorSuite is registered with the name validatorSuiteName; false otherwise.
 
USD_API std::vector< const UsdValidator * > GetOrLoadAllValidators ()
 Returns a vector of const pointer to UsdValidator corresponding to all validators registered in the UsdValidationRegistry.
 
USD_API const UsdValidatorGetOrLoadValidatorByName (const TfToken &validatorName)
 Returns a const pointer to UsdValidator if validatorName is found in the registry.
 
USD_API std::vector< const UsdValidator * > GetOrLoadValidatorsByName (const TfTokenVector &validatorNames)
 Returns a vector of const pointer to UsdValidator corresponding to validatorNames found in the registry.
 
USD_API std::vector< const UsdValidatorSuite * > GetOrLoadAllValidatorSuites ()
 Returns a vector of const pointer to UsdValidatorSuite corresponding to all validator suites registered in the UsdValidationRegistry.
 
USD_API const UsdValidatorSuiteGetOrLoadValidatorSuiteByName (const TfToken &suiteName)
 Returns a const pointer to UsdValidatorSuite if suiteName is found in the registry.
 
USD_API std::vector< const UsdValidatorSuite * > GetOrLoadValidatorSuitesByName (const TfTokenVector &suiteNames)
 Returns a vector of const pointer to UsdValidatorSuite corresponding to suiteNames found in the registry.
 
USD_API bool GetValidatorMetadata (const TfToken &name, UsdValidatorMetadata *metadata) const
 Returns true if metadata is found in the _validatorNameToMetadata for a validator/suite name, false otherwise.
 
USD_API UsdValidatorMetadataVector GetAllValidatorMetadata () const
 Return vector of all UsdValidatorMetadata known to the registry.
 
USD_API UsdValidatorMetadataVector GetValidatorMetadataForPlugin (const TfToken &pluginName) const
 Returns vector of UsdValidatorMetadata associated with the Validators which belong to the pluginName.
 
USD_API UsdValidatorMetadataVector GetValidatorMetadataForKeyword (const TfToken &keyword) const
 Returns vector of UsdValidatorMetadata associated with the Validators which has the keyword.
 
USD_API UsdValidatorMetadataVector GetValidatorMetadataForSchemaType (const TfToken &schemaType) const
 Returns vector of UsdValidatorMetadata associated with the Validators which has the schemaType.
 
USD_API UsdValidatorMetadataVector GetValidatorMetadataForPlugins (const TfTokenVector &pluginNames) const
 Returns vector of UsdValidatorMetadata associated with the Validators which belong to the pluginNames.
 
USD_API UsdValidatorMetadataVector GetValidatorMetadataForKeywords (const TfTokenVector &keywords) const
 Returns vector of UsdValidatorMetadata associated with the Validators which has at least one of the keywords.
 
USD_API UsdValidatorMetadataVector GetValidatorMetadataForSchemaTypes (const TfTokenVector &schemaTypes) const
 Returns vector of UsdValidatorMetadata associated with the Validators which has at least one of the schameTypes.
 

Static Public Member Functions

static USD_API UsdValidationRegistryGetInstance ()
 

Friends

class TfSingleton< UsdValidationRegistry >
 

Detailed Description

UsdValidationRegistry manages and provides access to UsdValidator / UsdValidatorSuite for USD Validation.

UsdValidationRegistry is a singleton class, which serves as a central registry to hold / own all validators and validatorSuites by their names. 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 UsdValidator, validators are associated with UsdValidateLayerTaskFn, UsdValidateStageTaskFn or UsdValidatePrimTaskFn, which govern how a layer, stage or a prim needs to be validated. UsdValidator / UsdValidatorSuite 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:

{
"Plugins": [
{
"Info": {
"Name": "usd"
"LibraryPath": "@PLUG_INFO_LIBRARY_PATH",
....
....
....
"Validators": {
"keywords" : ["UsdCoreValidators"],
...
"StageMetadataValidator": {
"doc": "Validates stage metadata."
},
...
...
...
}
}
} ]
}

The above example can then be registered in the plugin:

{
UsdValidationRegistry& registry = UsdValidationRegistry::GetInstance();
const TfToken validatorName("usd:StageMetadataValidator");
const UsdValidateStageTaskFn stageTaskFn =
[](const UsdStagePtr &usdStage) {
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.RegisterValidator(validatorName, stageTaskFn);
}
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
UsdValidationRegistry manages and provides access to UsdValidator / UsdValidatorSuite for USD Validat...
USD_API void RegisterValidator(const UsdValidatorMetadata &metadata, const UsdValidateLayerTaskFn &layerTaskFn)
Register UsdValidator using metadata and layerTaskFn with the UsdValidationRegistry.
std::function< UsdValidationErrorVector(const UsdStagePtr &)> UsdValidateStageTaskFn
UsdValidateStageTaskFn: Validation logic operating on a given UsdStage.
Definition: validator.h:98
#define TF_REGISTRY_FUNCTION(KEY_TYPE)
Define a function that is called on demand by TfRegistryManager.
UsdValidationErrorSite is important information available from a ValidationError, which annotates the...
USDGEOM_API TfStaticData< UsdGeomTokensType > UsdGeomTokens
A global variable with static, efficient TfTokens for use in all public USD API.

Clients can also register validators by explicitly providing UsdValidatorMetadata, 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:

{
UsdValidationRegistry& registry = UsdValidationRegistry::GetInstance();
const UsdValidatorMetadata &metadata = GetMetadataToBeRegistered();
const UsdValidateLayerTaskFn &layerTask = GetLayerTaskForValidator();
registry.RegisterValidator(metadata, layerTask);
}
std::function< UsdValidationErrorVector(const SdfLayerHandle &)> UsdValidateLayerTaskFn
UsdValidateLayerTaskFn: Validation logic operating on a given SdfLayerHandle.
Definition: validator.h:95
A structure which describes metadata for a UsdValidator.
Definition: validator.h:46

Usage:

As shown above, UsdValidator or UsdValidatorSuite 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.

See also
UsdValidator
UsdValidatorSuite

Definition at line 142 of file validationRegistry.h.

Member Function Documentation

◆ GetAllValidatorMetadata()

USD_API UsdValidatorMetadataVector GetAllValidatorMetadata ( ) const

Return vector of all UsdValidatorMetadata known to the registry.

◆ GetInstance()

static USD_API UsdValidationRegistry & GetInstance ( )
inlinestatic

Definition at line 148 of file validationRegistry.h.

◆ GetOrLoadAllValidators()

USD_API std::vector< const UsdValidator * > GetOrLoadAllValidators ( )

Returns a vector of const pointer to UsdValidator 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 UsdValidator, if not already loaded. Also note that returned validators will only include validators defined in plugins or any explicitly registered validators before this call.

◆ GetOrLoadAllValidatorSuites()

USD_API std::vector< const UsdValidatorSuite * > GetOrLoadAllValidatorSuites ( )

Returns a vector of const pointer to UsdValidatorSuite 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 UsdValidatorSuite, if not already loaded. Also note that returned suites will only include suites defined in plugins or any explicitly registered suites before this call.

◆ GetOrLoadValidatorByName()

USD_API const UsdValidator * GetOrLoadValidatorByName ( const TfToken validatorName)

Returns a const pointer to UsdValidator 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.

◆ GetOrLoadValidatorsByName()

USD_API std::vector< const UsdValidator * > GetOrLoadValidatorsByName ( const TfTokenVector validatorNames)

Returns a vector of const pointer to UsdValidator 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.

◆ GetOrLoadValidatorSuiteByName()

USD_API const UsdValidatorSuite * GetOrLoadValidatorSuiteByName ( const TfToken suiteName)

Returns a const pointer to UsdValidatorSuite 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.

◆ GetOrLoadValidatorSuitesByName()

USD_API std::vector< const UsdValidatorSuite * > GetOrLoadValidatorSuitesByName ( const TfTokenVector suiteNames)

Returns a vector of const pointer to UsdValidatorSuite 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.

◆ GetValidatorMetadata()

USD_API bool GetValidatorMetadata ( const TfToken name,
UsdValidatorMetadata 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.

◆ GetValidatorMetadataForKeyword()

USD_API UsdValidatorMetadataVector GetValidatorMetadataForKeyword ( const TfToken keyword) const

Returns vector of UsdValidatorMetadata 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.

◆ GetValidatorMetadataForKeywords()

USD_API UsdValidatorMetadataVector GetValidatorMetadataForKeywords ( const TfTokenVector keywords) const

Returns vector of UsdValidatorMetadata associated with the Validators which has at least one of the keywords.

The returned vector is a union of all UsdValidatorMetadata 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.

◆ GetValidatorMetadataForPlugin()

USD_API UsdValidatorMetadataVector GetValidatorMetadataForPlugin ( const TfToken pluginName) const

Returns vector of UsdValidatorMetadata 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.

◆ GetValidatorMetadataForPlugins()

USD_API UsdValidatorMetadataVector GetValidatorMetadataForPlugins ( const TfTokenVector pluginNames) const

Returns vector of UsdValidatorMetadata associated with the Validators which belong to the pluginNames.

The returned vector is a union of all UsdValidatorMetadata 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.

◆ GetValidatorMetadataForSchemaType()

USD_API UsdValidatorMetadataVector GetValidatorMetadataForSchemaType ( const TfToken schemaType) const

Returns vector of UsdValidatorMetadata 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.

◆ GetValidatorMetadataForSchemaTypes()

USD_API UsdValidatorMetadataVector GetValidatorMetadataForSchemaTypes ( const TfTokenVector schemaTypes) const

Returns vector of UsdValidatorMetadata associated with the Validators which has at least one of the schameTypes.

The returned vector is a union of all UsdValidatorMetadata 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.

◆ HasValidator()

bool HasValidator ( const TfToken validatorName) const

Return true if a UsdValidator is registered with the name validatorName; false otherwise.

◆ HasValidatorSuite()

bool HasValidatorSuite ( const TfToken suiteName) const

Return true if a UsdValidatorSuite is registered with the name validatorSuiteName; false otherwise.

◆ RegisterPluginValidator() [1/3]

USD_API void RegisterPluginValidator ( const TfToken validatorName,
const UsdValidateLayerTaskFn layerTaskFn 
)

Register UsdValidator 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.

See also
HasValidator

◆ RegisterPluginValidator() [2/3]

USD_API void RegisterPluginValidator ( const TfToken validatorName,
const UsdValidatePrimTaskFn primTaskFn 
)

Register UsdValidator 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.

See also
HasValidator

◆ RegisterPluginValidator() [3/3]

USD_API void RegisterPluginValidator ( const TfToken validatorName,
const UsdValidateStageTaskFn stageTaskFn 
)

Register UsdValidator 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.

See also
HasValidator

◆ RegisterPluginValidatorSuite()

USD_API void RegisterPluginValidatorSuite ( const TfToken validatorSuiteName,
const std::vector< const UsdValidator * > &  containedValidators 
)

Register UsdValidatorSuite 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 UsdValidatorMetadata::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.

See also
HasValidatorSuite

◆ RegisterValidator() [1/3]

USD_API void RegisterValidator ( const UsdValidatorMetadata metadata,
const UsdValidateLayerTaskFn layerTaskFn 
)

Register UsdValidator 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.

See also
HasValidator

◆ RegisterValidator() [2/3]

USD_API void RegisterValidator ( const UsdValidatorMetadata metadata,
const UsdValidatePrimTaskFn primTaskFn 
)

Register UsdValidator 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.

See also
HasValidator

◆ RegisterValidator() [3/3]

USD_API void RegisterValidator ( const UsdValidatorMetadata metadata,
const UsdValidateStageTaskFn stageTaskFn 
)

Register UsdValidator 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.

See also
HasValidator

◆ RegisterValidatorSuite()

USD_API void RegisterValidatorSuite ( const UsdValidatorMetadata metadata,
const std::vector< const UsdValidator * > &  containedValidators 
)

Register UsdValidatorSuite 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 UsdValidatorMetadata::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.

See also
HasValidatorSuite

Friends And Related Function Documentation

◆ TfSingleton< UsdValidationRegistry >

friend class TfSingleton< UsdValidationRegistry >
friend

Definition at line 480 of file validationRegistry.h.


The documentation for this class was generated from the following file: