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.

138 lines
3.9 KiB
C

/**
*
* @file FITKProgramDriverFactory.h
* @brief
* @author libaojun (libaojunqd@Foxmail.com)
* @date 2024-06-09
*
*/
#ifndef _FITK_PROGRAMDRIVER_FACTORY_H___
#define _FITK_PROGRAMDRIVER_FACTORY_H___
#include "FITKAppFrameworkAPI.h"
#include "FITK_Kernel/FITKCore/FITKCoreMacros.h"
#include "FITK_Kernel/FITKCore/FITKAbstractObject.hpp"
#include <QMutex>
#include <QStringList>
namespace AppFrame
{
class FITKAbstractProgramerDriver;
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-10
*/
#ifndef DRIVERTypeFuns
#define DRIVERTypeFuns QHash<QString,std::function<FITKAbstractProgramerDriver*()> >
#endif
class FITKProgramDriverFactoryDeleator;
/**
* @brief
* @author libaojun (libaojunqd@Foxmail.com)
* @date 2024-06-09
*/
class FITKAppFrameworkAPI FITKProgramDriverFactory
: public Core::FITKAbstractObject
{
friend FITKProgramDriverFactoryDeleator;
//声明为单例
DeclSingleton(FITKProgramDriverFactory);
public:
/**
* @brief
* @return QList<int>
* @author libaojun (libaojunqd@Foxmail.com)
* @date 2024-06-15
*/
QList<int> getProgramTypes();
/**
* @brief
* @param[i] driverType
* @return QStringList
* @author libaojun (libaojunqd@Foxmail.com)
* @date 2024-06-15
*/
QStringList getProgramDrivers(const int driverType);
/**
* @brief
* @param[i] t
* @param[i] driver
* @return std::function<FITKAbstractProgramerDriver*()>
* @author libaojun (libaojunqd@Foxmail.com)
* @date 2024-06-15
*/
std::function<FITKAbstractProgramerDriver*()> getDriverCreateFun(const int t, const QString driver);
private:
/**
* @brief
* @author libaojun (libaojunqd@Foxmail.com)
* @date 2024-06-09
*/
void initialize();
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-17
*/
void finalize();
private:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-10
*/
QHash<int, DRIVERTypeFuns> _createFuns{};
public:
template < typename T >
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-10
*/
class FITKDriverRegHelper
{
public:
FITKDriverRegHelper(int type, QString driverName)
{
auto ins = FITKProgramDriverFactory::getInstance();
// 注册构造函数T类型必须有默认的无参构造函数
ins->_createFuns[type][driverName] = ([&] { return new T; });
}
};
};
class FITKProgramDriverFactoryDeleator
{
public:
explicit FITKProgramDriverFactoryDeleator() = default;
virtual ~FITKProgramDriverFactoryDeleator();
};
}
/**
* @brief (int,)
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-10
*/
#ifndef Register2FITKProgramDriverFactory
#define Register2FITKProgramDriverFactory( Type,DriverName,T, ...) \
static AppFrame::FITKProgramDriverFactory::FITKDriverRegHelper< T > \
_FITKDriverRegHelper_##T##_##DriverName##__VA_ARGS__(Type, #DriverName);
#endif
#ifndef FITKPROGRAMDRIVERFACTORY
#define FITKPROGRAMDRIVERFACTORY ( AppFrame::FITKProgramDriverFactory::getInstance() )
#endif
#endif