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