Loading...
Searching...
No Matches
diagnosticBase.h
Go to the documentation of this file.
1//
2// Copyright 2016 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_BASE_TF_DIAGNOSTIC_BASE_H
8#define PXR_BASE_TF_DIAGNOSTIC_BASE_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/base/tf/api.h"
15#include "pxr/base/tf/enum.h"
16#include "pxr/base/tf/refBase.h"
18#include "pxr/base/tf/weakPtr.h"
19
23
24#include <any>
25#include <cstdarg>
26#include <string>
27
28PXR_NAMESPACE_OPEN_SCOPE
29
30typedef std::any TfDiagnosticInfo;
31
32class TfDiagnosticMgr;
33
49public:
50
52 const TfCallContext &GetContext() const {
53 return _context;
54 }
55
57 std::string GetSourceFileName() const {
58 if (_context.GetFile()) {
59 return _context.GetFile();
60 }
61 return std::string();
62 }
63
66 size_t GetSourceLineNumber() const {
67 return _context.GetLine();
68 }
69
71 std::string const &GetCommentary() const {
72 return _commentary;
73 }
74
76 std::string GetSourceFunction() const {
77 if (_context.GetFunction() && _context.GetPrettyFunction()) {
78 return ArchGetPrettierFunctionName(_context.GetFunction(),
79 _context.GetPrettyFunction());
80 }
81 return std::string();
82 }
83
94 void AugmentCommentary(const std::string& s) {
95 if (_commentary.empty())
96 _commentary = s;
97 else {
98 _commentary += "\n";
99 _commentary += s;
100 }
101 }
102
105 return _code;
106 }
107
108
127 const std::string& GetDiagnosticCodeAsString() const {
128 return _codeString;
129 }
130
150 template <typename T>
151 const T* GetInfo() const {
152 return std::any_cast<T>(&_info);
153 }
154
157 void SetInfo(TfDiagnosticInfo any) {
158 _info = any;
159 }
160
167 bool GetQuiet() const {
168 return _quiet;
169 }
170
172 TF_API
173 bool IsFatal() const;
174
177 TF_API
178 bool IsCodingError() const;
179
181 TF_API
182 TfDiagnosticBase(TfEnum code, char const *codeString,
183 TfCallContext const &context,
184 const std::string& commentary,
185 TfDiagnosticInfo info, bool quiet);
186
187protected:
188 TfCallContext _context;
189
190 std::string _commentary;
191 TfEnum _code;
192 std::string _codeString;
193 TfDiagnosticInfo _info;
194 size_t _serial = 0;
195 bool _quiet = false;
196
197 friend class TfDiagnosticMgr;
198 friend class TfErrorTransport;
199 friend class TfErrorMark;
200};
201
202PXR_NAMESPACE_CLOSE_SCOPE
203
204#endif // PXR_BASE_TF_DIAGNOSTIC_BASE_H
Define function attributes.
Functions for recording call locations.
Represents the base class of an object representing a diagnostic message.
TF_API TfDiagnosticBase(TfEnum code, char const *codeString, TfCallContext const &context, const std::string &commentary, TfDiagnosticInfo info, bool quiet)
Construct an instance.
TF_API bool IsCodingError() const
Return true if this diagnostic's code is either a fatal or nonfatal coding error.
const std::string & GetDiagnosticCodeAsString() const
Return the diagnostic code posted as a string.
TF_API bool IsFatal() const
Return true if this diagnostic's code is a fatal code.
const TfCallContext & GetContext() const
Return the call context where the message was issued.
std::string GetSourceFunction() const
Return the source function that the diagnostic message was posted from.
void SetInfo(TfDiagnosticInfo any)
Set the info object associated with this diagnostic message.
TfEnum GetDiagnosticCode() const
Return the diagnostic code posted.
size_t GetSourceLineNumber() const
Return the source line number that the diagnostic message was posted from.
std::string GetSourceFileName() const
Return the source file name that the diagnostic message was posted from.
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.
void AugmentCommentary(const std::string &s)
Add to the commentary string describing this diagnostic message.
Singleton class through which all errors and diagnostics pass.
Definition: diagnosticMgr.h:54
An enum class that records both enum type and enum value.
Definition: enum.h:120
Class used to record the end of the error-list.
Definition: errorMark.h:48
A facility for transporting errors from thread to thread.
Define preprocessor function name macros.
ARCH_API std::string ArchGetPrettierFunctionName(const std::string &function, const std::string &prettyFunction)
Return well formatted function name.
Define integral types.
Definitions of basic string utilities in tf.
Pointer storage with deletion detection.