ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Inner Classes | Public Static Methods | Public Methods | Protected Static Fields | Protected Fields | List of all members
Report Class Reference
Collaboration diagram for Report:
[legend]

Class Description


This class provides a simple facility to collect what is called a 'report'. Reports are maintenance messages, mostly error and warning messages, but is not aiming to replace any sort of error handling. (In ALib itself, sending a 'report' usually precedes raising an error.) Also, reports are not replacing any debug or release logging facility, which is not part of ALib. Much more, logging libraries might provide a derived object of type ReportWriter to plug into ALib report facility. This way, the concepts of logging and reports get unified. (As a sample, ALox Logging Library which builds on ALib does so.)

While a process can create different objects of this class, usually, the default instance, received by getDefault. is sufficient and all warnings and errors will be directed to this one. ALib itself directs all internal reports to the default instance.

This class uses a singleton of type ReportWriter to actually write the reports. By default, an object of type ReportWriterStdIO is attached.

The reporting method, doReport will check the flags provided with pushHaltFlags for message types 0 (errors) and 1 (warnings), and may invoke assert(). Such assertions are effective only in the debug compilation of the library/executable. Custom 'ReportWriters' might take action (e.g. for security reasons) and e.g. terminate the application also in release compilations.

To simplify things, a set of static methods are defined in class ALIB which are deemed to be pruned in release versions of the compilation unit. These are:

The use of these methods is recommended and preferred over the direct use of class Report whenever pure debug reports are intended.

Inner Classes

class  Message
 

Public Static Methods

static Report getDefault ()
 

Public Methods

 Report ()
 
synchronized void doReport (int type, Object... msg)
 
synchronized ReportWriter peekWriter ()
 
synchronized void popHaltFlags ()
 
synchronized void popWriter (ReportWriter checkWriter)
 
synchronized void pushHaltFlags (boolean haltOnErrors, boolean haltOnWarnings)
 
synchronized void pushWriter (ReportWriter newWriter)
 

Protected Static Fields

static Report defaultReport =new Report()
 

Protected Fields

Deque< Integer > haltAfterReport =new LinkedList<Integer>()
 
boolean recursionBlocker =false
 
Deque< ReportWriterwriters =new LinkedList<ReportWriter>()
 

Constructor & Destructor Documentation

◆ Report()

Report ( )

Constructor

Member Function Documentation

◆ doReport()

synchronized void doReport ( int  type,
Object...  msg 
)

Reports the given message to the current ReportWriter in place. The default ReportWriter will print the message on the process console. Furthermore, in debug execution the flags provided with pushHaltFlags is checked. If this is set for the type of message, the program halts or suspends into the debugger (platform and language specific).

If parameter is '0', the report is considered a severe error, otherwise a warning. User defined implementations of class ReportWriter may interpret this field arbitrarily.

Note
In Java, assertions are disabled by default. Therefore, to really have your program 'halted' on reports, assertions have to be enabled, by providing parameter -enableassertions to the Java virtual machine.
Parameters
typeThe report type.
msgThe report message.

◆ getDefault()

static Report getDefault ( )
static

Receives the default report object used by ALib and processes that rely on ALib.

Returns
The default Report.

◆ peekWriter()

synchronized ReportWriter peekWriter ( )

Retrieves the actual report writer.

Note
This method should not be used to retrieve the writer and use it. It should be used only to test the installation.
Returns
The actual report writer in place.

◆ popHaltFlags()

synchronized void popHaltFlags ( )

Restores the previous values after an invocation to pushHaltFlags.

◆ popWriter()

synchronized void popWriter ( ReportWriter  checkWriter)

Restores the previous writer after setting a new one using pushWriter. It is important to keep the right order when pushing and popping writers, as there lifetime is externally managed. (In standard use-cases, only one, app-specific writer should be pushed anyhow). To give a little assurance, this method popWriter takes the same parameter as pushWriter does, to verify if the one to be removed is really the topmost.

Parameters
checkWriterThe previously pushed writer (for checking of call order).

◆ pushHaltFlags()

synchronized void pushHaltFlags ( boolean  haltOnErrors,
boolean  haltOnWarnings 
)

Writes new values to the internal flags that decide if calls to doReport with report type '0' (errors), respectively report type '>0' (warnings) cause to halt program execution by calling assert(false). The previous values can be restored using popHaltFlags.

Parameters
haltOnErrorsSpecifies if halting on errors is wanted.
haltOnWarningsSpecifies if halting on warnings is wanted.

◆ pushWriter()

synchronized void pushWriter ( ReportWriter  newWriter)

Sets a new writer. The actual writer is implemented as a stack. It is important to keep the right order when pushing and popping writers, as there lifetime is externally managed. (In standard use-cases, only one, app-specific writer should be pushed anyhow). To give a little assurance, method popWriter takes the same parameter as this method does, to verify if if the one to be removed is really the topmost.

Parameters
newWriterThe writer to use.

Member Data Documentation

◆ defaultReport

Report defaultReport =new Report()
staticprotected

The default Report used internally by ALib and usually by processes that rely on ALib.

◆ haltAfterReport

Deque<Integer> haltAfterReport =new LinkedList<Integer>()
protected

A stack of integers. The topmost value is used to decide, whether program execution is halted on message of type 'error' (type 0, bit 0) or of type 'warning' (type 1, bit 1). Can be set at runtime using methods pushHaltFlags and popHaltFlags.

◆ recursionBlocker

boolean recursionBlocker =false
protected

This is a flag that avoids recursion. Recursion might occur when a more sophisticated report writer sends a report (e.g. an ALIB Error or Warning). Recursive calls are rejected without further notice.

◆ writers

Deque<ReportWriter> writers =new LinkedList<ReportWriter>()
protected

A stack of writers. The topmost one is the actual. Can be set at runtime using methods pushWriter and popWriter.


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