Adding functions to get and set global granular debug flags that can be controlled at runtime, see debug.h.

release/4.3a0
Richard Roberts 2011-02-04 00:32:30 +00:00
parent 62aa7a6681
commit 3d9f7294a9
3 changed files with 67 additions and 1 deletions

View File

@ -24,7 +24,7 @@ endif
# Testing
headers += Testable.h TestableAssertions.h numericalDerivative.h
sources += timing.cpp
sources += timing.cpp debug.cpp
# Lie Groups
headers += Lie.h Lie-inl.h lieProxies.h LieScalar.h

16
gtsam/base/debug.cpp Normal file
View File

@ -0,0 +1,16 @@
/**
* @file debug.cpp
* @brief
* @author Richard Roberts
* @created Feb 1, 2011
*/
#include <gtsam/base/debug.h>
namespace gtsam {
#ifdef GTSAM_ENABLE_DEBUG
FastMap<std::string, ValueWithDefault<bool,false> > debugFlags;
#endif
}

50
gtsam/base/debug.h Normal file
View File

@ -0,0 +1,50 @@
/**
* @file debug.h
* @brief Global debugging flags
* @author Richard Roberts
* @created Feb 1, 2011
*/
#pragma once
#include <gtsam/base/FastMap.h>
#include <gtsam/base/types.h>
#include <string>
// This file defines granular debugging flags that may be switched on and off
// at run time. Typical usage is 'if(ISDEBUG("myFunction"))' to check if the
// 'myFunction' flag is enabled, and SETDEBUG("myFunction", true) to enable
// this flag, or SETDEBUG("myFunction", false) to disable it.
//
// Debug flags are created automatically as they are accessed, so they can be
// used immediately without explicitly creating them. Each flag defaults to
// 'false', i.e. disabled.
//
// For these macro to have any effect, granular debugging must be enabled by
// defining GTSAM_ENABLE_DEBUG. If NDEBUG is not defined, then
// GTSAM_ENABLE_DEBUG will be automatically defined and thus granular
// debugging enabled.
#ifndef NDEBUG
#ifndef GTSAM_ENABLE_DEBUG
#define GTSAM_ENABLE_DEBUG
#endif
#endif
#ifdef GTSAM_ENABLE_DEBUG
namespace gtsam {
extern FastMap<std::string, ValueWithDefault<bool,false> > debugFlags;
}
#define ISDEBUG(S) (gtsam::debugFlags[S])
#define SETDEBUG(S,V) (gtsam::debugFlags[S] = (V))
#else
#define ISDEBUG(S) (false)
#define SETDEBUG(S,V) (false)
#endif