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.

358 lines
11 KiB
C++

/**
*
* @file FITKAbstractDataManager.hpp
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*
*/
#ifndef _FITKDATAMANAGERABSTRACT_H__
#define _FITKDATAMANAGERABSTRACT_H__
#include "FITKAbstractDataManagerHelper.h"
#include "FITKAbstractObject.hpp"
#include <QMutex>
#include <QMutexLocker>
namespace Core
{
class FITKAbstractDataObject;
class FITKAbstractDataManagerHelper;
template <class T>
/**
* @brief list 线
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
class FITKAbstractDataManager
{
public:
/**
* @brief Construct a new FITKAbstractDataManager object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
FITKAbstractDataManager()
{
_helper = new FITKAbstractDataManagerHelper(_dataList);
}
/**
* @brief Destroy the FITKAbstractDataManager object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual ~FITKAbstractDataManager()
{
this->clear();
if (_helper) delete _helper;
}
/**
* @brief
* @param[i] item
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void appendDataObj(FITKAbstractDataObject* item)
{
QMutexLocker locker(&_mutex);
if (!isT(item))
delete item;
else
_helper->appendData(item);
}
/**
* @brief
* @param[i] items
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void appendDataObj(const QList<FITKAbstractDataObject*> & items)
{
QMutexLocker locker(&_mutex);
_helper->appendData(items);
}
/**
* @brief
* @return int
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual int getDataCount() const
{
QMutexLocker locker(&_mutex);
return _dataList.size();
}
/**
* @brief
* @param[i] obj
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual bool isContains(FITKAbstractDataObject* obj)
{
QMutexLocker locker(&_mutex);
return (_helper && _helper->isContains(obj));
}
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void clear()
{
QMutexLocker locker(&_mutex);
_helper->clear();
}
/**
* @brief
* @param[i] index
* @param[i] item
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void insertDataObj(int index, FITKAbstractDataObject* item)
{
QMutexLocker locker(&_mutex);
if (!isT(item))
delete item;
else
_helper->insertDataObj(index, item);
}
/**
* @brief
* @param[i] index
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
T* getDataByIndex(const int index)
{
QMutexLocker locker(&_mutex);
return transfe2T(_helper->getDataByIndex(index));
}
/**
* @brief
* @param[i] index
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-25
*/
T* operator[](const int index)
{
QMutexLocker locker(&_mutex);
return transfe2T(_helper->getDataByIndex(index));
}
/**
* @brief ID
* @param[i] id ID
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual T* getDataByID(const int id)
{
QMutexLocker locker(&_mutex);
return transfe2T(_helper->getDataByID(id));
}
/**
* @brief -1
* @param[i] obj
* @return int
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual int getDataIndex(FITKAbstractDataObject* obj) const
{
QMutexLocker locker(&_mutex);
return _helper->getDataIndex(obj);
}
/**
* @brief FITKAbstractNDataObject
* @param[i] name
* @param[i] CompSens false
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
T* getDataByName(const QString& name, bool CompSens = false)
{
QMutexLocker locker(&_mutex);
return transfe2T(_helper->getDataByName(name,CompSens));
}
/**
* @brief
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void removeDataObj(FITKAbstractDataObject* obj)
{
QMutexLocker locker(&_mutex);
_helper->removeDataObj(obj);
}
/**
* @brief ,
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-23
*/
void removeDataObjWithoutRelease(FITKAbstractDataObject* obj)
{
QMutexLocker locker(&_mutex);
_helper->removeDataObjWithoutRelease(obj);
}
/**
* @brief index
* @param[i] index
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void removeDataByIndex(int index)
{
QMutexLocker locker(&_mutex);
_helper->removeDataByIndex(index);
}
/**
* @brief ID
* @param[i] id ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void removeDataByID(int id)
{
QMutexLocker locker(&_mutex);
_helper->removeDataByID(id);
}
/**
* @brief
* @param[i] name
* @param[i] CompSens false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual void removeDataByName(const QString &name, bool compSens = false)
{
QMutexLocker locker(&_mutex);
_helper->removeDataByName(name,compSens);
}
/**
* @brief ID
* @param[i] id ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
void setParentDataIDM(const int & id)
{
if (_helper)
_helper->setParentDataID(id);
}
/**
* @brief id
* @return int
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
int getMParentDataIDM() const
{
if (_helper)
return _helper->getParentDataID();
return -1;
}
/**
* @brief
* @param[i] name
* @return QString
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-11
*/
QString checkName(const QString& name)
{
if (_helper)
return _helper->checkName(name);
return name;
}
/**
* @brief ID
* @param dataIdID
* @return
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-10-22
*/
int getIndexByID(int dataId)
{
QMutexLocker locker(&_mutex);
return _helper->getIndexByID(dataId);
}
/**
* @brief ID
* @param dataIndex
* @return ID
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-10-22
*/
int getIDByIndex(int dataIndex)
{
QMutexLocker locker(&_mutex);
return _helper->getIDByIndex(dataIndex);
}
private:
/**
* @brief
* @param[i] obj
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
bool isT(FITKAbstractDataObject* obj)
{
auto p = dynamic_cast<T*>(obj);
return nullptr != p;
}
/**
* @brief T
* @param[i] data
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
T* transfe2T(FITKAbstractDataObject* data)
{
return dynamic_cast<T*>(data);
}
protected:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
FITKAbstractDataManagerHelper * _helper{};
/**
* @brief 线
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
mutable QMutex _mutex{};
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
QList<FITKAbstractDataObject*> _dataList{};
};
}
#endif