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