From 868dfc85c89c6444d96c6567b8b62f6aa7d2fe08 Mon Sep 17 00:00:00 2001 From: LazyPanda07 Date: Sat, 14 Aug 2021 06:58:44 +0500 Subject: [PATCH] Fixes --- .../StandardComposites/BaseWindow.cpp | 8 ++++---- .../StandardComposites/BaseWindow.h | 4 ++-- GUIFramework/src/GUIFramework.cpp | 2 +- GUIFramework/src/GUIFramework.h | 6 +++--- .../LoadableHolders/BaseLoadableHolder.cpp | 19 +++++++++++++++++++ .../LoadableHolders/BaseLoadableHolder.h | 4 ++-- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.cpp b/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.cpp index 8be53df01..a1a436e50 100644 --- a/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.cpp +++ b/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.cpp @@ -11,7 +11,7 @@ using namespace std; namespace gui_framework { - BaseWindow::drawedImages::drawedImages(unique_ptr&& images, utility::BaseLoadableHolder::imageType type) noexcept : + BaseWindow::drawedImages::drawedImages(smartPointerType&& images, utility::BaseLoadableHolder::imageType type) noexcept : images(move(images)), type(type) { @@ -50,16 +50,16 @@ namespace gui_framework void BaseWindow::initDrawing(const string& pictureBlockName, uint16_t imagesWidth, uint16_t imagesHeight, utility::BaseLoadableHolder::imageType type) { - unique_ptr images; + smartPointerType images; switch (type) { case utility::BaseLoadableHolder::imageType::bitmap: - images = make_unique(imagesWidth, imagesHeight); + images = utility::make_smart_pointer(imagesWidth, imagesHeight); break; case utility::BaseLoadableHolder::imageType::icon: - images = make_unique(imagesWidth, imagesHeight); + images = utility::make_smart_pointer(imagesWidth, imagesHeight); break; case utility::BaseLoadableHolder::imageType::cursor: diff --git a/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.h b/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.h index bc31ae116..db39f14c6 100644 --- a/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.h +++ b/GUIFramework/src/BaseComposites/StandardComposites/BaseWindow.h @@ -12,11 +12,11 @@ namespace gui_framework private: struct drawedImages { - std::unique_ptr images; + smartPointerType images; std::unordered_map> coordinates; utility::BaseLoadableHolder::imageType type; - drawedImages(std::unique_ptr&& images, utility::BaseLoadableHolder::imageType type) noexcept; + drawedImages(smartPointerType&& images, utility::BaseLoadableHolder::imageType type) noexcept; void addImage(BaseWindow* owner, int x, int y, const std::filesystem::path& pathToImage); diff --git a/GUIFramework/src/GUIFramework.cpp b/GUIFramework/src/GUIFramework.cpp index c10665068..6bfd08b6f 100644 --- a/GUIFramework/src/GUIFramework.cpp +++ b/GUIFramework/src/GUIFramework.cpp @@ -620,7 +620,7 @@ namespace gui_framework return result; } - const unordered_map>& GUIFramework::getCreators() const + const unordered_map>& GUIFramework::getCreators() const { return creators; } diff --git a/GUIFramework/src/GUIFramework.h b/GUIFramework/src/GUIFramework.h index 731bee883..fd450e6eb 100644 --- a/GUIFramework/src/GUIFramework.h +++ b/GUIFramework/src/GUIFramework.h @@ -44,7 +44,7 @@ namespace gui_framework INITCOMMONCONTROLSEX comm; std::unordered_map modules; std::unordered_map modulesPaths; - std::unordered_map> creators; + std::unordered_map> creators; #pragma region Ids std::unordered_multimap generatedIds; std::queue availableIds; @@ -173,7 +173,7 @@ namespace gui_framework /// @brief Get all current registered creators /// @return creators - const std::unordered_map>& getCreators() const; + const std::unordered_map>& getCreators() const; /// @brief Get settings from gui_framework.json /// @return jsonSettings @@ -211,6 +211,6 @@ namespace gui_framework template T, std::derived_from CreatorT, typename... Args> void GUIFramework::addCreator(Args&&... args) { - creators[typeid(T).hash_code()] = std::unique_ptr(new CreatorT(std::forward(args)...)); + creators[typeid(T).hash_code()] = smartPointerType(new CreatorT(std::forward(args)...)); } } diff --git a/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.cpp b/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.cpp index 1c9fca7f8..c1d100a4a 100644 --- a/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.cpp +++ b/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.cpp @@ -12,7 +12,15 @@ namespace gui_framework type(type), data(move(data)) { + + } + BaseLoadableHolder::imageData::imageData(const imageData& other) : + index(other.index), + type(other.type), + data(other.data) + { + const_cast(other).data.reset(); } BaseLoadableHolder::imageData::imageData(imageData&& other) noexcept : @@ -23,6 +31,17 @@ namespace gui_framework other.data.reset(); } + BaseLoadableHolder::imageData& BaseLoadableHolder::imageData::operator = (const imageData& other) + { + index = other.index; + type = other.type; + data = other.data; + + const_cast(other).data.reset(); + + return *this; + } + BaseLoadableHolder::imageData& BaseLoadableHolder::imageData::operator = (imageData&& other) noexcept { index = other.index; diff --git a/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.h b/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.h index a42d91183..a44b0361a 100644 --- a/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.h +++ b/GUIFramework/src/Utility/Holders/LoadableHolders/BaseLoadableHolder.h @@ -38,11 +38,11 @@ namespace gui_framework imageData(uint16_t index, imageType type, std::any&& data); - imageData(const imageData& other) = delete; + imageData(const imageData& other); imageData(imageData&& other) noexcept; - imageData& operator = (const imageData& other) = delete; + imageData& operator = (const imageData& other); imageData& operator = (imageData&& other) noexcept;