From 6515948e3f5b97f90446536f72e99d71e96f9de7 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 9 Nov 2018 19:59:57 +0800 Subject: Add AnyMap. --- src/ui/control.hpp | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'src/ui/control.hpp') diff --git a/src/ui/control.hpp b/src/ui/control.hpp index 26be653a..0e078da2 100644 --- a/src/ui/control.hpp +++ b/src/ui/control.hpp @@ -3,16 +3,15 @@ #include "system_headers.hpp" #include #include -#include #include #include "base.hpp" -#include "format.hpp" #include "ui_base.hpp" #include "layout_base.hpp" #include "events/ui_event.hpp" #include "border_property.hpp" #include "cursor.hpp" +#include "any_map.h" namespace cru::ui { @@ -183,33 +182,9 @@ namespace cru::ui //*************** region: additional properties *************** - template - std::optional GetAdditionalProperty(const String& key) + AnyMap* GetAdditionalPropertyMap() { - try - { - const auto find_result = additional_properties_.find(key); - if (find_result != additional_properties_.cend()) - return std::any_cast(find_result->second); - else - return std::nullopt; - } - catch (const std::bad_any_cast&) - { - throw std::runtime_error(Format("Key \"{}\" is not of the type {}.", ToUtf8String(key), typeid(T).name())); - } - } - - template - void SetAdditionalProperty(const String& key, const T& value) - { - additional_properties_[key] = std::make_any(value); - } - - template - void SetAdditionalProperty(const String& key, T&& value) - { - additional_properties_[key] = std::make_any(std::move(value)); + return &additional_property_map_; } @@ -389,7 +364,7 @@ namespace cru::ui bool is_bordered_ = false; BorderProperty border_property_; - std::unordered_map additional_properties_{}; + AnyMap additional_property_map_{}; bool is_focus_on_pressed_ = true; -- cgit v1.2.3