Loading...
Searching...
No Matches
TfDiagnosticBase Class Reference

Represents the base class of an object representing a diagnostic message. More...

#include <diagnosticBase.h>

+ Inheritance diagram for TfDiagnosticBase:

Public Member Functions

const TfCallContext & GetContext () const
 Return the call context where the message was issued.
 
std::string GetSourceFileName () const
 Return the source file name that the diagnostic message was posted from.
 
size_t GetSourceLineNumber () const
 Return the source line number that the diagnostic message was posted from.
 
std::string const & GetCommentary () const
 Return the commentary string describing this diagnostic message.
 
std::string GetSourceFunction () const
 Return the source function that the diagnostic message was posted from.
 
void AugmentCommentary (const std::string &s)
 Add to the commentary string describing this diagnostic message.
 
TfEnum GetDiagnosticCode () const
 Return the diagnostic code posted.
 
const std::string & GetDiagnosticCodeAsString () const
 Return the diagnostic code posted as a string.
 
template<typename T >
const T * GetInfo () const
 Return a (possibly NULL) const pointer to the info object associated with this message.
 
void SetInfo (TfDiagnosticInfo any)
 Set the info object associated with this diagnostic message.
 
bool GetQuiet () const
 Return true if the message was posted via PostQuietly().
 
TF_API bool IsFatal () const
 Return true if this diagnostic's code is a fatal code.
 
TF_API bool IsCodingError () const
 Return true if this diagnostic's code is either a fatal or nonfatal coding error.
 
TF_API TfDiagnosticBase (TfEnum code, char const *codeString, TfCallContext const &context, const std::string &commentary, TfDiagnosticInfo info, bool quiet)
 Construct an instance.
 

Protected Attributes

TfCallContext _context
 
std::string _commentary
 
TfEnum _code
 
std::string _codeString
 
TfDiagnosticInfo _info
 
size_t _serial = 0
 
bool _quiet = false
 

Friends

class TfDiagnosticMgr
 
class TfErrorTransport
 
class TfErrorMark
 

Detailed Description

Represents the base class of an object representing a diagnostic message.

This forms the base class for specific types associated with errors, warnings and status messages. It associates a diagnostic code (which is an enum value) with the message. It can also hold on to arbitrary information associated with the message in a TfDiagnosticInfo.

See The TfError Error Posting System in the C++ API reference for a detailed example. For a description of how to post an error, warning or a status message see TF_ERROR(), TF_WARN and TF_STATUS also in the C++ API reference.

Definition at line 65 of file diagnosticBase.h.

Constructor & Destructor Documentation

◆ TfDiagnosticBase()

TF_API TfDiagnosticBase ( TfEnum  code,
char const *  codeString,
TfCallContext const &  context,
const std::string &  commentary,
TfDiagnosticInfo  info,
bool  quiet 
)

Construct an instance.

Member Function Documentation

◆ AugmentCommentary()

void AugmentCommentary ( const std::string &  s)
inline

Add to the commentary string describing this diagnostic message.

Note: each string added to the commentary is separated from the previous one with a newline. This means that you the string s should not end with a newline. Thus,

cout << e.GetCommentary() << "\n";

always prints the entire commentary string as a newline separated sequence of messages.

Definition at line 105 of file diagnosticBase.h.

◆ GetCommentary()

std::string const & GetCommentary ( ) const
inline

Return the commentary string describing this diagnostic message.

Definition at line 85 of file diagnosticBase.h.

◆ GetContext()

const TfCallContext & GetContext ( ) const
inline

Return the call context where the message was issued.

Definition at line 69 of file diagnosticBase.h.

◆ GetDiagnosticCode()

TfEnum GetDiagnosticCode ( ) const
inline

Return the diagnostic code posted.

Definition at line 115 of file diagnosticBase.h.

◆ GetDiagnosticCodeAsString()

const std::string & GetDiagnosticCodeAsString ( ) const
inline

