mirror of
https://github.com/znc/znc.git
synced 2026-06-28 22:11:14 +02:00
CModule: use member initialization lists [-Weffc++] (#270)
This fixes the problem that CModule::GetType() returned a random uninitialized value in CModule constructor, which was als the reason for #905. CModule constructor signature has been changed so that it optionally takes the type so it can be initialized appropriately. The new type argument has a default value in order to retain source compatibility in case some 3rdparty module would call CModule ctor by hand instead of using the MODCONSTRUCTOR macro.
This commit is contained in:
+26
-23
@@ -49,16 +49,6 @@ class CModInfo;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef void* ModHandle;
|
||||
|
||||
template<class M> void TModInfo(CModInfo& Info) {}
|
||||
|
||||
template<class M> CModule* TModLoad(ModHandle p, CUser* pUser,
|
||||
CIRCNetwork* pNetwork, const CString& sModName,
|
||||
const CString& sModPath) {
|
||||
return new M(p, pUser, pNetwork, sModName, sModPath);
|
||||
}
|
||||
|
||||
#if HAVE_VISIBILITY
|
||||
# define MODULE_EXPORT __attribute__((__visibility__("default")))
|
||||
#else
|
||||
@@ -97,8 +87,8 @@ template<class M> CModule* TModLoad(ModHandle p, CUser* pUser,
|
||||
*/
|
||||
#define MODCONSTRUCTOR(CLASS) \
|
||||
CLASS(ModHandle pDLL, CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, \
|
||||
const CString& sModPath) \
|
||||
: CModule(pDLL, pUser, pNetwork, sModName, sModPath)
|
||||
const CString& sModPath, CModInfo::EModuleType eType) \
|
||||
: CModule(pDLL, pUser, pNetwork, sModName, sModPath, eType)
|
||||
|
||||
// User Module Macros
|
||||
/** This works exactly like MODULEDEFS, but for user modules. */
|
||||
@@ -209,25 +199,30 @@ protected:
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef void* ModHandle;
|
||||
|
||||
class CModInfo {
|
||||
public:
|
||||
typedef CModule* (*ModLoader)(ModHandle p, CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sModPath);
|
||||
|
||||
typedef enum {
|
||||
GlobalModule,
|
||||
UserModule,
|
||||
NetworkModule
|
||||
} EModuleType;
|
||||
|
||||
CModInfo() {
|
||||
m_fLoader = nullptr;
|
||||
m_bHasArgs = false;
|
||||
typedef CModule* (*ModLoader)(ModHandle p, CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sModPath, EModuleType eType);
|
||||
|
||||
CModInfo() : CModInfo("", "", NetworkModule) {
|
||||
}
|
||||
CModInfo(const CString& sName, const CString& sPath, EModuleType eType) {
|
||||
m_sName = sName;
|
||||
m_sPath = sPath;
|
||||
m_fLoader = nullptr;
|
||||
m_bHasArgs = false;
|
||||
CModInfo(const CString& sName, const CString& sPath, EModuleType eType)
|
||||
: m_seType(),
|
||||
m_eDefaultType(eType),
|
||||
m_sName(sName),
|
||||
m_sPath(sPath),
|
||||
m_sDescription(""),
|
||||
m_sWikiPage(""),
|
||||
m_sArgsHelpText(""),
|
||||
m_bHasArgs(false),
|
||||
m_fLoader(nullptr) {
|
||||
}
|
||||
~CModInfo() {}
|
||||
|
||||
@@ -286,6 +281,14 @@ protected:
|
||||
ModLoader m_fLoader;
|
||||
};
|
||||
|
||||
template<class M> void TModInfo(CModInfo& Info) {}
|
||||
|
||||
template<class M> CModule* TModLoad(ModHandle p, CUser* pUser,
|
||||
CIRCNetwork* pNetwork, const CString& sModName,
|
||||
const CString& sModPath, CModInfo::EModuleType eType) {
|
||||
return new M(p, pUser, pNetwork, sModName, sModPath, eType);
|
||||
}
|
||||
|
||||
/** A helper class for handling commands in modules. */
|
||||
class CModCommand {
|
||||
public:
|
||||
@@ -356,7 +359,7 @@ private:
|
||||
class CModule {
|
||||
public:
|
||||
CModule(ModHandle pDLL, CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName,
|
||||
const CString& sDataDir);
|
||||
const CString& sDataDir, CModInfo::EModuleType eType = CModInfo::NetworkModule); // TODO: remove default value in ZNC 2.x
|
||||
virtual ~CModule();
|
||||
|
||||
CModule(const CModule&) = delete;
|
||||
|
||||
Reference in New Issue
Block a user