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/FITKAdaptor/FITKViewAdaptorFactory.h

167 lines
4.7 KiB
C

/**
*
* @file FITKViewAdaptorFactory.h
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*
*/
#ifndef __FITK_VIEW_FACTORY_H___
#define __FITK_VIEW_FACTORY_H___
#include "FITK_Kernel/FITKCore/FITKAbstractObject.hpp"
#include "FITK_Kernel/FITKCore/FITKCoreMacros.h"
#include "FITKAdaptorAPI.h"
#include <QMutex>
#include <QHash>
#include <functional>
namespace Core
{
class FITKAbstractObject;
}
namespace Adaptor
{
class FITKAbstractViewAdaptor;
/**
* @brief -
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
#ifndef VIEWTypeFuns
#define VIEWTypeFuns QHash<QString,std::function<FITKAbstractViewAdaptor*()> >
#endif
class FITKViewAdaptorFactoryDeleator;
/**
* @brief
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-03-25
*/
class FITKAdaptorAPI FITKViewAdaptorFactory : public Core::FITKAbstractObject
{
friend FITKViewAdaptorFactoryDeleator;
DeclSingleton(FITKViewAdaptorFactory);
public:
/**
* @brief
* @param[i] fileType
* @param[i] className
* @return FITKAbstractViewAdaptor*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
FITKAbstractViewAdaptor* create(const QString& graphObjType, const QString & className );
/**
* @brief
* @param[i] fileType
* @param[i] obj
* @return FITKAbstractViewAdaptor*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
FITKAbstractViewAdaptor* create(const QString& graphObjType, Core::FITKAbstractObject* obj);
template<class T>
/**
* @brief
* @param[i] graphObjType
* @param[i] className
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
T* createT(const QString& graphObjType, const QString & className)
{
return dynamic_cast<T*>(create(graphObjType, className));
}
template<class T>
/**
* @brief
* @param[i] fileType
* @param[i] obj
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
T* createT(const QString& graphObjType, Core::FITKAbstractObject* obj)
{
return dynamic_cast<T*>(create(graphObjType, obj));
}
private:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
void initialize();
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-17
*/
void finalize();
private:
/**
* @brief Adaptor
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
QHash<QString, VIEWTypeFuns> _createFuns{};
public:
template < typename T >
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
class FITKViewAdaFacRegHelper
{
public:
FITKViewAdaFacRegHelper(QString file, QString className)
{
auto ins = FITKViewAdaptorFactory::getInstance();
// 注册构造函数T类型必须有默认的无参构造函数
ins->_createFuns[file][className] = ([&] { return new T; });
}
};
};
class FITKViewAdaptorFactoryDeleator
{
public:
explicit FITKViewAdaptorFactoryDeleator() = default;
virtual ~FITKViewAdaptorFactoryDeleator();
};
} // namespace Adaptor
/**
* @brief Adaptor
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-03
*/
#ifndef Register2FITKViewAdaptorFactory
#define Register2FITKViewAdaptorFactory( File,DataClass, T, ...) \
static Adaptor::FITKViewAdaptorFactory::FITKViewAdaFacRegHelper< T > \
_FITKDataViewRegHelper_##T##_##File##_##__VA_ARGS__( #File,#DataClass );
#endif
#ifndef FITKVIEWADAPTORFACTORY
#define FITKVIEWADAPTORFACTORY ( Adaptor::FITKViewAdaptorFactory::getInstance() )
#endif
#endif