MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
MDebug Class Reference

The DEBUG class for the maia. More...

#include <debug.h>

Collaboration diagram for MDebug:
[legend]

Static Public Member Functions

static void maiaerror (MString message, MDebugLevel debugLevel)
 
static void maiaprint (const MString &message, MDebugLevel debugLevel)
 
static void setLevel (MInt debugLevel)
 
static void setLevelNotEnabled (const MInt debugLevel)
 
static void displayOn ()
 
static void displayOff ()
 

Static Public Attributes

static MString debugMessage
 
static const MInt m_minLevel = MAIA_DEBUG_ASSERTION
 
static const MInt m_maxLevel = MAIA_DEBUG_USER5
 

Static Private Attributes

static MInt m_debugLevel
 
static MBool m_debugOn
 
static std::basic_string< char > m_traceSpaces
 

Detailed Description

This class handles the DEBUG messaging for the maia.

For debugging you mainly use two macros : SET_DEBUG_LEVEL(debuglevel) and DEBUG( message, debuglevel) The SET_DEBUG_LEVEL macro accepts arbitrary or combinations of debug levels, so that you can display only the messages you want to observe. The message that is given to the DEBUG macro is only displayed, if the connected debug level was given to the SET_DEBUG_LEVEL function (as a single value or a combination). If you temporarily want to suppress the DEBUG output you can use the macros DEBUG_DISPLAY_ON and DEBUG_DISPLAY_OFF, which do what their names imply.

The common debug policy in the maia development is that you use MAIA_DEBUG_TRACE only for marking the entry and return point of a function. As long as your code is still experimental use the MAIA_DEBUG_USER levels (choose the numbers at will). If you handover your code, i.e. if it is added to the project all MAIA_DEBUG_USER levels must be removed. All DEBUG output that might be usefull later (i.e. also for other programmers) must be set to MAIA_DEBUG_LEVEL levels.

So (ideally speaking) you should never get code with MAIA_DEBUG_USER levels set and you also should never hand over code which still includes MAIA_DEBUG_USER levels.

------------------------—EXAMPLE :-----------------------------—

SET_DEBUG_LEVEL(MAIA_DEBUG_USER1|MAIA_DEBUG_USER3);

DEBUG ( "Hello", MAIA_DEBUG_USER2 ); // this prints "Hello" if the DEBUG level is set to MAIA_DEBUG_USER2

DEBUG ( "Solver::Solver" << " entry, solverId: " << m_solverId , MAIA_DEBUG_USER2 ); // hint: DEBUG works exactly like cout

--------------------— END OF EXAMPLE :-------------------------—

!!!!!!!!!! Important note !!!!!!!!!!!! SINCE DEBUG IS A MACRO, NEVER BREAK THE LINE IN WHICH YOU USE IT, I.E. DEBUG WON'T WORK WITH ARGUMENTS OF MULTIPLE LINES !

Definition at line 180 of file debug.h.

Member Function Documentation

◆ displayOff()

void MDebug::displayOff ( )
inlinestatic

Definition at line 202 of file debug.h.

202{ m_debugOn = false; }
static MBool m_debugOn
Definition: debug.h:196

◆ displayOn()

void MDebug::displayOn ( )
inlinestatic

Definition at line 200 of file debug.h.

200{ m_debugOn = true; }

◆ maiaerror()

static void MDebug::maiaerror ( MString  message,
MDebugLevel  debugLevel 
)
static

◆ maiaprint()

void MDebug::maiaprint ( const MString message,
MDebugLevel  debugLevel 
)
inlinestatic

Definition at line 216 of file debug.h.

216 {
217 // This function seperates the debug levels and
218 // displays the messages which have the right debug level.
219 if(m_debugOn) {
220 auto a = (MUint)m_maxLevel;
221 auto b = (MUint)m_debugLevel;
222 ldiv_t adiv;
223 do {
224 adiv = ldiv(b, a);
225 if(adiv.quot == 1 && a == (MUint)debugLevel) {
226 if(debugLevel == MAIA_DEBUG_TRACE_OUT) {
227 m_traceSpaces.erase(0, 2);
228 }
229 m_log << m_traceSpaces << "MDebug: "
230 << "[" << globalDomainId() << "]:" << message << std::endl;
231 if(debugLevel == MAIA_DEBUG_TRACE_IN) {
232 m_traceSpaces += " ";
233 }
234 }
235 if(b >= a) {
236 b -= a;
237 }
238 a = a / 2;
239 } while(adiv.rem != 0); // repeat as long as there
240 // is a rest and a level
241 }
242}
static MInt m_debugLevel
Definition: debug.h:195
static std::basic_string< char > m_traceSpaces
Definition: debug.h:197
static const MInt m_maxLevel
Definition: debug.h:192
const MString const MString & message
Definition: functions.h:37
MInt globalDomainId()
Return global domain id.
InfoOutFile m_log
uint32_t MUint
Definition: maiatypes.h:63
Definition: contexttypes.h:19

◆ setLevel()

void MDebug::setLevel ( MInt  debugLevel)
inlinestatic

Definition at line 204 of file debug.h.

204 {
205 displayOn();
206 m_debugLevel = debugLevel;
207}
static void displayOn()
Definition: debug.h:200

◆ setLevelNotEnabled()

void MDebug::setLevelNotEnabled ( const MInt  debugLevel)
inlinestatic

Definition at line 209 of file debug.h.

209 {
210 if(debugLevel != 0) {
211 cerr0 << "WARNING: trying to set debug level " << debugLevel << " but MAIA_DEBUG_FUNCTION is not enabled."
212 << std::endl;
213 }
214}
std::ostream cerr0

Member Data Documentation

◆ debugMessage

MString MDebug::debugMessage
static

Definition at line 182 of file debug.h.

◆ m_debugLevel

MInt MDebug::m_debugLevel
staticprivate

Definition at line 195 of file debug.h.

◆ m_debugOn

MBool MDebug::m_debugOn
staticprivate

Definition at line 196 of file debug.h.

◆ m_maxLevel

const MInt MDebug::m_maxLevel = MAIA_DEBUG_USER5
static

Definition at line 192 of file debug.h.

◆ m_minLevel

const MInt MDebug::m_minLevel = MAIA_DEBUG_ASSERTION
static

Definition at line 191 of file debug.h.

◆ m_traceSpaces

basic_string< char > MDebug::m_traceSpaces
staticprivate

Definition at line 197 of file debug.h.


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