File msg_stack.hxx

Defines

__thefunc__

The PRETTY_FUNCTION variable is defined by GCC (and some other families) but is not a part of the standard. The func variable is a part of the c++11 standard so we’d like to fall back to this if possible. However as these are variables/constants and not macros we can’t just check if PRETTY_FUNCITON is defined or not. Instead we need to say if we support this or not by defining BOUT_HAS_PRETTY_FUNCTION (to be implemented in configure)

GLOBAL

This is a way to define a global object, so that it is declared extern in all files except one where GLOBALORIGIN is defined.

CONCATENATE_DIRECT(s1, s2)

To concatenate strings for a variable name.

CONCATENATE(s1, s2)

Need to use two levels due to macro strangeness.

TRACE(...)

The TRACE macro provides a convenient way to put messages onto the msg_stack It pushes a message onto the stack, and pops it when the scope ends

Example

{ TRACE(“Starting calculation”)

} // Scope ends, message popped

AUTO_TRACE()

The AUTO_TRACE macro provides a convenient way to put messages onto the msg_stack It pushes a message onto the stack, and pops it when the scope ends The message is automatically derived from the function signature as identified by the compiler. This will be PRETTY_FUNCTION if available else it will be the mangled form.

This is implemented as a use of the TRACE macro with specific arguments.

Example

{ AUTO_TRACE();

} // Scope ends, message popped

Variables

MsgStack msg_stack

Global object. Will eventually replace with better system.

class MsgStack
#include <msg_stack.hxx>

Message stack

Implements a stack of messages which can be pushed onto the top and popped off the top. This is used for debugging: messages are put into this stack at the start of a section of code, and removed at the end. If an error occurs in between push and pop, then the message can be printed.

This code is only enabled if CHECK > 1. If CHECK is disabled then this message stack code reverts to empty functions which should be removed by the optimiser

Public Functions

MsgStack() = default
inline ~MsgStack()
inline int push(const std::string&)

Dummy functions which should be optimised out.

template<class S, class ...Args>
inline int push(const S&, const Args&...)
inline void pop()
inline void pop(int id)
inline void clear()
inline void dump()
inline std::string getDump()

Private Members

std::vector<std::string> stack

Message stack;.

std::vector<std::string>::size_type position = {0}

Position in stack.

class MsgStackItem
#include <msg_stack.hxx>

MsgStackItem

Simple class to manage pushing and popping messages from the message stack. Pushes a message in the constructor, and pops the message on destruction.

Public Functions

inline MsgStackItem(std::string message)
inline MsgStackItem(const std::string &message, const char *file, int line)
inline MsgStackItem(const std::string &file, int line, const char *msg)
template<class S, class ...Args>
inline MsgStackItem(const std::string &file, int line, const S &msg, const Args&... args)
inline ~MsgStackItem()

Private Members

int exception_count = uncaught_exceptions()
int point

Private Static Functions

static inline int uncaught_exceptions()

Backfill for C++14: note this wrong and only useful for our purposes here, that is, telling us if there has been an uncaught exception, which is why this is a private method