From: <man...@us...> - 2013-05-12 10:02:07
|
Revision: 2050 http://sourceforge.net/p/modplug/code/2050 Author: manxorist Date: 2013-05-12 10:02:01 +0000 (Sun, 12 May 2013) Log Message: ----------- [Ref] Simplify openmpt::exception. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt.hpp trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp trunk/OpenMPT/openmpt123/openmpt123.cpp Modified: trunk/OpenMPT/libopenmpt/libopenmpt.hpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.hpp 2013-05-12 09:50:36 UTC (rev 2049) +++ trunk/OpenMPT/libopenmpt/libopenmpt.hpp 2013-05-12 10:02:01 UTC (rev 2050) @@ -25,12 +25,10 @@ class LIBOPENMPT_CXX_API exception : public std::exception { public: - exception( const char * text ) throw(); + exception() throw(); virtual ~exception() throw(); public: virtual const char * what() const throw(); -private: - const char * const text; }; // class exception LIBOPENMPT_CXX_API std::uint32_t get_library_version(); Modified: trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2013-05-12 09:50:36 UTC (rev 2049) +++ trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2013-05-12 10:02:01 UTC (rev 2050) @@ -254,7 +254,7 @@ #define OPENMPT_INTERFACE_CHECK_SOUNDFILE( mod ) \ do { \ if ( !(mod) ) { \ - throw openmpt::exception("module * not valid"); \ + throw openmpt::exception_message("module * not valid"); \ } \ } while(0) \ /**/ @@ -262,7 +262,7 @@ #define OPENMPT_INTERFACE_CHECK_POINTER( value ) \ do { \ if ( !(value) ) { \ - throw openmpt::exception("null pointer"); \ + throw openmpt::exception_message("null pointer"); \ } \ } while(0) \ /**/ Modified: trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp 2013-05-12 09:50:36 UTC (rev 2049) +++ trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp 2013-05-12 10:02:01 UTC (rev 2050) @@ -21,7 +21,7 @@ namespace openmpt { -exception::exception( const char * text_ ) throw() : text(text_) { +exception::exception() throw() { return; } @@ -30,7 +30,7 @@ } const char * exception::what() const throw() { - return text; + return ""; } std::uint32_t get_library_version() { Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp 2013-05-12 09:50:36 UTC (rev 2049) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp 2013-05-12 10:02:01 UTC (rev 2050) @@ -41,6 +41,18 @@ } // namespace version +class exception_message : public exception { +public: + exception_message( const char * text_ ) throw() : text(text_) { } + virtual ~exception_message() throw() { } +public: + virtual const char * what() const throw() { + return text; + } +private: + const char * text; +}; // class exception_message + class log_interface : public ILog { protected: log_interface() { @@ -146,7 +158,7 @@ } static void load( CSoundFile & sndFile, FileReader file ) { if ( !sndFile.Create( file, CSoundFile::loadCompleteModule ) ) { - throw openmpt::exception("error loading file"); + throw openmpt::exception_message("error loading file"); } } void load( FileReader file ) { @@ -266,7 +278,7 @@ default: break; } - throw exception("unknown interpolation mode set internally"); + throw openmpt::exception_message("unknown interpolation mode set internally"); } break; case module::RENDER_VOLUMERAMP_IN_SAMPLES: { return m_sndFile.m_MixerSettings.glVolumeRampUpSamples; @@ -274,7 +286,7 @@ case module::RENDER_VOLUMERAMP_OUT_SAMPLES: { return m_sndFile.m_MixerSettings.glVolumeRampDownSamples; } break; - default: throw exception("unknown command"); break; + default: throw openmpt::exception_message("unknown command"); break; } return 0; } @@ -343,12 +355,12 @@ m_sndFile.SetMixerSettings( settings ); } } break; - default: throw exception("unknown command"); break; + default: throw openmpt::exception_message("unknown command"); break; } } std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono ) { if ( !mono ) { - throw exception("null pointer"); + throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 1, SampleFormatInt16 ); m_int16Buffer.resize( count * 1 ); @@ -361,7 +373,7 @@ } std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right ) { if ( !left || !right ) { - throw exception("null pointer"); + throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 2, SampleFormatInt16 ); m_int16Buffer.resize( count * 2 ); @@ -375,7 +387,7 @@ } std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * back_left, std::int16_t * back_right ) { if ( !left || !right || !back_left || !back_right ) { - throw exception("null pointer"); + throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 4, SampleFormatInt16 ); m_int16Buffer.resize( count * 4 ); @@ -391,7 +403,7 @@ } std::size_t read( std::int32_t samplerate, std::size_t count, float * mono ) { if ( !mono ) { - throw exception("null pointer"); + throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 1, SampleFormatFloat32 ); m_floatBuffer.resize( count * 1 ); @@ -404,7 +416,7 @@ } std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right ) { if ( !left || !right ) { - throw exception("null pointer"); + throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 2, SampleFormatFloat32 ); m_floatBuffer.resize( count * 2 ); @@ -418,7 +430,7 @@ } std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * back_left, float * back_right ) { if ( !left || !right || !back_left || !back_right ) { - throw exception("null pointer"); + throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 4, SampleFormatFloat32 ); m_floatBuffer.resize( count * 4 ); Modified: trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp 2013-05-12 09:50:36 UTC (rev 2049) +++ trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp 2013-05-12 10:02:01 UTC (rev 2050) @@ -107,9 +107,18 @@ namespace detail { +class version_mismatch : public openmpt::exception { +public: + version_mismatch() throw() { } + virtual ~version_mismatch() throw() { } + virtual const char * what() const throw() { + return "API and header version mismatch"; + } +}; // class version_mismatch + void version_compatible_or_throw( std::int32_t api_version ) { if ( version::get_version_compatbility( api_version ) < 2 ) { - throw exception( "API and header version mismatch" ); + throw version_mismatch(); } } Modified: trunk/OpenMPT/openmpt123/openmpt123.cpp =================================================================== --- trunk/OpenMPT/openmpt123/openmpt123.cpp 2013-05-12 09:50:36 UTC (rev 2049) +++ trunk/OpenMPT/openmpt123/openmpt123.cpp 2013-05-12 10:02:01 UTC (rev 2050) @@ -40,7 +40,11 @@ }; struct openmpt123_exception : public openmpt::exception { - openmpt123_exception( const char * text ) throw() : openmpt::exception( text ) { } + openmpt123_exception( const char * text_ ) throw() : text(text_) { } + virtual const char * what() const throw() { + return text; + } + const char * text; }; struct silent_exit_exception : public std::exception { @@ -51,8 +55,8 @@ show_version_number_exception() throw() { } }; -struct portaudio_exception : public openmpt::exception { - portaudio_exception( PaError code ) throw() : openmpt::exception( Pa_GetErrorText( code ) ) { } +struct portaudio_exception : public openmpt123_exception { + portaudio_exception( PaError code ) throw() : openmpt123_exception( Pa_GetErrorText( code ) ) { } }; struct openmpt123_flags { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |