File output.hxx#

Defines

BOUT_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 BOUT_USE_OUTPUT_DEBUG is false

template<typename T>
DummyOutput &operator<<(DummyOutput &out, const T *t)#
inline DummyOutput &operator<<(DummyOutput &out, stream_manipulator pf)#
inline 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

ConditionalOutput 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 : private 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 fmt 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

inline Output()#
inline Output(const std::string &filename)#

Specify a log file to open.

template<class S, class ...Args>
inline Output(const S &format, const Args&... args)#
inline ~Output() override#
virtual void enable()#

Enables writing to stdout (default)

virtual void disable()#

Disables stdout.

int open(const std::string &filename)#

Open an output log file.

template<class S, class ...Args>
inline int open(const S &format, const Args&... args)#
void close()#

Close the log file.

virtual void write(const std::string &message)#

Write a string using fmt format.

template<class S, class ...Args>
inline void write(const S &format, const Args&... args)#
virtual void print(const std::string &message)#

Same as write, but only to screen.

template<class S, class ...Args>
inline void print(const S &format, const Args&... args)#
inline void add(std::basic_ostream<char, _Tr> &str)#

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

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

Remove an output stream.

Public Static Functions

static Output *getInstance()#

Return pointer to instance.

Protected Functions

inline virtual Output *getBase()#
inline 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.

bool enabled#

Whether output to stdout is enabled.

Friends

friend class 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

template<class S, class ...Args>
inline void write([[maybe_unused]] const S &format, [[maybe_unused]] const Args&... args)#
template<class S, class ...Args>
inline void print([[maybe_unused]] const S &format, [[maybe_unused]] const Args&... args)#
inline void write([[maybe_unused]] const std::string &message) override#
inline void print([[maybe_unused]] const std::string &message) override#
inline virtual void enable() override#

Enables writing to stdout (default)

inline virtual void disable() override#

Disables stdout.

inline void enable([[maybe_unused]] bool enable)#
inline virtual bool isEnabled() override#
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

inline ConditionalOutput(Output *base, bool enabled = true)#
Parameters:
  • base[in] The Output object which will be written to if enabled

  • enabled[in] Should this be enabled by default?

inline ConditionalOutput(ConditionalOutput *base)#

Constuctor taking ConditionalOutput. This allows several layers of conditions

Parameters:

base[in] A ConditionalOutput which will be written to if enabled

virtual void write(const std::string &message) override#

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

template<class S, class ...Args>
inline void write(const S &format, const Args&... args)#
virtual void print(const std::string &message) override#

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

template<class S, class ...Args>
inline void print(const S &format, const Args&... args)#
inline virtual Output *getBase() override#

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

inline void enable(bool enable_)#

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

inline virtual void enable() override#

Turn on outputs through calls to print and write.

inline virtual void disable() override#

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

inline virtual bool isEnabled() override#

Check if output is enabled.

Protected Attributes

bool enabled#

Does this instance output anything?

Private Members

Output *base#

The lower-level Output to send output to.

Friends

friend class WithQuietOutput
class WithQuietOutput#
#include <output.hxx>

Disable a ConditionalOutput during a scope; reenable it on exit. You must give the variable a name!

{
  WithQuietOutput quiet{output};
  // output disabled during this scope
}
// output now enabled

Public Functions

inline explicit WithQuietOutput(ConditionalOutput &output_in)#
inline ~WithQuietOutput()#

Private Members

ConditionalOutput &output#
bool state#