add export control with -fvisibility=hidden to audiographer
[ardour.git] / libs / audiographer / audiographer / throwing.h
1 #ifndef AUDIOGRAPHER_THROWING_H
2 #define AUDIOGRAPHER_THROWING_H
3
4 #ifndef DEFAULT_THROW_LEVEL
5 #define DEFAULT_THROW_LEVEL ThrowStrict
6 #endif
7
8 #include "audiographer/visibility.h"
9
10 namespace AudioGrapher
11 {
12
13 /** Compile time defined throw level.
14   * Throw levels less than ThrowStrict should be used with caution.
15   * Not throwing could mean getting a segfault.
16   * However, if you want ultra-optimized code and/or don't care about handling
17   * error situations, feel free to use whatever you want.
18   */
19 enum LIBAUDIOGRAPHER_API ThrowLevel
20 {
21         ThrowNone,     ///< Not allowed to throw
22         ThrowObject,   ///< Object level stuff, ctors, initalizers etc.
23         ThrowProcess,  ///< Process cycle level stuff
24         ThrowStrict,   ///< Stricter checks than ThrowProcess, less than ThrowSample
25         ThrowSample    ///< Sample level stuff
26 };
27
28 /** Class that allows optimizing out error checking during compile time.
29   * Usage: to take all advantage of this class you should wrap all 
30   * throwing statemets like this:
31   * \code
32   * if (throw_level (SomeThrowLevel) && other_optional_conditionals) {
33   *     throw Exception (...);
34   * }
35   * \endcode
36   *
37   * The order of the conditionals in the if-clause is important.
38   * The checks specified in \a other_optional_conditionals are only
39   * optimized out if \a throw_level() is placed before it with a
40   * logical and (short-circuiting).
41   */
42 template<ThrowLevel L = DEFAULT_THROW_LEVEL>
43 class LIBAUDIOGRAPHER_API Throwing
44 {
45   protected:
46         Throwing() {}
47         bool throw_level (ThrowLevel level) { return L >= level; }
48 };
49
50
51 } // namespace
52
53 #endif // AUDIOGRAPHER_THROWING_H