1 #ifndef AUDIOGRAPHER_THROWING_H
2 #define AUDIOGRAPHER_THROWING_H
4 #ifndef DEFAULT_THROW_LEVEL
5 #define DEFAULT_THROW_LEVEL ThrowStrict
8 #include "audiographer/visibility.h"
10 namespace AudioGrapher
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.
19 enum LIBAUDIOGRAPHER_API ThrowLevel
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
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:
32 * if (throw_level (SomeThrowLevel) && other_optional_conditionals) {
33 * throw Exception (...);
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).
42 template<ThrowLevel L = DEFAULT_THROW_LEVEL>
43 class LIBAUDIOGRAPHER_API Throwing
47 bool throw_level (ThrowLevel level) { return L >= level; }
53 #endif // AUDIOGRAPHER_THROWING_H