From 5175b3ae6687839afa2cdfe01f2fd70d714024ed Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 17 Oct 2023 04:19:26 +0800 Subject: refactor: use c++17 features and piml tech to rewrite DataObject and Task --- src/core/thread/DataObject.cpp | 57 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'src/core/thread/DataObject.cpp') diff --git a/src/core/thread/DataObject.cpp b/src/core/thread/DataObject.cpp index c99e0bfd..b21db7cb 100644 --- a/src/core/thread/DataObject.cpp +++ b/src/core/thread/DataObject.cpp @@ -26,4 +26,59 @@ * */ -#include "DataObject.h" \ No newline at end of file +#include "DataObject.h" + +#include +#include + +#include "function/DataObjectOperator.h" + +namespace GpgFrontend::Thread { + +class DataObject::Impl { + public: + Impl() {} + + Impl(std::initializer_list init_list) : params_(init_list) {} + + void AppendObject(std::any obj) { params_.push_back(obj); } + + std::any GetParameter(size_t index) { + if (index >= params_.size()) { + throw std::out_of_range("index out of range"); + } + return params_[index]; + } + + size_t GetObjectSize() { return params_.size(); } + + private: + std::vector params_; +}; + +DataObject::DataObject() : p_(std::make_unique()) {} + +DataObject::DataObject(std::initializer_list i) + : p_(std::make_unique(i)) {} + +DataObject::~DataObject() = default; + +DataObject::DataObject(GpgFrontend::Thread::DataObject&&) noexcept = default; + +std::any DataObject::operator[](size_t index) const { + return p_->GetParameter(index); +} + +std::any DataObject::GetParameter(size_t index) const { + return p_->GetParameter(index); +} + +size_t DataObject::GetObjectSize() const { return p_->GetObjectSize(); } + +void DataObject::Swap(DataObject& other) noexcept { std::swap(p_, other.p_); } + +void DataObject::Swap(DataObject&& other) noexcept { p_ = std::move(other.p_); } + +void swap(DataObject& a, DataObject& b) noexcept { a.Swap(b); } + +} // namespace GpgFrontend::Thread \ No newline at end of file -- cgit v1.2.3