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