All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 TF_DIAGNOSTIC_BASE_H
25 #define TF_DIAGNOSTIC_BASE_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/base/tf/callContext.h"
31 #include "pxr/base/tf/enum.h"
32 #include "pxr/base/tf/refBase.h"
33 #include "pxr/base/tf/stringUtils.h"
34 #include "pxr/base/tf/weakPtr.h"
35 
36 #include "pxr/base/arch/inttypes.h"
37 #include "pxr/base/arch/attributes.h"
38 #include "pxr/base/arch/function.h"
39 
40 #include <boost/any.hpp>
41 #include <cstdarg>
42 #include <string>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 typedef boost::any TfDiagnosticInfo;
47 
48 class TfDiagnosticMgr;
49 
65 public:
66 
68  const TfCallContext &GetContext() const {
69  return _context;
70  }
71 
73  std::string GetSourceFileName() const {
74  return _context.GetFile();
75  }
76 
79  size_t GetSourceLineNumber() const {
80  return _context.GetLine();
81  }
82 
84  std::string const &GetCommentary() const {
85  return _commentary;
86  }
87 
89  std::string GetSourceFunction() const {
90  return ArchGetPrettierFunctionName(_context.GetFunction(),
91  _context.GetPrettyFunction());
92  }
93 
104  void AugmentCommentary(const std::string& s) {
105  if (_commentary.empty())
106  _commentary = s;
107  else {
108  _commentary += "\n";
109  _commentary += s;
110  }
111  }
112 
115  return _code;
116  }
117 
118 
137  const std::string& GetDiagnosticCodeAsString() const {
138  return _codeString;
139  }
140 
160  template <typename T>
161  const T* GetInfo() const {
162  return boost::any_cast<T>(&_info);
163  }
164 
167  void SetInfo(TfDiagnosticInfo any) {
168  _info = any;
169  }
170 
177  bool GetQuiet() const {
178  return _quiet;
179  }
180 
182  std::string GetPrettyPrintString() const;
183 
185  bool IsFatal() const;
186 
189  bool IsCodingError() const;
190 
192  TfDiagnosticBase(TfEnum code, char const *codeString,
193  TfCallContext const &context,
194  const std::string& commentary,
195  TfDiagnosticInfo info, bool quiet);
196 
197 protected:
198  TfCallContext _context;
199 
200  std::string _commentary;
201  TfEnum _code;
202  std::string _codeString;
203  TfDiagnosticInfo _info;
204  size_t _serial = 0;
205  bool _quiet = false;
206 
207  friend class TfDiagnosticMgr;
208  friend class TfErrorTransport;
209  friend class TfErrorMark;
210 };
211 
212 PXR_NAMESPACE_CLOSE_SCOPE
213 
214 #endif // TF_DIAGNOSTIC_BASE_H
std::string GetSourceFileName() const
Return the source file name that the diagnostic message was posted from.
Singleton class through which all errors and diagnostics pass.
Definition: diagnosticMgr.h:70
void SetInfo(TfDiagnosticInfo any)
Set the info object associated with this diagnostic message.
const std::string & GetDiagnosticCodeAsString() const
Return the diagnostic code posted as a string.
An enum class that records both enum type and enum value.
Definition: enum.h:140
size_t GetSourceLineNumber() const
Return the source line number that the diagnostic message was posted from.
std::string GetPrettyPrintString() const
Return the commentary string.
const TfCallContext & GetContext() const
Return the call context where the message was issued.
TfDiagnosticBase(TfEnum code, char const *codeString, TfCallContext const &context, const std::string &commentary, TfDiagnosticInfo info, bool quiet)
Construct an instance.
std::string GetSourceFunction() const
Return the source function that the diagnostic message was posted from.
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
bool IsCodingError() const
Return true if this diagnostic&#39;s code is either a fatal or nonfatal coding error. ...
bool IsFatal() const
Return true if this diagnostic&#39;s code is a fatal code.
TfEnum GetDiagnosticCode() const
Return the diagnostic code posted.
bool GetQuiet() const
Return true if the message was posted via PostQuietly().
const T * GetInfo() const
Return a (possibly NULL) const pointer to the info object associated with this message.
std::string const & GetCommentary() const
Return the commentary string describing this diagnostic message.
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.