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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_USD_UTILS_CONDITIONAL_ABORT_DIAGNOSTIC_DELEGATE_H
25 #define PXR_USD_USD_UTILS_CONDITIONAL_ABORT_DIAGNOSTIC_DELEGATE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdUtils/api.h"
30 
31 #include <string>
32 #include <vector>
33 
35 
36 class TfPatternMatcher;
37 
38 /// A class which represents the inclusion exclusion filters on which errors
39 /// will be matched
40 /// stringFilters: matching and filtering will be done on explicit string
41 /// of the error/warning
42 /// codePathFilters: matching and filtering will be done on errors/warnings
43 /// coming from a specific usd code path
45 {
46 public:
50  const std::vector<std::string>& stringFilters,
51  const std::vector<std::string>& codePathFilters);
52 
53  const std::vector<std::string>& GetStringFilters() const {
54  return _stringFilters;
55  };
56 
57  const std::vector<std::string>& GetCodePathFilters() const {
58  return _codePathFilters;
59  }
60 
62  void SetStringFilters(const std::vector<std::string>& stringFilters);
64  void SetCodePathFilters(const std::vector<std::string>& codePathFilters);
65 private:
66  std::vector<std::string> _stringFilters;
67  std::vector<std::string> _codePathFilters;
68 };
69 
70 /// A class that allows client application to instantiate a diagnostic delegate
71 /// that can be used to abort operations for a non fatal USD error or warning
72 /// based on immutable include exclude rules defined for this instance.
73 ///
74 /// These rules are regex strings where case sensitive matching is done on
75 /// error/warning text or the location of the code path where the error/warning
76 /// occured.
77 /// Note that these rules will be respected only during the lifetime of the
78 /// delegate.
79 /// Include Rules determine what errors or warnings will cause a fatal abort.
80 /// Exclude Rules determine what errors or warnings matched from the Include
81 /// Rules should not cause the fatal abort.
82 /// Example: to abort on all errors and warnings coming from "*pxr*" codepath
83 /// but not from "*ConditionalAbortDiagnosticDelegate*", a client can create the
84 /// following delegate:
85 ///
86 /// \code
87 /// UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters includeFilters;
88 /// UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters excludeFilters;
89 /// includeFilters.SetCodePathFilters({"*pxr*"});
90 /// excludeFilters.SetCodePathFilters({"*ConditionalAbortDiagnosticDelegate*"});
91 /// UsdUtilsConditionalAbortDiagnosticDelegate delegate =
92 /// UsdUtilsConditionalAbortDiagnosticDelegate(includeFilters,
93 /// excludeFilters);
94 /// \endcode
95 ///
98 {
99 public:
100 
101  /// Constructor to initialize conditionalAbortDiagnosticDelegate.
102  /// Responsible for adding this delegate instance to TfDiagnosticMgr and
103  /// also sets the \p includeFilters and \p excludeFilters
104  /// \note The _includeFilters and _excludeFilters are immutable
108  includeFilters,
110  excludeFilters);
111 
112  /// Handles the removal of this delegate from TfDiagnosticMgr.
115 
118  const UsdUtilsConditionalAbortDiagnosticDelegate& delegate) = delete;
119  UsdUtilsConditionalAbortDiagnosticDelegate& operator=(
120  const UsdUtilsConditionalAbortDiagnosticDelegate& delegate) = delete;
121 
122  // Interface overrides
123  void IssueError(const TfError& err) override;
124  void IssueWarning(const TfWarning& warning) override;
125  void IssueFatalError(const TfCallContext &ctx,
126  const std::string &msg) override;
127  // Following will be no-ops for our purposes - prints same message as
128  // DiagnosticMgr
129  void IssueStatus(const TfStatus& status) override;
130 
131 private:
132 
133  const std::vector<TfPatternMatcher> _includePatternStringFilters;
134  const std::vector<TfPatternMatcher> _includePatternCodePathFilters;
135  const std::vector<TfPatternMatcher> _excludePatternStringFilters;
136  const std::vector<TfPatternMatcher> _excludePatternCodePathFilters;
137 
138 protected:
139  /// Helper to match \p err against a given set of \p errorFilters
140  /// A client can override this to affect the behavior of the rule matcher.
141  virtual bool _RuleMatcher(const TfDiagnosticBase& err,
142  const std::vector<TfPatternMatcher>& stringPatternFilters,
143  const std::vector<TfPatternMatcher>& codePathPatternFilters);
144 };
145 
146 
148 
149 #endif
void IssueError(const TfError &err) override
Called when a TfError is posted.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:49
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:1432
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:91
virtual USDUTILS_API ~UsdUtilsConditionalAbortDiagnosticDelegate()
Handles the removal of this delegate from TfDiagnosticMgr.
#define USDUTILS_API
Definition: api.h:40