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