diff options
author | crupest <crupest@outlook.com> | 2018-09-29 17:35:09 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-29 17:35:09 +0800 |
commit | 20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3 (patch) | |
tree | 40285fea213ab85fba79a9a13132c8497e36338e /src/base.h | |
parent | 398b8f3ba535bb43c4b8593e3027c14894a7a211 (diff) | |
download | cru-20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3.tar.gz cru-20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3.tar.bz2 cru-20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3.zip |
Add PropertyChangedNotifyObject and BorderProperty.
Diffstat (limited to 'src/base.h')
-rw-r--r-- | src/base.h | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -20,6 +20,7 @@ #include <memory> #include <string_view> #include <chrono> +#include <list> namespace cru { @@ -60,6 +61,12 @@ namespace cru return std::make_shared<typename Type::element_type>(std::forward<Args>(args)...); } + template<typename Type> + Type CreateFunctionPtr(Function<Type>&& function) + { + return std::make_shared<FunctionPtr<Type>>(std::move(function)); + } + inline ActionPtr CreateActionPtr(Action&& action) { return std::make_shared<Action>(std::move(action)); @@ -104,4 +111,26 @@ namespace cru using CancelablePtr = std::shared_ptr<ICancelable>; MultiByteString ToUtf8String(const StringView& string); + + + class PropertyChangedNotifyObject : public Object + { + public: + PropertyChangedNotifyObject() = default; + PropertyChangedNotifyObject(const PropertyChangedNotifyObject& other) = delete; + PropertyChangedNotifyObject(PropertyChangedNotifyObject&& other) = delete; + PropertyChangedNotifyObject& operator = (const PropertyChangedNotifyObject& other) = delete; + PropertyChangedNotifyObject& operator = (PropertyChangedNotifyObject&& other) = delete; + ~PropertyChangedNotifyObject() override = default; + + void AddPropertyChangedListener(FunctionPtr<void(String)> listener); + + void RemovePropertyChangedListener(const FunctionPtr<void(String)>& listener); + + protected: + void RaisePropertyChangedEvent(String property_name); + + private: + std::list<FunctionPtr<void(String)>> listeners_; + }; } |