diff --git a/gtsam/base/Makefile.am b/gtsam/base/Makefile.am index 1acc61b7d..ba13e1641 100644 --- a/gtsam/base/Makefile.am +++ b/gtsam/base/Makefile.am @@ -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 diff --git a/gtsam/base/debug.cpp b/gtsam/base/debug.cpp new file mode 100644 index 000000000..57951d756 --- /dev/null +++ b/gtsam/base/debug.cpp @@ -0,0 +1,16 @@ +/** + * @file debug.cpp + * @brief + * @author Richard Roberts + * @created Feb 1, 2011 + */ + +#include + +namespace gtsam { + +#ifdef GTSAM_ENABLE_DEBUG + FastMap > debugFlags; +#endif + +} diff --git a/gtsam/base/debug.h b/gtsam/base/debug.h new file mode 100644 index 000000000..215766661 --- /dev/null +++ b/gtsam/base/debug.h @@ -0,0 +1,50 @@ +/** + * @file debug.h + * @brief Global debugging flags + * @author Richard Roberts + * @created Feb 1, 2011 + */ + +#pragma once + +#include +#include +#include + + +// 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 > 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 +