Loading...
Searching...
No Matches
fixer.h
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_USD_VALIDATION_USD_VALIDATION_FIXER_H
9#define PXR_USD_VALIDATION_USD_VALIDATION_FIXER_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/tf/token.h"
13#include "pxr/usd/usd/timeCode.h"
14#include "pxr/usdValidation/usdValidation/api.h"
15
16#include <functional>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
21class UsdEditTarget;
22
23using FixerImplFn =
24 std::function<bool(
25 const UsdValidationError& e, const UsdEditTarget& editTarget,
26 const UsdTimeCode& timeCode)>;
27
28using FixerCanApplyFn =
29 std::function<bool(
30 const UsdValidationError& e, const UsdEditTarget& editTarget,
31 const UsdTimeCode& timeCode)>;
32
63{
64public:
65 UsdValidationFixer(const UsdValidationFixer&) = default;
66 UsdValidationFixer& operator=(const UsdValidationFixer&) = default;
67
68 UsdValidationFixer(UsdValidationFixer&&) noexcept = default;
69 UsdValidationFixer& operator=(UsdValidationFixer&&) noexcept = default;
70
84 USDVALIDATION_API
86 const TfToken &name, const std::string &description,
87 const FixerImplFn &fixerImplFn, const FixerCanApplyFn &canApplyFn,
88 const TfTokenVector &keywords = TfTokenVector(),
89 const TfToken &errorName = TfToken());
90
91 ~UsdValidationFixer() = default;
92
94 const TfToken &GetName() const &
95 {
96 return _name;
97 }
98
101 {
102 return std::move(_name);
103 }
104
106 const std::string &GetDescription() const &
107 {
108 return _description;
109 }
110
112 std::string GetDescription() &&
113 {
114 return std::move(_description);
115 }
116
118 const TfToken &GetErrorName() const &
119 {
120 return _errorName;
121 }
122
125 {
126 return std::move(_errorName);
127 }
128
130 USDVALIDATION_API
131 bool IsAssociatedWithErrorName(const TfToken &errorName) const;
132
134 const TfTokenVector &GetKeywords() const &
135 {
136 return _keywords;
137 }
138
141 {
142 return std::move(_keywords);
143 }
144
146 USDVALIDATION_API
147 bool HasKeyword(const TfToken &keyword) const;
148
160 USDVALIDATION_API
162 const UsdValidationError &error, const UsdEditTarget &editTarget,
163 const UsdTimeCode &timeCode = UsdTimeCode::Default()) const;
164
169 USDVALIDATION_API
171 const UsdValidationError &error, const UsdEditTarget &editTarget,
172 const UsdTimeCode &timeCode = UsdTimeCode::Default()) const;
173
174private:
175 TfToken _name;
176 std::string _description;
177 FixerImplFn _fixerImplFn;
178 FixerCanApplyFn _canApplyFn;
179 TfTokenVector _keywords;
180 TfToken _errorName;
181};
182
183PXR_NAMESPACE_CLOSE_SCOPE
184
185#endif // PXR_USD_VALIDATION_USD_VALIDATION_FIXER_H
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Defines a mapping from scene graph paths to Sdf spec paths in a SdfLayer where edits should be direct...
Definition: editTarget.h:64
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Definition: timeCode.h:113
UsdValidationError is an entity returned by a validation task, which is associated with a UsdValidati...
Definition: error.h:237
A UsdValidationFixer represents a fix that can be applied to fix a specific validation error.
Definition: fixer.h:63
TfToken GetName() &&
Return the name of this fixer by-value.
Definition: fixer.h:100
const TfToken & GetErrorName() const &
Returns the error name that this fixer can fix, if any.
Definition: fixer.h:118
USDVALIDATION_API bool ApplyFix(const UsdValidationError &error, const UsdEditTarget &editTarget, const UsdTimeCode &timeCode=UsdTimeCode::Default()) const
Applies the fix for the given error at the given time code and edit target.
TfToken GetErrorName() &&
Returns the error name that this fixer can fix, if any, by-value.
Definition: fixer.h:124
const std::string & GetDescription() const &
Returns the description of this fixer.
Definition: fixer.h:106
USDVALIDATION_API bool IsAssociatedWithErrorName(const TfToken &errorName) const
Returns true if this fixer is associated with the given error name.
const TfToken & GetName() const &
Returns the name of this fixer.
Definition: fixer.h:94
std::string GetDescription() &&
Return the description of this fixer by-value.
Definition: fixer.h:112
TfTokenVector GetKeywords() &&
Return the keywords associated with this fixer by-value.
Definition: fixer.h:140
USDVALIDATION_API bool CanApplyFix(const UsdValidationError &error, const UsdEditTarget &editTarget, const UsdTimeCode &timeCode=UsdTimeCode::Default()) const
Returns true if this fixer can be applied to the given error and edit target; false otherwise.
const TfTokenVector & GetKeywords() const &
Returns the keywords associated with this fixer.
Definition: fixer.h:134
USDVALIDATION_API bool HasKeyword(const TfToken &keyword) const
Returns true if this fixer has the given keyword.
USDVALIDATION_API UsdValidationFixer(const TfToken &name, const std::string &description, const FixerImplFn &fixerImplFn, const FixerCanApplyFn &canApplyFn, const TfTokenVector &keywords=TfTokenVector(), const TfToken &errorName=TfToken())
Construct a UsdValidationFixer with the given name and description.
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