File msg_stack.hxx



The maximum length (in chars) of messages, not including terminating ‘0’.


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 HAS_PRETTY_FUNCTION (to be implemented in configure)


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


To concatenate strings for a variable name.


Need to use two levels due to macro strangeness.


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


{ TRACE(“Starting calculation”)

} // Scope ends, message popped


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.



} // Scope ends, message popped


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

int push(const char *s, ...)

Add a message to the stack. Returns a message id.

Provides a message stack to print more useful error messages.

Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu

Contact: Ben Dudson,

This file is part of BOUT++.

BOUT++ is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

BOUT++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with BOUT++. If not, see

int setPoint()

get a message point

void pop()

Remove the last message.

void pop(int id)

Remove all messages back to msg id.

void clear()

Clear all message.

void dump()

Write out all messages (using output)

std::string getDump()

Write out all messages to a string.

Private Members

char buffer[256]

Buffer for vsnprintf.

std::vector<std::string> stack

Message stack;.

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

Position in stack.

class MsgStackItem
#include <msg_stack.hxx>


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

MsgStackItem(const char *msg)
MsgStackItem(const char *msg, const char *file, int line)
MsgStackItem(const char *file, int line, const char *msg, ...)

Private Members

int point
char buffer[256]