coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
diagnostic_base Struct Reference

A base class for diagnostic classes. More...

#include <diagnostic.h>

Inheritance diagram for diagnostic_base:
no_assign cloner< diagnostic_base, diagnostic< Level, Id > > diagnostic< Level, Id > diagnostic< severity::abend, Id > diagnostic< severity::error, Id > diagnostic< severity::info, Id > diagnostic< severity::progress, Id > diagnostic< severity::summary_info, Id > diagnostic< severity::summary_progress, Id > diagnostic< severity::summary_warning, Id > diagnostic< severity::warning, Id >

Public Types

using ptr = std::shared_ptr< diagnostic_base >
 Type of pointer to diagnostic_base
 

Public Member Functions

 diagnostic_base (std::string const &severity_name, severity level, unsigned id, bool in_code_only=false)
 Constructor. More...
 
 diagnostic_base (diagnostic_base const &src)
 Copy constructor.
 
void queue () const
 Globally enqueue a copy of this diagnostic_base for deferred action.
 
virtual severity level () const
 Get the severity level of the runtime type.
 
virtual unsigned id () const
 Get the unique identifier of the runtime type. More...
 
unsigned encode () const
 Get the reason-code of the diagnostic. More...
 
 operator unsigned () const
 Explicitly cast the object to its reason-code.
 
bool gagged () const
 Say whether this diagnostic is suppressed.
 
std::string text () const
 Get the text of the diagnostic.
 
 operator std::string () const
 Explicitly cast the object to its textual representation.
 
template<typename T >
diagnostic_baseoperator<< (T const &obj)
 Insert an arbitrary object into the diagnostic. More...
 
diagnostic_baseoperator<< (defer)
 Queue the diagnostic for deferred action. More...
 
diagnostic_baseoperator<< (emit)
 Emit the diagnostic. More...
 

Static Public Member Functions

static size_t deferred ()
 Count the diagnostics enqueued for deferred action.
 
static size_t discard (unsigned reason)
 Discard any queued diagnostics that match a reason-code, returning the number discarded. More...
 
static size_t discard (severity level)
 Discard any queued diagnostics that match a severity, returning the number discarded. More...
 
static void discard_all ()
 Discard all queued diagnostics.
 
static size_t flush (unsigned reason)
 Emit all queued diagnostics that match a reason-code.
 
static size_t flush (severity level)
 Emit all queued diagnostics that match a severity.
 
static void flush_all ()
 Emit any queued diagnostics.
 
static void epilogue ()
 Write summary diagnostics on cerr at exit. More...
 
static int exitcode ()
 Convert the internal exit status to an exit code for exit(). More...
 

Protected Member Functions

virtual void count () const
 Increment global counts appropriately for the runtime type.
 
virtual diagnostic_baseclone () const
 Clone the runtime object on the heap.
 
void despatch () const throw (unsigned)
 Emit the diagnostic.
 

Static Protected Member Functions

static unsigned code (severity level, unsigned id)
 Get the reason-code that encodes a causal identifier and severity. More...
 

Protected Attributes

bool _gagged
 Is the diagnostic suppressed?
 
std::stringstream _text
 The text of the diagnostic.
 

Static Protected Attributes

static std::list< ptr_queue_
 Queue of deferred diagnostics. More...
 
static unsigned _infos_
 Global count of informational diagnostics.
 
static unsigned _warnings_
 Global count of warning diagnostics.
 
static unsigned _errors_
 Global count of error diagnostics.
 
static unsigned _abends_
 Global count of fatal error diagnostics.
 
static unsigned _error_directives_generated_
 Global count of error directives output.
 
static unsigned _error_directives_operative_
 Global count of operative error directives output.
 

Static Private Member Functions

template<class T >
static size_t volley (T match, T(diagnostic_base::*selector)() const, void(diagnostic_base::*action)() const =nullptr)
 Call a member function on all queued diagnostics for which a given member function returns a given result. More...
 

Detailed Description

A base class for diagnostic classes.

Definition at line 85 of file diagnostic.h.

Constructor & Destructor Documentation

diagnostic_base::diagnostic_base ( std::string const &  severity_name,
severity  level,
unsigned  id,
bool  in_code_only = false 
)

Constructor.

Parameters
severity_nameName of the severity level of the diagnostic
levelThe severity level of the diagnostic
idThe causal identifier of the diagnostic
in_code_onlyTrue if the diagnostic is applicable only when parsing code.

