File output.hxx

Defines

__OUTPUT_H__

Typedefs

using stream_manipulator = std::ostream &(*)(std::ostream&)

Functions

template<typename T>
DummyOutput &operator<<(DummyOutput &out, T const &t)

Catch stream outputs to DummyOutput objects. This is so that statements like output_debug << “debug message”; compile but have no effect if DEBUG_ENABLED is false

template<typename T>
DummyOutput &operator<<(DummyOutput &out, const T *t)
DummyOutput &operator<<(DummyOutput &out, stream_manipulator pf)
ConditionalOutput &operator<<(ConditionalOutput &out, stream_manipulator pf)
template<typename T>
ConditionalOutput &operator<<(ConditionalOutput &out, T const &t)
template<typename T>
ConditionalOutput &operator<<(ConditionalOutput &out, const T *t)

Variables

DummyOutput output_debug

To allow statements like “output.write(…)” or “output << …” Output for debugging

ConditionalOutput output_warn

warnings

ConditionalOutput output_progress

progress

ConditionalOutput output_info

information

ConditionalOutput output_error

errors

ConditionalOutput output_verbose

less interesting messages

ConditionalOutput output

Generic output, given the same level as output_progress.

class Output : multioutbuf_init<char, std::char_traits<char>>, public std::basic_ostream<char, std::char_traits<char>>
#include <output.hxx>

Class for text output to stdout and/or log file.

This class can be used to output either in C printf format:

output.write(“A string %s and number %d\n”, str, i);

or as a C++ stream buffer:

output << “A string ” << str << ” and number ” << i << endl;

If a file has been opened (i.e. the processor’s log file) then the string will be written to the file. In addition, output to stdout can be enabled and disabled.

Subclassed by ConditionalOutput, DummyOutput

Public Functions

Output()
Output(const char *fname)

Specify a log file to open.

~Output()
void enable()

Enables writing to stdout (default)

void disable()

Disables stdout.

int open(const char *fname, ...)

Open an output log file.

void close()

Close the log file.

void write(const char *string, ...)

Write a string using C printf format.

void print(const char *string, ...)

Same as write, but only to screen.

void vwrite(const char *string, va_list args)

Write a string using C vprintf format.

void vprint(const char *string, va_list args)

Same as vwrite, but only to screen.

void add(std::basic_ostream<char, _Tr> &str)

Add an output stream. All output will be sent to all streams.

void remove(std::basic_ostream<char, _Tr> &str)

Remove an output stream.

Public Static Functions

Output *getInstance()

Return pointer to instance.

Protected Functions

virtual Output *getBase()
virtual bool isEnabled()

Private Types

using _Tr = std::char_traits<char>
using multioutbuf_init = multioutbuf_init<char, _Tr>

Private Members

std::ofstream file

Log file stream.

int buffer_len

the current length

char *buffer

Buffer used for C style output.

bool enabled

Whether output to stdout is enabled.

Private Static Attributes

const int BUFFER_LEN = 1024

default length

Friends

friend ConditionalOutput
class DummyOutput : public Output
#include <output.hxx>

Class which behaves like Output, but has no effect. This is to allow debug outputs to be disabled at compile time

Public Functions

void write(const char *string, ...)

Write a string using C printf format.

void print(const char *string, ...)

Same as write, but only to screen.

void enable()

Enables writing to stdout (default)

void disable()

Disables stdout.

void enable(bool enable)
bool isEnabled()
class ConditionalOutput : public Output
#include <output.hxx>

Layer on top of Output which passes through calls to write, print etc if it is enabled, but discards messages otherwise. This is used to provide different levels of output (info, prog, warn, error) which can be enabled and disabled at run time.

Public Functions

ConditionalOutput(Output *base, bool enabled = true)

Parameters
  • base: The Output object which will be written to if enabled
  • enabled: Should this be enabled by default?

ConditionalOutput(ConditionalOutput *base)

Constuctor taking ConditionalOutput. This allows several layers of conditions

Parameters

void write(const char *str, ...)

If enabled, writes a string using C printf formatting by calling base->vwrite This string is then sent to log file and stdout (on processor 0)

void vwrite(const char *string, va_list args)

Write a string using C vprintf format.

void print(const char *str, ...)

If enabled, print a string to stdout using C printf formatting note: unlike write, this is not also sent to log files

void vprint(const char *string, va_list args)

Same as vwrite, but only to screen.

Output *getBase()

Get the lowest-level Output object which is the base of this ConditionalOutput.

void enable(bool enable_)

Set whether this ConditionalOutput is enabled If set to false (disabled), then all print and write calls do nothing

void enable()

Turn on outputs through calls to print and write.

void disable()

Turn off outputs through calls to print and write This includes log files and stdout

bool isEnabled()

Check if output is enabled.

Private Members

Output *base

The lower-level Output to send output to.

bool enabled

Does this instance output anything?