annotate src/portaudio/bindings/cpp/source/portaudiocpp/Exception.cxx @ 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 #include "portaudiocpp/Exception.hxx"
cannam@89 2
cannam@89 3 namespace portaudio
cannam@89 4 {
cannam@89 5 // -----------------------------------------------------------------------------------
cannam@89 6 // PaException:
cannam@89 7 // -----------------------------------------------------------------------------------
cannam@89 8
cannam@89 9 //////
cannam@89 10 /// Wraps a PortAudio error into a PortAudioCpp PaException.
cannam@89 11 //////
cannam@89 12 PaException::PaException(PaError error) : error_(error)
cannam@89 13 {
cannam@89 14 }
cannam@89 15
cannam@89 16 // -----------------------------------------------------------------------------------
cannam@89 17
cannam@89 18 //////
cannam@89 19 /// Alias for paErrorText(), to have std::exception compliance.
cannam@89 20 //////
cannam@89 21 const char *PaException::what() const throw()
cannam@89 22 {
cannam@89 23 return paErrorText();
cannam@89 24 }
cannam@89 25
cannam@89 26 // -----------------------------------------------------------------------------------
cannam@89 27
cannam@89 28 //////
cannam@89 29 /// Returns the PortAudio error code (PaError).
cannam@89 30 //////
cannam@89 31 PaError PaException::paError() const
cannam@89 32 {
cannam@89 33 return error_;
cannam@89 34 }
cannam@89 35
cannam@89 36 //////
cannam@89 37 /// Returns the error as a (zero-terminated) text string.
cannam@89 38 //////
cannam@89 39 const char *PaException::paErrorText() const
cannam@89 40 {
cannam@89 41 return Pa_GetErrorText(error_);
cannam@89 42 }
cannam@89 43
cannam@89 44 //////
cannam@89 45 /// Returns true is the error is a HostApi error.
cannam@89 46 //////
cannam@89 47 bool PaException::isHostApiError() const
cannam@89 48 {
cannam@89 49 return (error_ == paUnanticipatedHostError);
cannam@89 50 }
cannam@89 51
cannam@89 52 //////
cannam@89 53 /// Returns the last HostApi error (which is the current one if
cannam@89 54 /// isHostApiError() returns true) as an error code.
cannam@89 55 //////
cannam@89 56 long PaException::lastHostApiError() const
cannam@89 57 {
cannam@89 58 return Pa_GetLastHostErrorInfo()->errorCode;
cannam@89 59 }
cannam@89 60
cannam@89 61 //////
cannam@89 62 /// Returns the last HostApi error (which is the current one if
cannam@89 63 /// isHostApiError() returns true) as a (zero-terminated) text
cannam@89 64 /// string, if it's available.
cannam@89 65 //////
cannam@89 66 const char *PaException::lastHostApiErrorText() const
cannam@89 67 {
cannam@89 68 return Pa_GetLastHostErrorInfo()->errorText;
cannam@89 69 }
cannam@89 70
cannam@89 71 // -----------------------------------------------------------------------------------
cannam@89 72
cannam@89 73 bool PaException::operator==(const PaException &rhs) const
cannam@89 74 {
cannam@89 75 return (error_ == rhs.error_);
cannam@89 76 }
cannam@89 77
cannam@89 78 bool PaException::operator!=(const PaException &rhs) const
cannam@89 79 {
cannam@89 80 return !(*this == rhs);
cannam@89 81 }
cannam@89 82
cannam@89 83 // -----------------------------------------------------------------------------------
cannam@89 84 // PaCppException:
cannam@89 85 // -----------------------------------------------------------------------------------
cannam@89 86
cannam@89 87 PaCppException::PaCppException(ExceptionSpecifier specifier) : specifier_(specifier)
cannam@89 88 {
cannam@89 89 }
cannam@89 90
cannam@89 91 const char *PaCppException::what() const throw()
cannam@89 92 {
cannam@89 93 switch (specifier_)
cannam@89 94 {
cannam@89 95 case UNABLE_TO_ADAPT_DEVICE:
cannam@89 96 {
cannam@89 97 return "Unable to adapt the given device to the specified host api specific device extension";
cannam@89 98 }
cannam@89 99 }
cannam@89 100
cannam@89 101 return "Unknown exception";
cannam@89 102 }
cannam@89 103
cannam@89 104 PaCppException::ExceptionSpecifier PaCppException::specifier() const
cannam@89 105 {
cannam@89 106 return specifier_;
cannam@89 107 }
cannam@89 108
cannam@89 109 bool PaCppException::operator==(const PaCppException &rhs) const
cannam@89 110 {
cannam@89 111 return (specifier_ == rhs.specifier_);
cannam@89 112 }
cannam@89 113
cannam@89 114 bool PaCppException::operator!=(const PaCppException &rhs) const
cannam@89 115 {
cannam@89 116 return !(*this == rhs);
cannam@89 117 }
cannam@89 118
cannam@89 119 // -----------------------------------------------------------------------------------
cannam@89 120
cannam@89 121 } // namespace portaudio
cannam@89 122
cannam@89 123