File size: 1,583 Bytes
83418c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
#ifndef INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX
#define INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX

// ---------------------------------------------------------------------------------------

#include "portaudiocpp/System.hxx"

// ---------------------------------------------------------------------------------------

namespace portaudio
{


	//////
	/// @brief A RAII idiom class to ensure automatic clean-up when an exception is 
	/// raised.
	///
	/// A simple helper class which uses the 'Resource Acquisition is Initialization' 
	/// idiom (RAII). Use this class to initialize/terminate the System rather than 
	/// using System directly. AutoSystem must be created on stack and must be valid 
	/// throughout the time you wish to use PortAudioCpp. Your 'main' function might be 
	/// a good place for it.
	///
	/// To avoid having to type portaudio::System::instance().xyz() all the time, it's usually 
	/// a good idea to make a reference to the System which can be accessed directly.
	/// @verbatim
	/// portaudio::AutoSys autoSys;
	/// portaudio::System &sys = portaudio::System::instance();
	/// @endverbatim
	//////
	class AutoSystem
	{
	public:
		AutoSystem(bool initialize = true)
		{
			if (initialize)
				System::initialize();
		}

		~AutoSystem()
		{
			if (System::exists())
				System::terminate();
		}

		void initialize()
		{
			System::initialize();
		}

		void terminate()
		{
			System::terminate();
		}
	};


} // namespace portaudio

// ---------------------------------------------------------------------------------------

#endif // INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX