comparison src/portaudio/bindings/cpp/include/portaudiocpp/AutoSystem.hxx @ 4:e13257ea84a4

Add bzip2, zlib, liblo, portaudio sources
author Chris Cannam
date Wed, 20 Mar 2013 13:59:52 +0000
parents
children
comparison
equal deleted inserted replaced
3:6c505a35919a 4:e13257ea84a4
1 #ifndef INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX
2 #define INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX
3
4 // ---------------------------------------------------------------------------------------
5
6 #include "portaudiocpp/System.hxx"
7
8 // ---------------------------------------------------------------------------------------
9
10 namespace portaudio
11 {
12
13
14 //////
15 /// @brief A RAII idiom class to ensure automatic clean-up when an exception is
16 /// raised.
17 ///
18 /// A simple helper class which uses the 'Resource Acquisition is Initialization'
19 /// idiom (RAII). Use this class to initialize/terminate the System rather than
20 /// using System directly. AutoSystem must be created on stack and must be valid
21 /// throughout the time you wish to use PortAudioCpp. Your 'main' function might be
22 /// a good place for it.
23 ///
24 /// To avoid having to type portaudio::System::instance().xyz() all the time, it's usually
25 /// a good idea to make a reference to the System which can be accessed directly.
26 /// @verbatim
27 /// portaudio::AutoSys autoSys;
28 /// portaudio::System &sys = portaudio::System::instance();
29 /// @endverbatim
30 //////
31 class AutoSystem
32 {
33 public:
34 AutoSystem(bool initialize = true)
35 {
36 if (initialize)
37 System::initialize();
38 }
39
40 ~AutoSystem()
41 {
42 if (System::exists())
43 System::terminate();
44 }
45
46 void initialize()
47 {
48 System::initialize();
49 }
50
51 void terminate()
52 {
53 System::terminate();
54 }
55 };
56
57
58 } // namespace portaudio
59
60 // ---------------------------------------------------------------------------------------
61
62 #endif // INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX