All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
validationContext.h
Go to the documentation of this file.
1//
2// Copyright 2024 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_VALIDATION_CONTEXT_H
8#define PXR_USD_USD_VALIDATION_CONTEXT_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/usd/api.h"
14
15#include "pxr/base/plug/plugin.h"
17#include "pxr/base/tf/token.h"
18#include "pxr/usd/usd/primRange.h"
20#include "pxr/usd/usd/validationError.h"
21
22#include <mutex>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26class TfType;
27class WorkDispatcher;
28
75{
76public:
90 USD_API
91 explicit UsdValidationContext(const TfTokenVector &keywords,
92 bool includeAllAncestors = true);
93
107 USD_API
108 explicit UsdValidationContext(const PlugPluginPtrVector &plugins,
109 bool includeAllAncestors = true);
110
123 USD_API
124 explicit UsdValidationContext(const UsdValidatorMetadataVector &metadata,
125 bool includeAllAncestors = true);
126
137 USD_API
138 explicit UsdValidationContext(const std::vector<TfType> &schemaTypes);
139
145 USD_API
147 const std::vector<const UsdValidator*> &validators);
148
154 USD_API
156 const std::vector<const UsdValidatorSuite*> &suites);
157
174 USD_API
175 UsdValidationErrorVector Validate(const SdfLayerHandle &layer) const;
176
195 USD_API
196 UsdValidationErrorVector Validate(const UsdStagePtr &stage) const;
197
213 USD_API
214 UsdValidationErrorVector Validate(const std::vector<UsdPrim> &prims) const;
215
231 USD_API
232 UsdValidationErrorVector Validate(const UsdPrimRange &prims) const;
233
234private:
235 // helper to initialize UsdValidationContext, given a vector of metadata
236 // and a flag to include all ancestors.
237 void _InitializeFromValidatorMetadata(
238 const UsdValidatorMetadataVector &metadata, bool includeAllAncestors);
239
240 // Distribute the validators into different groups based on the type of
241 // validation to be performed. This method distributes the selected
242 // validators into _layerValidators, _stageValidators, _primValidators and
243 // _schemaTypeValidators.
244 void _DistributeValidators(
245 const std::vector<const UsdValidator*> &validators);
246
247 // Private helper functions to validate layers, stages and prims.
248 void _ValidateLayer(WorkDispatcher &dispatcher,
249 const SdfLayerHandle &layer,
250 UsdValidationErrorVector *errors,
251 std::mutex *errorsMutex) const;
252
253 void _ValidateStage(WorkDispatcher &dispatcher,
254 const UsdStagePtr &stage,
255 UsdValidationErrorVector *errors,
256 std::mutex *errorsMutex) const;
257
258 // Helper function to validate prims. Generalized for UsdPrimRange and
259 // vector of UsdPrims.
260 template <typename T>
261 void _ValidatePrims(WorkDispatcher &dispatcher,
262 const T &prims,
263 UsdValidationErrorVector *errors,
264 std::mutex *errorsMutex) const;
265
266 // Validators catering to a specific schemaType
267 using _SchemaTypeValidatorPair =
268 std::pair<TfToken, std::vector<const UsdValidator*>>;
269 using _SchemaTypeValidatorPairVector =
270 std::vector<_SchemaTypeValidatorPair>;
271
272 // Vectors of selected sets of validators, which will be run for this
273 // UsdValidationContext. Validation tasks will be enqueued for each of these
274 // validators on a given layer / stage or prims (traversed or explicitly
275 // specified).
276 std::vector<const UsdValidator*> _layerValidators;
277 std::vector<const UsdValidator*> _stageValidators;
278 std::vector<const UsdValidator*> _primValidators;
279
280 // validators here will be used to validate prims based on their schema
281 // types, such that:
282 // - For every typed schemaType found in here, prim being validated will be
283 // checked if it satisfies the IsA<schemaType> and validation task will be
284 // enqueued.
285 // - For every applied schemaType found in here, prim's appliedAPISchemas
286 // will be checked and if found, validation task will be enqueued for the
287 // prim.
288 _SchemaTypeValidatorPairVector _schemaTypeValidators;
289};
290
291PXR_NAMESPACE_CLOSE_SCOPE
292
293#endif // PXR_USD_USD_VALIDATION_CONTEXT_H
TfType represents a dynamic runtime type.
Definition: type.h:48
An forward-iterable range that traverses a subtree of prims rooted at a given prim in depth-first ord...
Definition: primRange.h:102
UsdValidationContext provides an interface for managing and running validators on USD layers,...
USD_API UsdValidationErrorVector Validate(const SdfLayerHandle &layer) const
Run validation on the given valid layer by executing the selected validators for this UsdValidationCo...
USD_API UsdValidationContext(const std::vector< TfType > &schemaTypes)
Create a UsdValidationContext by collecting validators using the specified schema types.
USD_API UsdValidationContext(const UsdValidatorMetadataVector &metadata, bool includeAllAncestors=true)
Create a UsdValidationContext by collecting validators using the specified vector of validator metada...
USD_API UsdValidationContext(const PlugPluginPtrVector &plugins, bool includeAllAncestors=true)
Create a UsdValidationContext by collecting validators using the specified vector of plugins.
USD_API UsdValidationErrorVector Validate(const UsdStagePtr &stage) const
Run validation on the given valid stage by executing the selected validators for this UsdValidationCo...
USD_API UsdValidationContext(const std::vector< const UsdValidator * > &validators)
Create a UsdValidationContext by collecting validators using the specified vector of validators.
USD_API UsdValidationContext(const TfTokenVector &keywords, bool includeAllAncestors=true)
Create a UsdValidationContext by collecting validators using the specified keywords.
USD_API UsdValidationErrorVector Validate(const UsdPrimRange &prims) const
Run validation on the given valid prims by executing the selected validators for this UsdValidationCo...
USD_API UsdValidationContext(const std::vector< const UsdValidatorSuite * > &suites)
Create a UsdValidationContext by collecting validators from the specified vector of validator suites.
USD_API UsdValidationErrorVector Validate(const std::vector< UsdPrim > &prims) const
Run validation on the given valid prims by executing the selected validators for this UsdValidationCo...
A work dispatcher runs concurrent tasks.
Definition: dispatcher.h:66
Definitions of basic string utilities in tf.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440