HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
conditionalAbortDiagnosticDelegate.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_UTILS_CONDITIONAL_ABORT_DIAGNOSTIC_DELEGATE_H
8 #define PXR_USD_USD_UTILS_CONDITIONAL_ABORT_DIAGNOSTIC_DELEGATE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usdUtils/api.h"
13 
14 #include <string>
15 #include <vector>
16 
18 
19 class TfPatternMatcher;
20 
21 /// A class which represents the inclusion exclusion filters on which errors
22 /// will be matched
23 /// stringFilters: matching and filtering will be done on explicit string
24 /// of the error/warning
25 /// codePathFilters: matching and filtering will be done on errors/warnings
26 /// coming from a specific usd code path
28 {
29 public:
33  const std::vector<std::string>& stringFilters,
34  const std::vector<std::string>& codePathFilters);
35 
36  const std::vector<std::string>& GetStringFilters() const {
37  return _stringFilters;
38  };
39 
40  const std::vector<std::string>& GetCodePathFilters() const {
41  return _codePathFilters;
42  }
43 
45  void SetStringFilters(const std::vector<std::string>& stringFilters);
47  void SetCodePathFilters(const std::vector<std::string>& codePathFilters);
48 private:
49  std::vector<std::string> _stringFilters;
50  std::vector<std::string> _codePathFilters;
51 };
52 
53 /// A class that allows client application to instantiate a diagnostic delegate
54 /// that can be used to abort operations for a non fatal USD error or warning
55 /// based on immutable include exclude rules defined for this instance.
56 ///
57 /// These rules are regex strings where case sensitive matching is done on
58 /// error/warning text or the location of the code path where the error/warning
59 /// occured.
60 /// Note that these rules will be respected only during the lifetime of the
61 /// delegate.
62 /// Include Rules determine what errors or warnings will cause a fatal abort.
63 /// Exclude Rules determine what errors or warnings matched from the Include
64 /// Rules should not cause the fatal abort.
65 /// Example: to abort on all errors and warnings coming from "*pxr*" codepath
66 /// but not from "*ConditionalAbortDiagnosticDelegate*", a client can create the
67 /// following delegate:
68 ///
69 /// \code
70 /// UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters includeFilters;
71 /// UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters excludeFilters;
72 /// includeFilters.SetCodePathFilters({"*pxr*"});
73 /// excludeFilters.SetCodePathFilters({"*ConditionalAbortDiagnosticDelegate*"});
74 /// UsdUtilsConditionalAbortDiagnosticDelegate delegate =
75 /// UsdUtilsConditionalAbortDiagnosticDelegate(includeFilters,
76 /// excludeFilters);
77 /// \endcode
78 ///
81 {
82 public:
83 
84  /// Constructor to initialize conditionalAbortDiagnosticDelegate.
85  /// Responsible for adding this delegate instance to TfDiagnosticMgr and
86  /// also sets the \p includeFilters and \p excludeFilters
87  /// \note The _includeFilters and _excludeFilters are immutable
91  includeFilters,
93  excludeFilters);
94 
95  /// Handles the removal of this delegate from TfDiagnosticMgr.
98 
101  const UsdUtilsConditionalAbortDiagnosticDelegate& delegate) = delete;
102  UsdUtilsConditionalAbortDiagnosticDelegate& operator=(
103  const UsdUtilsConditionalAbortDiagnosticDelegate& delegate) = delete;
104 
105  // Interface overrides
106  void IssueError(const TfError& err) override;
107  void IssueWarning(const TfWarning& warning) override;
108  void IssueFatalError(const TfCallContext &ctx,
109  const std::string &msg) override;
110  // Following will be no-ops for our purposes - prints same message as
111  // DiagnosticMgr
112  void IssueStatus(const TfStatus& status) override;
113 
114 private:
115 
116  const std::vector<TfPatternMatcher> _includePatternStringFilters;
117  const std::vector<TfPatternMatcher> _includePatternCodePathFilters;
118  const std::vector<TfPatternMatcher> _excludePatternStringFilters;
119  const std::vector<TfPatternMatcher> _excludePatternCodePathFilters;
120 
121 protected:
122  /// Helper to match \p err against a given set of \p errorFilters
123  /// A client can override this to affect the behavior of the rule matcher.
124  virtual bool _RuleMatcher(const TfDiagnosticBase& err,
125  const std::vector<TfPatternMatcher>& stringPatternFilters,
126  const std::vector<TfPatternMatcher>& codePathPatternFilters);
127 };
128 
129 
131 
132 #endif
void IssueError(const TfError &err) override
Called when a TfError is posted.
void IssueWarning(const TfWarning &warning) override
Called when a TF_WARNING() is issued.
USDUTILS_API void SetStringFilters(const std::vector< std::string > &stringFilters)
Definition: error.h:32
void IssueStatus(const TfStatus &status) override
Called when a TF_STATUS() is issued.
UsdUtilsConditionalAbortDiagnosticDelegate & operator=(const UsdUtilsConditionalAbortDiagnosticDelegate &delegate)=delete
void IssueFatalError(const TfCallContext &ctx, const std::string &msg) override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual bool _RuleMatcher(const TfDiagnosticBase &err, const std::vector< TfPatternMatcher > &stringPatternFilters, const std::vector< TfPatternMatcher > &codePathPatternFilters)
USDUTILS_API void SetCodePathFilters(const std::vector< std::string > &codePathFilters)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual USDUTILS_API ~UsdUtilsConditionalAbortDiagnosticDelegate()
Handles the removal of this delegate from TfDiagnosticMgr.
#define USDUTILS_API
Definition: api.h:23