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.
AppFlow/FITK_Kernel/FITKCore/FITKOperatorRepo.h

129 lines
3.5 KiB
C

/**
*
* @file FITKOperatorRepo.h
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*
*/
#ifndef __FITK_OPERATOR_REPO_H__
#define __FITK_OPERATOR_REPO_H__
#include "FITKCoreAPI.h"
#include "FITKCoreMacros.h"
#include "FITKAbstractObject.hpp"
#include <QMutex>
#include <QHash>
#include <functional>
#include <QString>
namespace Core
{
class FITKAbstractOperator;
class FITKOperatorRepoPrivate;
class FITKOperatorDeletor;
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
class FITKCoreAPI FITKOperatorRepo : public FITKAbstractObject
{
friend FITKOperatorDeletor;
//声明为单例
DeclSingleton(FITKOperatorRepo);
/**
* @brief
* @param[i] key Operator
* @return FITKAbstractOperator*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
FITKAbstractOperator* getOperator(const QString& key);
template <class T>
/**
* @brief T
* @param[i] key Operator
* @return FITKAbstractOperator*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
T* getOperatorT(const QString& key)
{
return dynamic_cast<T*> (this->getOperator(key));
}
private:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
void initialize();
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-17
*/
void finalize();
private:
/**
* @brief operator
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
QHash<QString, std::function<FITKAbstractOperator*()>> _createFuns{};
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
FITKOperatorRepoPrivate* _private{};
public:
template < typename T >
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
class FITKOperatorRepoRegHelper
{
public:
FITKOperatorRepoRegHelper(QString key)
{
auto ins = FITKOperatorRepo::getInstance();
// 注册构造函数T类型必须有默认的无参构造函数
ins->_createFuns.insert( key,[&] { return new T; });
}
};
};
}
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
#ifndef Register2FITKOPeratorRepo
#define Register2FITKOPeratorRepo(key,Class,...) \
static Core::FITKOperatorRepo::FITKOperatorRepoRegHelper< Class > \
_FITKDataIORegHelper_##key##_##Class##__VA_ARGS__(#key)
#endif
/**
* @brief 访
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
#ifndef FITKOPERREPO
#define FITKOPERREPO Core::FITKOperatorRepo::getInstance()
#endif // !FITKOPERREPO
#endif // !__FITK_OPERATOR_REPO_H__