/** * Copyright (C) 2021 Saturneric * * This file is part of GpgFrontend. * * GpgFrontend is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GpgFrontend is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GpgFrontend. If not, see . * * The initial version of the source code is inherited from * the gpg4usb project, which is under GPL-3.0-or-later. * * All the source code of GpgFrontend was modified and released by * Saturneric starting on May 12, 2021. * * SPDX-License-Identifier: GPL-3.0-or-later * */ #pragma once #include #include "core/GpgFrontendCoreExport.h" namespace GpgFrontend::Thread { class DataObject; using DataObjectPtr = std::shared_ptr; ///< class GPGFRONTEND_CORE_EXPORT DataObject { public: DataObject(); DataObject(std::initializer_list); ~DataObject(); DataObject(GpgFrontend::Thread::DataObject&&) noexcept; std::any operator[](size_t index) const; void AppendObject(std::any); std::any GetParameter(size_t index) const; size_t GetObjectSize() const; void Swap(DataObject& other) noexcept; void Swap(DataObject&& other) noexcept; template bool Check() { if (sizeof...(Args) != GetObjectSize()) return false; std::vector type_list = {&typeid(Args)...}; for (size_t i = 0; i < type_list.size(); ++i) { if (type_list[i] != &((*this)[i]).type()) return false; } return true; } private: class Impl; std::unique_ptr p_; }; template std::shared_ptr TransferParams(Args&&... args) { return std::make_shared(DataObject{std::forward(args)...}); } template T ExtractParams(const std::shared_ptr& d_o, int index) { if (!d_o) { throw std::invalid_argument("nullptr provided for DataObjectPtr"); } return std::any_cast(d_o->GetParameter(index)); } void swap(DataObject& a, DataObject& b) noexcept; } // namespace GpgFrontend::Thread