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/FITKAbstractObjectContainer...

143 lines
4.2 KiB
C++

#ifndef __FITKABSTRACT_OBJECT_CONTAINER_H__
#define __FITKABSTRACT_OBJECT_CONTAINER_H__
#include "FITKCoreAPI.h"
#include "FITKAbstractObject.hpp"
namespace Core
{
class FITKAbstractObjectPrivate;
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
class FITKCoreAPI FITKAbstractObjectContainerPrivate
{
friend FITKAbstractObjectPrivate;
public:
/**
* @brief Construct a new FITKAbstractObjectContainerPrivate object
* @param[i] absObj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
FITKAbstractObjectContainerPrivate(FITKAbstractObjectPrivate* absObj);
FITKAbstractObjectContainerPrivate();
virtual ~FITKAbstractObjectContainerPrivate() = 0;
/**
* @brief
* @return FITKAbstractObjectPrivate*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
FITKAbstractObjectPrivate* getObject();
void setObj(FITKAbstractObjectPrivate* obj);
private:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
virtual void ObjectDestoried();
private:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
FITKAbstractObjectPrivate* _object{};
};
template <typename T >
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
class FITKAbstractObjectContainer : protected FITKAbstractObjectContainerPrivate
{
public:
/**
* @brief Construct a new FITKAbstractObjectContainer object
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
explicit FITKAbstractObjectContainer(FITKAbstractObject* obj)
:FITKAbstractObjectContainerPrivate(obj) {}
explicit FITKAbstractObjectContainer() = default;
/**
* @brief Destroy the FITKAbstractObjectContainer object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
virtual ~FITKAbstractObjectContainer() = default;
FITKAbstractObjectContainer(const FITKAbstractObjectContainer&) = delete;
/**
* @brief
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
T* getObjectPtr() { return dynamic_cast<T*>(this->getObject()); }
/**
* @brief *
* @return T&
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
T& operator *() { return *(this->getObjectPtr()); }
/**
* @brief ->
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
T* operator->() { return this->getObjectPtr(); }
/**
* @brief
* @return bool
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
operator bool() { return this->getObjectPtr() != nullptr; }
/**
* @brief
* @return bool
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
void operator = (FITKAbstractObject* obj) { this->setObj(obj); }
/**
* @brief
* @return bool
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
bool operator == (FITKAbstractObject* obj) { return this->getObjectPtr() == obj; }
/**
* @brief
* @return bool
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-10
*/
bool operator != (FITKAbstractObject* obj) { return this->getObjectPtr() != obj; }
};
}
#endif