From: <man...@us...> - 2015-05-03 20:31:14
|
Revision: 5039 http://sourceforge.net/p/modplug/code/5039 Author: manxorist Date: 2015-05-03 20:31:07 +0000 (Sun, 03 May 2015) Log Message: ----------- [Ref] Split dynamic library handling concerns from ComponentBase into a separate ComponentLibrary class. Modified Paths: -------------- trunk/OpenMPT/common/ComponentManager.cpp trunk/OpenMPT/common/ComponentManager.h trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp trunk/OpenMPT/soundlib/Load_mo3.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp Modified: trunk/OpenMPT/common/ComponentManager.cpp =================================================================== --- trunk/OpenMPT/common/ComponentManager.cpp 2015-05-03 20:10:21 UTC (rev 5038) +++ trunk/OpenMPT/common/ComponentManager.cpp 2015-05-03 20:31:07 UTC (rev 5039) @@ -24,7 +24,6 @@ : m_Type(type) , m_Initialized(false) , m_Available(false) - , m_BindFailed(false) { return; } @@ -37,6 +36,22 @@ } +ComponentLibrary::ComponentLibrary(ComponentType type) +//---------------------------------------------------- + : ComponentBase(type) + , m_BindFailed(false) +{ + return; +} + + +ComponentLibrary::~ComponentLibrary() +//----------------------------------- +{ + return; +} + + void ComponentBase::SetName(const std::string &name) //-------------------------------------------------- { @@ -58,8 +73,8 @@ } -bool ComponentBase::AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath) -//----------------------------------------------------------------------------------------- +bool ComponentLibrary::AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath) +//-------------------------------------------------------------------------------------------- { if(m_Libraries[libName].IsValid()) { @@ -76,29 +91,29 @@ } -void ComponentBase::ClearLibraries() -//---------------------------------- +void ComponentLibrary::ClearLibraries() +//------------------------------------- { m_Libraries.clear(); } -void ComponentBase::SetBindFailed() -//--------------------------------- +void ComponentLibrary::SetBindFailed() +//------------------------------------ { m_BindFailed = true; } -void ComponentBase::ClearBindFailed() -//----------------------------------- +void ComponentLibrary::ClearBindFailed() +//-------------------------------------- { m_BindFailed = false; } -bool ComponentBase::HasBindFailed() const -//--------------------------------------- +bool ComponentLibrary::HasBindFailed() const +//------------------------------------------ { return m_BindFailed; } @@ -139,8 +154,8 @@ } -mpt::Library ComponentBase::GetLibrary(const std::string &libName) const -//---------------------------------------------------------------------- +mpt::Library ComponentLibrary::GetLibrary(const std::string &libName) const +//------------------------------------------------------------------------- { TLibraryMap::const_iterator it = m_Libraries.find(libName); if(it == m_Libraries.end()) Modified: trunk/OpenMPT/common/ComponentManager.h =================================================================== --- trunk/OpenMPT/common/ComponentManager.h 2015-05-03 20:10:21 UTC (rev 5038) +++ trunk/OpenMPT/common/ComponentManager.h 2015-05-03 20:31:07 UTC (rev 5039) @@ -70,8 +70,6 @@ virtual void Initialize() = 0; // try to load the component - virtual mpt::Library GetLibrary(const std::string &libName) const = 0; - }; @@ -80,15 +78,12 @@ { private: + std::string m_Name; ComponentType m_Type; - + bool m_Initialized; bool m_Available; - typedef std::map<std::string, mpt::Library> TLibraryMap; - TLibraryMap m_Libraries; - - bool m_BindFailed; protected: @@ -103,11 +98,6 @@ void SetName(const std::string &name); void SetInitialized(); void SetAvailable(); - bool AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath); - void ClearLibraries(); - void SetBindFailed(); - void ClearBindFailed(); - bool HasBindFailed() const; public: @@ -115,13 +105,51 @@ virtual ComponentType GetType() const; virtual bool IsInitialized() const; virtual bool IsAvailable() const; - + virtual mpt::ustring GetVersion() const; + +public: + + virtual void Initialize(); + +protected: + + virtual bool DoInitialize() = 0; + +}; + + +class ComponentLibrary + : public ComponentBase +{ + +private: + typedef std::map<std::string, mpt::Library> TLibraryMap; + TLibraryMap m_Libraries; + + bool m_BindFailed; + +protected: + + ComponentLibrary(ComponentType type); + +public: + + virtual ~ComponentLibrary(); + +protected: + + bool AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath); + void ClearLibraries(); + void SetBindFailed(); + void ClearBindFailed(); + bool HasBindFailed() const; + +public: + virtual mpt::Library GetLibrary(const std::string &libName) const; - virtual void Initialize(); - template <typename Tfunc> bool Bind(Tfunc * & f, const std::string &libName, const std::string &symbol) const { @@ -134,6 +162,7 @@ }; + #define MPT_COMPONENT_BIND(libName, func) do { if(!Bind( func , libName , #func )) { SetBindFailed(); } } while(0) #define MPT_COMPONENT_BIND_OPTIONAL(libName, func) Bind( func , libName , #func ) #define MPT_COMPONENT_BIND_SYMBOL(libName, symbol, func) do { if(!Bind( func , libName , symbol )) { SetBindFailed(); } } while(0) @@ -155,13 +184,13 @@ }; -class ComponentSystemDLL : public ComponentBase +class ComponentSystemDLL : public ComponentLibrary { private: mpt::PathString m_BaseName; public: ComponentSystemDLL(const mpt::PathString &baseName) - : ComponentBase(ComponentTypeSystem) + : ComponentLibrary(ComponentTypeSystem) , m_BaseName(baseName) { return; @@ -174,13 +203,13 @@ }; -class ComponentBundledDLL : public ComponentBase +class ComponentBundledDLL : public ComponentLibrary { private: mpt::PathString m_FullName; public: ComponentBundledDLL(const mpt::PathString &fullName) - : ComponentBase(ComponentTypeBundled) + : ComponentLibrary(ComponentTypeBundled) , m_FullName(fullName) { return; Modified: trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp =================================================================== --- trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp 2015-05-03 20:10:21 UTC (rev 5038) +++ trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp 2015-05-03 20:31:07 UTC (rev 5039) @@ -255,7 +255,7 @@ typedef lame_global_flags *lame_t; class ComponentLame - : public ComponentBase + : public ComponentLibrary { MPT_DECLARE_COMPONENT_MEMBERS @@ -329,7 +329,7 @@ public: ComponentLame() - : ComponentBase(ComponentTypeForeign) + : ComponentLibrary(ComponentTypeForeign) { return; } @@ -645,7 +645,7 @@ #ifdef MPT_MP3ENCODER_BLADE class ComponentBlade - : public ComponentBase + : public ComponentLibrary { MPT_DECLARE_COMPONENT_MEMBERS @@ -673,7 +673,7 @@ public: ComponentBlade() - : ComponentBase(ComponentTypeForeign) + : ComponentLibrary(ComponentTypeForeign) , isLame(false) { return; Modified: trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp =================================================================== --- trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp 2015-05-03 20:10:21 UTC (rev 5038) +++ trunk/OpenMPT/mptrack/StreamEncoderOpus.cpp 2015-05-03 20:31:07 UTC (rev 5039) @@ -35,7 +35,7 @@ class ComponentOpus - : public ComponentBase + : public ComponentLibrary { MPT_DECLARE_COMPONENT_MEMBERS @@ -65,7 +65,7 @@ public: ComponentOpus() - : ComponentBase(ComponentTypeForeign) + : ComponentLibrary(ComponentTypeForeign) { return; } Modified: trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp =================================================================== --- trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp 2015-05-03 20:10:21 UTC (rev 5038) +++ trunk/OpenMPT/mptrack/StreamEncoderVorbis.cpp 2015-05-03 20:31:07 UTC (rev 5039) @@ -29,7 +29,7 @@ class ComponentVorbis - : public ComponentBase + : public ComponentLibrary { MPT_DECLARE_COMPONENT_MEMBERS @@ -69,7 +69,7 @@ public: ComponentVorbis() - : ComponentBase(ComponentTypeForeign) + : ComponentLibrary(ComponentTypeForeign) { return; } Modified: trunk/OpenMPT/soundlib/Load_mo3.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mo3.cpp 2015-05-03 20:10:21 UTC (rev 5038) +++ trunk/OpenMPT/soundlib/Load_mo3.cpp 2015-05-03 20:31:07 UTC (rev 5039) @@ -34,7 +34,7 @@ #ifndef NO_MO3 -class ComponentUnMO3 : public ComponentBase +class ComponentUnMO3 : public ComponentLibrary { MPT_DECLARE_COMPONENT_MEMBERS public: @@ -52,7 +52,7 @@ return (UNMO3_Decode_New ? UNMO3_Decode_New(data, len, flags) : UNMO3_Decode_Old(data, len)); } public: - ComponentUnMO3() : ComponentBase(ComponentTypeForeign) { } + ComponentUnMO3() : ComponentLibrary(ComponentTypeForeign) { } std::string GetSettingsKey() const { return "UnMO3"; } bool DoInitialize() { Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2015-05-03 20:10:21 UTC (rev 5038) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2015-05-03 20:31:07 UTC (rev 5039) @@ -2539,7 +2539,7 @@ #ifndef NO_MP3_SAMPLES -class ComponentMPG123 : public ComponentBase +class ComponentMPG123 : public ComponentLibrary { MPT_DECLARE_COMPONENT_MEMBERS public: @@ -2576,7 +2576,7 @@ MPG123_ENC_16 = 0x040, MPG123_ENC_SIGNED = 0x080, }; public: - ComponentMPG123() : ComponentBase(ComponentTypeForeign) { } + ComponentMPG123() : ComponentLibrary(ComponentTypeForeign) { } std::string GetSettingsKey() const { return "Mpg123"; } bool DoInitialize() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |