~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/audiographer/audiographer/throwing.h

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

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