cannam@140: #include "portaudiocpp/Exception.hxx" cannam@140: cannam@140: namespace portaudio cannam@140: { cannam@140: // ----------------------------------------------------------------------------------- cannam@140: // PaException: cannam@140: // ----------------------------------------------------------------------------------- cannam@140: cannam@140: ////// cannam@140: /// Wraps a PortAudio error into a PortAudioCpp PaException. cannam@140: ////// cannam@140: PaException::PaException(PaError error) : error_(error) cannam@140: { cannam@140: } cannam@140: cannam@140: // ----------------------------------------------------------------------------------- cannam@140: cannam@140: ////// cannam@140: /// Alias for paErrorText(), to have std::exception compliance. cannam@140: ////// cannam@140: const char *PaException::what() const throw() cannam@140: { cannam@140: return paErrorText(); cannam@140: } cannam@140: cannam@140: // ----------------------------------------------------------------------------------- cannam@140: cannam@140: ////// cannam@140: /// Returns the PortAudio error code (PaError). cannam@140: ////// cannam@140: PaError PaException::paError() const cannam@140: { cannam@140: return error_; cannam@140: } cannam@140: cannam@140: ////// cannam@140: /// Returns the error as a (zero-terminated) text string. cannam@140: ////// cannam@140: const char *PaException::paErrorText() const cannam@140: { cannam@140: return Pa_GetErrorText(error_); cannam@140: } cannam@140: cannam@140: ////// cannam@140: /// Returns true is the error is a HostApi error. cannam@140: ////// cannam@140: bool PaException::isHostApiError() const cannam@140: { cannam@140: return (error_ == paUnanticipatedHostError); cannam@140: } cannam@140: cannam@140: ////// cannam@140: /// Returns the last HostApi error (which is the current one if cannam@140: /// isHostApiError() returns true) as an error code. cannam@140: ////// cannam@140: long PaException::lastHostApiError() const cannam@140: { cannam@140: return Pa_GetLastHostErrorInfo()->errorCode; cannam@140: } cannam@140: cannam@140: ////// cannam@140: /// Returns the last HostApi error (which is the current one if cannam@140: /// isHostApiError() returns true) as a (zero-terminated) text cannam@140: /// string, if it's available. cannam@140: ////// cannam@140: const char *PaException::lastHostApiErrorText() const cannam@140: { cannam@140: return Pa_GetLastHostErrorInfo()->errorText; cannam@140: } cannam@140: cannam@140: // ----------------------------------------------------------------------------------- cannam@140: cannam@140: bool PaException::operator==(const PaException &rhs) const cannam@140: { cannam@140: return (error_ == rhs.error_); cannam@140: } cannam@140: cannam@140: bool PaException::operator!=(const PaException &rhs) const cannam@140: { cannam@140: return !(*this == rhs); cannam@140: } cannam@140: cannam@140: // ----------------------------------------------------------------------------------- cannam@140: // PaCppException: cannam@140: // ----------------------------------------------------------------------------------- cannam@140: cannam@140: PaCppException::PaCppException(ExceptionSpecifier specifier) : specifier_(specifier) cannam@140: { cannam@140: } cannam@140: cannam@140: const char *PaCppException::what() const throw() cannam@140: { cannam@140: switch (specifier_) cannam@140: { cannam@140: case UNABLE_TO_ADAPT_DEVICE: cannam@140: { cannam@140: return "Unable to adapt the given device to the specified host api specific device extension"; cannam@140: } cannam@140: } cannam@140: cannam@140: return "Unknown exception"; cannam@140: } cannam@140: cannam@140: PaCppException::ExceptionSpecifier PaCppException::specifier() const cannam@140: { cannam@140: return specifier_; cannam@140: } cannam@140: cannam@140: bool PaCppException::operator==(const PaCppException &rhs) const cannam@140: { cannam@140: return (specifier_ == rhs.specifier_); cannam@140: } cannam@140: cannam@140: bool PaCppException::operator!=(const PaCppException &rhs) const cannam@140: { cannam@140: return !(*this == rhs); cannam@140: } cannam@140: cannam@140: // ----------------------------------------------------------------------------------- cannam@140: cannam@140: } // namespace portaudio cannam@140: cannam@140: