annotate src/portaudio_20140130/bindings/cpp/source/portaudiocpp/Exception.cxx @ 83:ae30d91d2ffe

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