diagnosticBase.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_BASE_TF_DIAGNOSTIC_BASE_H
25 #define PXR_BASE_TF_DIAGNOSTIC_BASE_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/base/tf/api.h"
32 #include "pxr/base/tf/enum.h"
33 #include "pxr/base/tf/refBase.h"
35 #include "pxr/base/tf/weakPtr.h"
36 
37 #include "pxr/base/arch/inttypes.h"
39 #include "pxr/base/arch/function.h"
40 
41 #include <boost/any.hpp>
42 #include <cstdarg>
43 #include <string>
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 typedef boost::any TfDiagnosticInfo;
48 
49 class TfDiagnosticMgr;
50 
66 public:
67 
69  const TfCallContext &GetContext() const {
70  return _context;
71  }
72 
74  std::string GetSourceFileName() const {
75  return _context.GetFile();
76  }
77 
80  size_t GetSourceLineNumber() const {
81  return _context.GetLine();
82  }
83 
85  std::string const &GetCommentary() const {
86  return _commentary;
87  }
88 
90  std::string GetSourceFunction() const {
91  return ArchGetPrettierFunctionName(_context.GetFunction(),
92  _context.GetPrettyFunction());
93  }
94 
105  void AugmentCommentary(const std::string& s) {
106  if (_commentary.empty())
107  _commentary = s;
108  else {
109  _commentary += "\n";
110  _commentary += s;
111  }
112  }
113 
116  return _code;
117  }
118 
119 
138  const std::string& GetDiagnosticCodeAsString() const {
139  return _codeString;
140  }
141 
161  template <typename T>
162  const T* GetInfo() const {
163  return boost::any_cast<T>(&_info);
164  }
165 
168  void SetInfo(TfDiagnosticInfo any) {
169  _info = any;
170  }
171 
178  bool GetQuiet() const {
179  return _quiet;
180  }
181 
183  TF_API
184  bool IsFatal() const;
185 
188  TF_API
189  bool IsCodingError() const;
190 
192  TF_API
193  TfDiagnosticBase(TfEnum code, char const *codeString,
194  TfCallContext const &context,
195  const std::string& commentary,
196  TfDiagnosticInfo info, bool quiet);
197 
198 protected:
199  TfCallContext _context;
200 
201  std::string _commentary;
202  TfEnum _code;
203  std::string _codeString;
204  TfDiagnosticInfo _info;
205  size_t _serial = 0;
206  bool _quiet = false;
207 
208  friend class TfDiagnosticMgr;
209  friend class TfErrorTransport;
210  friend class TfErrorMark;
211 };
212 
213 PXR_NAMESPACE_CLOSE_SCOPE
214 
215 #endif // PXR_BASE_TF_DIAGNOSTIC_BASE_H
Define preprocessor function name macros.
Singleton class through which all errors and diagnostics pass.
Definition: diagnosticMgr.h:71
std::string GetSourceFunction() const
Return the source function that the diagnostic message was posted from.
Functions for recording call locations.
void SetInfo(TfDiagnosticInfo any)
Set the info object associated with this diagnostic message.
TF_API TfDiagnosticBase(TfEnum code, char const *codeString, TfCallContext const &context, const std::string &commentary, TfDiagnosticInfo info, bool quiet)
Construct an instance.
Define function attributes.
Definitions of basic string utilities in tf.
TF_API bool IsCodingError() const
Return true if this diagnostic's code is either a fatal or nonfatal coding error.
An enum class that records both enum type and enum value.
Definition: enum.h:139
const std::string & GetDiagnosticCodeAsString() const
Return the diagnostic code posted as a string.
Pointer storage with deletion detection.
size_t GetSourceLineNumber() const
Return the source line number that the diagnostic message was posted from.
const TfCallContext & GetContext() const
Return the call context where the message was issued.
Represents the base class of an object representing a diagnostic message.
void AugmentCommentary(const std::string &s)
Add to the commentary string describing this diagnostic message.
Class used to record the end of the error-list.
Definition: errorMark.h:66
std::string const & GetCommentary() const
Return the commentary string describing this diagnostic message.
Define integral types.
TF_API bool IsFatal() const
Return true if this diagnostic's code is a fatal code.
const T * GetInfo() const
Return a (possibly NULL) const pointer to the info object associated with this message.
std::string GetSourceFileName() const
Return the source file name that the diagnostic message was posted from.
TfEnum GetDiagnosticCode() const
Return the diagnostic code posted.
bool GetQuiet() const
Return true if the message was posted via PostQuietly().
ARCH_API std::string ArchGetPrettierFunctionName(const std::string &function, const std::string &prettyFunction)
Return well formatted function name.
A facility for transporting errors from thread to thread.