Skip to content

Commit

Permalink
Reformatted debug mode enums and methods - now in namespace Debug. Fi…
Browse files Browse the repository at this point in the history
…xed issue with Energystore::Totalise() which would ignore values in half of the energy matrices (problematic for Model::modelEnergy() which wuold not necessarily store energy values with the lowest pattern id first).
  • Loading branch information
t.youngs committed Mar 26, 2008
1 parent 209ecf4 commit 3d34682
Show file tree
Hide file tree
Showing 109 changed files with 1,577 additions and 1,555 deletions.
26 changes: 13 additions & 13 deletions src/base/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,36 @@ void MasterData::debugCli(int argc, char *argv[])
{
// Turn on call debugging
case (Cli::DebugSwitch):
addDebugLevel(DM_CALLS);
Debug::addDebug(Debug::Calls);
break;
// Turn on debug messages for atom typing
case (Cli::DebugTypingSwitch):
addDebugLevel(DM_TYPING);
Debug::addDebug(Debug::Typing);
break;
// Turn on debug messages for atom typing
case (Cli::DebugParseSwitch):
addDebugLevel(DM_PARSE);
Debug::addDebug(Debug::Parse);
break;
// Turn on debug messages for atom typing
case (Cli::DebugFileSwitch):
addDebugLevel(DM_FILTERS);
Debug::addDebug(Debug::Filters);
break;
// Turn on debug messages for more calls
case (Cli::DebugMoreSwitch):
addDebugLevel(DM_CALLS);
addDebugLevel(DM_MORECALLS);
Debug::addDebug(Debug::Calls);
Debug::addDebug(Debug::MoreCalls);
break;
// Turn on debug messages for all calls
case (Cli::DebugAllSwitch):
addDebugLevel(DM_CALLS);
addDebugLevel(DM_MORECALLS);
addDebugLevel(DM_VERBOSE);
addDebugLevel(DM_PARSE);
addDebugLevel(DM_TYPING);
Debug::addDebug(Debug::Calls);
Debug::addDebug(Debug::MoreCalls);
Debug::addDebug(Debug::Verbose);
Debug::addDebug(Debug::Parse);
Debug::addDebug(Debug::Typing);
break;
// Turn on verbose messaging
case (Cli::VerboseSwitch):
addDebugLevel(DM_VERBOSE);
Debug::addDebug(Debug::Verbose);
break;
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ int MasterData::parseCli(int argc, char *argv[])
for (n=0; n<parser.nArgs(); n++)
{
el = elements.find(afterChar(parser.argc(n), '='));
if (el == 0) msg(DM_NONE,"Unrecognised element '%s' in type map.\n",afterChar(parser.argc(n),'='));
if (el == 0) msg(Debug::None,"Unrecognised element '%s' in type map.\n",afterChar(parser.argc(n),'='));
else typeMap.add(beforeChar(parser.argc(n),'='), el);
}
for (ri = typeMap.first(); ri != NULL; ri = ri->next)
Expand Down
33 changes: 21 additions & 12 deletions src/base/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@
*/

// Bitvector of debug levels
int debug_output = 0;
int Debug::debugOutput = 0;
// Formatting indent for call debugging output
int funclevel = 0;
// Add a debug level to the debug output bitvector
void addDebugLevel(DebugMode dm) { if (!(debug_output&dm)) debug_output += dm; }
void Debug::addDebug(Debug::DebugMode dm)
{
if (!(Debug::debugOutput&dm)) Debug::debugOutput += dm;
}
// Remove a debug level from the debug output bitvector
void removeDebugLevel(DebugMode dm) { if (debug_output&dm) debug_output -= dm; }
void Debug::removeDebug(Debug::DebugMode dm)
{
if (Debug::debugOutput&dm) Debug::debugOutput -= dm;
}
// Returns whether the specified debug level is set
bool isDebugLevelActive(DebugMode dm) { return ((debug_output&dm) ? TRUE : FALSE); }
bool Debug::isDebugActive(Debug::DebugMode dm)
{
return ((Debug::debugOutput&dm) ? TRUE : FALSE);
}

// Standard message
void msg(DebugMode dm, const char *fmt ...)
void msg(Debug::DebugMode dm, const char *fmt ...)
{
// Print to the text view in the main window if it has been initialised.
// Otherwise, print to stdout. Also print to stdout if debuglevel >= msglevel.
Expand All @@ -48,23 +57,23 @@ void msg(DebugMode dm, const char *fmt ...)
// Parse the argument list (...) and internally write the output string into msgs[]
va_start(arguments,fmt);
vsprintf(msgs,fmt,arguments);
// We always print messages with mode DM_NONE to stdout *or* the GUI (if it has been initialised)
// We always print messages with mode Debug::None to stdout *or* the GUI (if it has been initialised)
// For other message levels, only print if it's debug level is active
if (dm == DM_NONE)
if (dm == Debug::None)
{
if (gui.exists()) gui.printMessage(msgs);
else printf("%s",msgs);
}
else if (isDebugLevelActive(dm)) printf("%s",msgs);
else if (Debug::isDebugActive(dm)) printf("%s",msgs);
va_end(arguments);
}

// Function enter
void dbgBegin(DebugMode dm, const char *fmt ...)
void dbgBegin(Debug::DebugMode dm, const char *fmt ...)
{
// Debug Messaging - Enter Function
static char msgs[8096];
if (!isDebugLevelActive(dm)) return;
if (!Debug::isDebugActive(dm)) return;
va_list arguments;
msgs[0] = '\0';
// Parse the argument list (...) and internally write the output string into msgs[]
Expand All @@ -78,11 +87,11 @@ void dbgBegin(DebugMode dm, const char *fmt ...)
}

// Function leave
void dbgEnd(DebugMode dm, const char *fmt ...)
void dbgEnd(Debug::DebugMode dm, const char *fmt ...)
{
// Debug Messaging - Leave Function
static char msgs[8096];
if (!isDebugLevelActive(dm)) return;
if (!Debug::isDebugActive(dm)) return;
va_list arguments;
msgs[0] = '\0';
// Parse the argument list (...) and internally write the output string into msgs[]
Expand Down
25 changes: 15 additions & 10 deletions src/base/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@
*/

// Debug messaging modes
enum DebugMode { DM_NONE=0, DM_CALLS=1, DM_MORECALLS=2, DM_TYPING=4, DM_PARSE=8, DM_VERBOSE=16, DM_FILTERS=32 };
// Add a debug level to the debug output bitvector
void addDebugLevel(DebugMode);
// Remove a debug level from the debug output bitvector
void removeDebugLevel(DebugMode);
// Returns whether the specified debug level is set
bool isDebugLevelActive(DebugMode);
namespace Debug
{
enum DebugMode { None=0, Calls=1, MoreCalls=2, Typing=4, Parse=8, Verbose=16, Filters=32 };
// Add a debug level to the debug output bitvector
void addDebug(Debug::DebugMode);
// Remove a debug level from the debug output bitvector
void removeDebug(Debug::DebugMode);
// Returns whether the specified debug level is set
bool isDebugActive(Debug::DebugMode);
// Bitvector of debug levels
extern int debugOutput;
}

// Messaging Functions
void msg(DebugMode, const char* ...);
void dbgBegin(DebugMode, const char* ...);
void dbgEnd(DebugMode, const char* ...);
void msg(Debug::DebugMode, const char* ...);
void dbgBegin(Debug::DebugMode, const char* ...);
void dbgEnd(Debug::DebugMode, const char* ...);

#endif
6 changes: 3 additions & 3 deletions src/base/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ int ElementMap::ffToZ(const char *s)
int ElementMap::find(const char *query)
{
// Get the element number from the element name provided.
dbgBegin(DM_CALLS,"ElementMap::find");
dbgBegin(Debug::Calls,"ElementMap::find");
int result = -1;
if (query[0] == '\0')
{
printf("Warning: Element search requested on blank string.\n");
dbgEnd(DM_CALLS,"ElementMap::find");
dbgEnd(Debug::Calls,"ElementMap::find");
return 0;
}
// Convert the query string according to the specified rule
Expand Down Expand Up @@ -462,7 +462,7 @@ int ElementMap::find(const char *query)
result = numberToZ(query);
break;
}
dbgEnd(DM_CALLS,"ElementMap::find");
dbgEnd(Debug::Calls,"ElementMap::find");
return ((result == -1) ? 0 : result);
}

Expand Down
Loading

0 comments on commit 3d34682

Please sign in to comment.