annotate src/portaudio_20161030/bindings/cpp/source/portaudiocpp/Exception.cxx @ 55:284acf908dcd

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