annotate src/portaudio_20140130/bindings/cpp/include/portaudiocpp/AutoSystem.hxx @ 169:223a55898ab9 tip default

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