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.

170 lines
4.7 KiB
C

/**
*
* @file FITKDataRepo.h
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*
*/
#ifndef __FITKDATAREPO_H__
#define __FITKDATAREPO_H__
#include "FITKAbstractDataManager.hpp"
#include "FITKCoreMacros.h"
#include "FITKAbstractDataObject.h"
#include <QList>
namespace Core
{
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
class FITKDataRepoPrivate : public FITKAbstractDataManager<FITKAbstractDataObject>
{
public:
explicit FITKDataRepoPrivate() = default;
virtual ~FITKDataRepoPrivate() = default;
/**
* @brief
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-29
*/
virtual void appendDataObj(FITKAbstractDataObject* item) override;
/**
* @brief
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-29
*/
void remveFromListOnly(FITKAbstractDataObject* obj);
};
class FITKDataRepoDeleator;
/**
* @brief FITKAbstractDataObject访
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
class FITKCoreAPI FITKDataRepo
{
DeclSingleton(FITKDataRepo);
friend FITKDataRepoDeleator;
friend FITKAbstractDataObject;
/**
* @brief
* @return int
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
int getDataCount();
/**
* @brief ID
* @param[i] id
* @return FITKAbstractDataObject*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
FITKAbstractDataObject* getDataByID(const int id);
template <class T >
/**
* @brief IDT
* @param[i] id id
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
T* getTDataByID(const int id)
{
QMutexLocker locker(&m_mutex);
auto v = _repoPrivate.getDataByID(id);
return dynamic_cast<T*>(v);
}
template<class T>
/**
* @brief T
* @return QList<T*>
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
QList<T*> getData()
{
QMutexLocker locker(&m_mutex);
QList<T*> d;
const int n = _repoPrivate.getDataCount();
for (int i =0;i<n; ++i)
{
auto v = _repoPrivate.getDataByIndex(i);
auto tv = dynamic_cast<T*>(v);
if (tv) d.append(tv);
}
return d;
}
/**
* @brief
* @param[i] save ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-18
*/
void resetRepo(QList<int> save = { -1 });
private:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
void initialize();
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-17
*/
void finalize();
/**
* @brief FITKAbstractDataObject
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
void addDataObj(FITKAbstractDataObject* obj);
/**
* @brief FITKAbstractDataObject
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
void removeDataObj(FITKAbstractDataObject* obj);
private:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-27
*/
FITKDataRepoPrivate _repoPrivate{};
};
class FITKDataRepoDeleator
{
public:
explicit FITKDataRepoDeleator() = default;
virtual ~FITKDataRepoDeleator();
};
}
#ifndef FITKDATAREPO
#define FITKDATAREPO (Core::FITKDataRepo::getInstance())
#endif
#endif