You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "iBase_global.h"
|
|
#include <IxDynObj.h>
|
|
|
|
class QLibrary;
|
|
class QString;
|
|
class QStringList;
|
|
|
|
// 对象工厂方法
|
|
typedef IxDynObj* (*ZX_OBJECT_CREATOR)();
|
|
|
|
// 内部辅助实现
|
|
struct I_BASE_EXPORT __RegisterObjectCreatorEx
|
|
{
|
|
__RegisterObjectCreatorEx(const char* _file, int _line, const char* _tagName, const char* _className, ZX_OBJECT_CREATOR _creator);
|
|
};
|
|
|
|
// 查找动态对象的工厂方法
|
|
I_BASE_EXPORT ZX_OBJECT_CREATOR zxFindDynamicCreator(const char* _tagName);
|
|
|
|
// 这是zxDynamicCreate的别名, 请不要在应用层直接使用.
|
|
I_BASE_EXPORT IxDynObj* _zxDynamicCreate(const char* _tagName);
|
|
|
|
// 创建动态对象
|
|
inline static IxDynObj* zxDynamicCreate(const char* _tagName)
|
|
{
|
|
return _zxDynamicCreate(_tagName);
|
|
}
|
|
|
|
// 创建动态对象, 并转换为指定类型
|
|
template <typename T>
|
|
inline static T zxDynamicCreate(const char* _tagName)
|
|
{
|
|
IxDynObj * p = _zxDynamicCreate(_tagName);
|
|
T o = dynamic_cast<T>(p);
|
|
if (p && !o)
|
|
{
|
|
Q_ASSERT_X(0, __FUNCTION__, "incompatible object type.");
|
|
delete p;
|
|
}
|
|
return o;
|
|
}
|
|
|
|
// 声明动态创建
|
|
# define ZX_DECLARE_DYNAMIC \
|
|
public: \
|
|
const char* getClassName() const; \
|
|
const char* getTagName() const; \
|
|
private:
|
|
|
|
// 实现动态创建
|
|
// ZX_DEFINE_DYNAMIC( MyClass, ZxMyClass )
|
|
# define ZX_DEFINE_DYNAMIC(tagName, className) \
|
|
extern "C" Q_DECL_EXPORT IxDynObj * _zx_dycreate_##tagName() {return new className();}\
|
|
static struct __RegisterObjectCreatorEx _zx_dyregister_##tagName(__FILE__, __LINE__, #tagName, #className, &_zx_dycreate_##tagName);\
|
|
const char* className::getClassName() const { return #className;}\
|
|
const char* className::getTagName() const { return #tagName;}
|
|
|
|
// 加载动态链接库(DLL)
|
|
//I_BASE_EXPORT QLibrary* zxLoadDll(const QString& baseName);
|
|
|
|
|