Remove all use of nframes_t.
[ardour.git] / libs / audiographer / audiographer / debuggable.h
1 #ifndef AUDIOGRAPHER_DEBUGGABLE_H
2 #define AUDIOGRAPHER_DEBUGGABLE_H
3
4 #ifndef DEFAULT_DEBUG_LEVEL
5 #define DEFAULT_DEBUG_LEVEL DebugNone
6 #endif
7
8 #include <iostream>
9
10 namespace AudioGrapher
11 {
12
13 /// Compile time defined debug level
14 enum DebugLevel
15 {
16         DebugNone,     ///< Disabled
17         DebugObject,   ///< Object level stuff, ctors, initalizers etc.
18         DebugFlags,    ///< Debug ProcessContext flags only on process cycle level
19         DebugProcess,  ///< Process cycle level stuff
20         DebugVerbose,  ///< Lots of output, not on sample level
21         DebugSample    ///< Sample level stuff
22 };
23
24 /** Class that allows optimizing out debugging code during compile time.
25   * Usage: to take all advantage of this class you should wrap all 
26   * debugging statemets like this:
27   * \code
28   * if (debug_level (SomeDebugLevel) && other_optional_conditionals) {
29   *     debug_stream() << "Debug output" << std::endl;
30   * }
31   * \endcode
32   *
33   * The order of the conditionals in the if-clause is important.
34   * The checks specified in \a other_optional_conditionals are only
35   * optimized out if \a debug_level() is placed before it with a
36   * logical and (short-circuiting).
37   */
38 template<DebugLevel L = DEFAULT_DEBUG_LEVEL>
39 class Debuggable
40 {
41   protected:
42         Debuggable(std::ostream & debug_stream = std::cerr)
43                 : stream (debug_stream) {}
44
45         bool debug_level (DebugLevel level) {
46                 #ifdef NDEBUG
47                 return false;
48                 #else
49                 return L >= level;
50                 #endif
51         }
52         std::ostream & debug_stream() { return stream; }
53
54   private:
55           std::ostream & stream;
56 };
57
58
59 } // namespace
60
61 #endif // AUDIOGRAPHER_DEBUGGABLE_H