From fd46d4667611c0db9cea3f06205727399b6fb5fd Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 29 Oct 2023 02:46:15 +0800 Subject: refactor: start to tidy up code using clang-tidy --- src/core/model/DataObject.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/core/model/DataObject.cpp (limited to 'src/core/model/DataObject.cpp') diff --git a/src/core/model/DataObject.cpp b/src/core/model/DataObject.cpp new file mode 100644 index 00000000..a1eca4af --- /dev/null +++ b/src/core/model/DataObject.cpp @@ -0,0 +1,83 @@ +/** + * 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 + * + */ + +#include "DataObject.h" + +#include + +namespace GpgFrontend { + +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(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); +} + +void DataObject::AppendObject(std::any obj) { return p_->AppendObject(obj); } + +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 \ No newline at end of file -- cgit v1.2.3 From 8f633b806baec5004d99f554c4af95e427b82258 Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 7 Nov 2023 17:25:13 +0800 Subject: style: tidy up core/model --- src/core/model/DataObject.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/core/model/DataObject.cpp') diff --git a/src/core/model/DataObject.cpp b/src/core/model/DataObject.cpp index a1eca4af..9b49d0d4 100644 --- a/src/core/model/DataObject.cpp +++ b/src/core/model/DataObject.cpp @@ -29,25 +29,26 @@ #include "DataObject.h" #include +#include namespace GpgFrontend { class DataObject::Impl { public: - Impl() {} + Impl() = default; Impl(std::initializer_list init_list) : params_(init_list) {} - void AppendObject(std::any obj) { params_.push_back(obj); } + void AppendObject(const std::any& obj) { params_.push_back(obj); } - std::any GetParameter(size_t index) { + auto GetParameter(size_t index) -> std::any { if (index >= params_.size()) { throw std::out_of_range("index out of range"); } return params_[index]; } - size_t GetObjectSize() { return params_.size(); } + auto GetObjectSize() -> size_t { return params_.size(); } private: std::vector params_; @@ -62,17 +63,17 @@ DataObject::~DataObject() = default; DataObject::DataObject(DataObject&&) noexcept = default; -std::any DataObject::operator[](size_t index) const { +auto DataObject::operator[](size_t index) const -> std::any { return p_->GetParameter(index); } -std::any DataObject::GetParameter(size_t index) const { +auto DataObject::GetParameter(size_t index) const -> std::any { return p_->GetParameter(index); } void DataObject::AppendObject(std::any obj) { return p_->AppendObject(obj); } -size_t DataObject::GetObjectSize() const { return p_->GetObjectSize(); } +auto DataObject::GetObjectSize() const -> size_t { return p_->GetObjectSize(); } void DataObject::Swap(DataObject& other) noexcept { std::swap(p_, other.p_); } -- cgit v1.2.3 From 37215a895a649345165027971690dfdcd9106a32 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 15 Dec 2023 21:53:03 -0800 Subject: fix: use secure memory management at impl class --- src/core/model/DataObject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/model/DataObject.cpp') diff --git a/src/core/model/DataObject.cpp b/src/core/model/DataObject.cpp index 9b49d0d4..6fc1f353 100644 --- a/src/core/model/DataObject.cpp +++ b/src/core/model/DataObject.cpp @@ -54,10 +54,10 @@ class DataObject::Impl { std::vector params_; }; -DataObject::DataObject() : p_(std::make_unique()) {} +DataObject::DataObject() : p_(SecureCreateUniqueObject()) {} DataObject::DataObject(std::initializer_list i) - : p_(std::make_unique(i)) {} + : p_(SecureCreateUniqueObject(i)) {} DataObject::~DataObject() = default; -- cgit v1.2.3 From 4994f4eaa1211d402b791660ad6221154a4c2405 Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 16 Jan 2024 11:49:50 +0800 Subject: fix: make task and threading system safer --- src/core/model/DataObject.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/core/model/DataObject.cpp') diff --git a/src/core/model/DataObject.cpp b/src/core/model/DataObject.cpp index 6fc1f353..d0e9d141 100644 --- a/src/core/model/DataObject.cpp +++ b/src/core/model/DataObject.cpp @@ -29,7 +29,6 @@ #include "DataObject.h" #include -#include namespace GpgFrontend { -- cgit v1.2.3