annotate src/portaudio/bindings/cpp/source/portaudiocpp/Exception.cxx @ 19:891f60ab2af1

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