Return the diagnostic code posted as a string.

If the enum value posted with the message has been registered with TF_ADD_ENUM_NAME(), then GetDiagnosticCodeAsString() will return the symbolic name of the enum.

If the enum has not been registered, then code of the form

TF_ERROR(PUCE).Post("is an ugly color");
#define TF_ERROR(...)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:71

will still result in GetDiagnosticCodeAsString() returning the string "PUCE"; however, code of the form

MyErrorCode c = PUCE;
TF_ERROR(c).Post("is still ugly");

will result in GetDiagnosticCodeAsString() returning the (uninformative) string "c".

Definition at line 138 of file diagnosticBase.h.

◆ GetInfo()

const T * GetInfo ( ) const
inline

Return a (possibly NULL) const pointer to the info object associated with this message.

If this message was posted without supplying an info argument to Post(), e.g.

TF_ERROR(SOME_CODE).Post("something went wrong");

then GetInfo() returns NULL. Otherwise, when info is supplied, e.g.

T myInfo = ...
TF_ERROR(SOME_CODE).Post("something went wrong")->SetInfo(myInfo);

then a const pointer to a copy of myInfo in the above example is returned by GetInfo<T>(). If the type T doesn't match the held type then GetInfo() returns NULL.

Definition at line 162 of file diagnosticBase.h.

◆ GetQuiet()

bool GetQuiet ( ) const
inline

Return true if the message was posted via PostQuietly().

Notices sent from PostQuietly() are indicating that an immediate printout of the error is not desirable, because someone higher up on the stack may actually handle this error. This is rare, but it does happen on occasion.

Definition at line 178 of file diagnosticBase.h.

◆ GetSourceFileName()

std::string GetSourceFileName ( ) const
inline

Return the source file name that the diagnostic message was posted from.

Definition at line 74 of file diagnosticBase.h.

◆ GetSourceFunction()

std::string GetSourceFunction ( ) const
inline

Return the source function that the diagnostic message was posted from.

Definition at line 90 of file diagnosticBase.h.

◆ GetSourceLineNumber()

size_t GetSourceLineNumber ( ) const
inline

Return the source line number that the diagnostic message was posted from.

Definition at line 80 of file diagnosticBase.h.

◆ IsCodingError()

TF_API bool IsCodingError ( ) const

Return true if this diagnostic's code is either a fatal or nonfatal coding error.

◆ IsFatal()

TF_API bool IsFatal ( ) const

Return true if this diagnostic's code is a fatal code.

◆ SetInfo()

void SetInfo ( TfDiagnosticInfo  any)
inline

Set the info object associated with this diagnostic message.

See also
GetInfo()

Definition at line 168 of file diagnosticBase.h.

Friends And Related Function Documentation

◆ TfDiagnosticMgr

friend class TfDiagnosticMgr
friend

Definition at line 208 of file diagnosticBase.h.

◆ TfErrorMark

friend class TfErrorMark
friend

Definition at line 210 of file diagnosticBase.h.

◆ TfErrorTransport

friend class TfErrorTransport
friend

Definition at line 209 of file diagnosticBase.h.

Member Data Documentation

◆ _code

TfEnum _code
protected

Definition at line 202 of file diagnosticBase.h.

◆ _codeString

std::string _codeString
protected

Definition at line 203 of file diagnosticBase.h.

◆ _commentary

std::string _commentary
protected

Definition at line 201 of file diagnosticBase.h.

◆ _context

TfCallContext _context
protected

Definition at line 199 of file diagnosticBase.h.

◆ _info

TfDiagnosticInfo _info
protected

Definition at line 204 of file diagnosticBase.h.

◆ _quiet

bool _quiet = false
protected

Definition at line 206 of file diagnosticBase.h.

◆ _serial

size_t _serial = 0
protected

Definition at line 205 of file diagnosticBase.h.


The documentation for this class was generated from the following file: