logplus/Workflow/WFEngine/Module/include/ModuleFactory.h
2026-01-16 17:18:41 +08:00

95 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file ModuleFactory.h
* @brief 文件定义了模块创建的工厂类
* @author dev
* @date 2011-8-30
*/
#ifndef PAI_FRAME_MODULEAPI_MODULEFACTORY_H
#define PAI_FRAME_MODULEAPI_MODULEFACTORY_H
#include <string>
#include <map>
#include "Turtle.h"
/**
* @brief 定义创建模块实例的全局宏
*/
#define DECLARE_PAI_MODULE(classname) static CModule* CreateInstance(){return new classname();} virtual std::string GetClassName() {return std::string(#classname);} virtual void Delete(){delete this;}
/**
* @brief 定义注册模块的全局宏
*/
#define IMPLEMENT_PAI_MODULE(classname) namespace pai{namespace module{class regist##classname { public:regist##classname(){CModuleFactory::Instance()->Register(#classname,classname::CreateInstance);}};}} \
pai::module::regist##classname g_##classname##_creator;
namespace pai {
namespace module {
class CModule;
/**
* @class CModuleFactory
* @brief 定义了与创建模块相关的接口,模块开发人员请不要使用此类,如需要请使用<code>ModuleManger</code>
* @see CModuleManager
*/
class PAI_MODULE_EXPORT CModuleFactory
{
public:
/**
* @var typedef CModule* (*pCreateObjectFunction)()
* @brief 定义创建模块的函数指针
*/
typedef CModule* (*pCreateObjectFunction)();
/**
* @brief 获取<code>CModuleFactory</code>实例指针
* @return <code>CModuleFactory</code>实例指针
*/
static CModuleFactory* Instance();
/**
* @brief 根据注册的模块名创建模块
* @param[in] typeID 注册的模块类名
* @return 模块<code>CModule</code>指针
*/
CModule* CreateModule(const std::string& typeID);
/**
* @brief 根据类名注册模块
* @param[in] typeID 注册的模块类名
* @param[in] pFunc 创建模块的函数指针
* @return 注册成功返回true否则返回false
*/
bool Register(const std::string& typeID,pCreateObjectFunction pFunc);
private:
/**
* @brief 构造函数
*/
CModuleFactory():m_mapCreateFunctions()
{
}
/**
* @brief 析构函数
*/
~CModuleFactory()
{
}
/**
* @brief 拷贝构造
*/
CModuleFactory(const CModuleFactory&);
/**
* @brief 赋值构造
*/
CModuleFactory& operator=(const CModuleFactory&);
private:
std::map<std::string,pCreateObjectFunction> m_mapCreateFunctions;
};
}
}
#endif