annotate src/portaudio/bindings/cpp/include/portaudiocpp/AutoSystem.hxx @ 107:71c914cf6201

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