This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 return _context.GetFile();
59 }
60
63 size_t GetSourceLineNumber() const {
64 return _context.GetLine();
65 }
66
68 std::string const &GetCommentary() const {
69 return _commentary;
70 }
71
73 std::string GetSourceFunction() const {
74 return ArchGetPrettierFunctionName(_context.GetFunction(),
75 _context.GetPrettyFunction());
76 }
77
88 void AugmentCommentary(const std::string& s) {
89 if (_commentary.empty())
90 _commentary = s;
91 else {
92 _commentary += "\n";
93 _commentary += s;
94 }
95 }
96
99 return _code;
100 }
101
102
121 const std::string& GetDiagnosticCodeAsString() const {
122 return _codeString;
123 }
124
144 template <typename T>
145 const T* GetInfo() const {
146 return std::any_cast<T>(&_info);
147 }
148
151 void SetInfo(TfDiagnosticInfo any) {
152 _info = any;
153 }
154
161 bool GetQuiet() const {
162 return _quiet;
163 }
164
166 TF_API
167 bool IsFatal() const;
168
171 TF_API
172 bool IsCodingError() const;
173
175 TF_API
176 TfDiagnosticBase(TfEnum code, char const *codeString,
177 TfCallContext const &context,
178 const std::string& commentary,
179 TfDiagnosticInfo info, bool quiet);
180
181protected:
182 TfCallContext _context;
183
184 std::string _commentary;
185 TfEnum _code;
186 std::string _codeString;
187 TfDiagnosticInfo _info;
188 size_t _serial = 0;
189 bool _quiet = false;
190
191 friend class TfDiagnosticMgr;
192 friend class TfErrorTransport;
193 friend class TfErrorMark;
194};
195
196PXR_NAMESPACE_CLOSE_SCOPE
197
198#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.