Definition at line 61 of file diagnostic.cpp.

Member Function Documentation

static unsigned diagnostic_base::code ( severity  level,
unsigned  id 
)
inlinestaticprotected

Get the reason-code that encodes a causal identifier and severity.

Parameters
levelThe severity to be encoded.
idThe causal identifier to be encoded.
Returns
The reason-code that encodes a causal identifier and severity level.

Definition at line 314 of file diagnostic.h.

static size_t diagnostic_base::discard ( unsigned  reason)
inlinestatic

Discard any queued diagnostics that match a reason-code, returning the number discarded.

Parameters
reasonThe reason-code for selecting the queued diagnostics to discard.
Returns
The number of discarded diagnostics.

Definition at line 217 of file diagnostic.h.

static size_t diagnostic_base::discard ( severity  level)
inlinestatic

Discard any queued diagnostics that match a severity, returning the number discarded.

Parameters
levelThe severityfor selecting the queued diagnostics to discard.
Returns
The number of discarded diagnostics.

Definition at line 227 of file diagnostic.h.

unsigned diagnostic_base::encode ( ) const
inline

Get the reason-code of the diagnostic.

The reason-code encodes the id of the diagnostic and its severity.

Returns
The reason-code of the diagnostic.

Definition at line 138 of file diagnostic.h.

void diagnostic_base::epilogue ( )
static

Write summary diagnostics on cerr at exit.

The summary diagnostics will be output unless --gag summary is in force, which it is by default.

Definition at line 101 of file diagnostic.cpp.

int diagnostic_base::exitcode ( )
static

Convert the internal exit status to an exit code for exit().

Returns
RC such that:

RC & 0x12: Input lines were dropped on output (info).

  • RC & 0x22: Input lines were changed on output (info)
  • RC & 0x44: Lines were changed to errors on output (warning).
  • RC & 0x84: Unconditional errors were output.

Definition at line 156 of file diagnostic.cpp.

virtual unsigned diagnostic_base::id ( ) const
inlinevirtual

Get the unique identifier of the runtime type.

Each distinct cause that may be reported by a diagnostic has a distinct identifier.

Returns
The unique identifier of the runtime type.

Reimplemented in diagnostic< Level, Id >, diagnostic< severity::summary_info, Id >, diagnostic< severity::info, Id >, diagnostic< severity::warning, Id >, diagnostic< severity::summary_progress, Id >, diagnostic< severity::error, Id >, diagnostic< severity::summary_warning, Id >, diagnostic< severity::abend, Id >, and diagnostic< severity::progress, Id >.

Definition at line 127 of file diagnostic.h.

template<typename T >
diagnostic_base& diagnostic_base::operator<< ( T const &  obj)
inline

Insert an arbitrary object into the diagnostic.

Template Parameters
TType of the object to be inserted.
Parameters
objThe T to be inserted.
Returns
A reference to *this.

The member function inserts obj into the text of the diagnostic.

Definition at line 171 of file diagnostic.h.

diagnostic_base& diagnostic_base::operator<< ( defer  )
inline

Queue the diagnostic for deferred action.

Inserting a token object of type defer to the diagnostic adds the diagnostic to the deferred queue.

Returns
A reference to *this.

Definition at line 185 of file diagnostic.h.

diagnostic_base& diagnostic_base::operator<< ( emit  )
inline

Emit the diagnostic.

Inserting a token object of type emit to the diagnostic causes it to be emitted.

Returns
A reference to *this.

Definition at line 199 of file diagnostic.h.

template<class T >
static size_t diagnostic_base::volley ( match,
T(diagnostic_base::*)() const  selector,
void(diagnostic_base::*)() const  action = nullptr 
)
inlinestaticprivate

Call a member function on all queued diagnostics for which a given member function returns a given result.

Template Parameters
TType returned by the selector member function.
Parameters
matchThe T that shall be returned by the selector function to select the diagnostic.
selectorThe member method that selects queued diagnostics for action.
actionThe member method, if any, to be called on selected diagnostics, else null.
Returns
The number of diagnostics selected.

Definition at line 353 of file diagnostic.h.

Member Data Documentation

list< diagnostic_base::ptr > diagnostic_base::_queue_
staticprotected

Queue of deferred diagnostics.

A diagnostic may have to be constructed before we know whether it should be issued. In the meantime it can be queued.

Definition at line 323 of file diagnostic.h.


The documentation for this struct was generated from the following files: