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