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