aboutsummaryrefslogtreecommitdiff
path: root/src/base.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-29 17:35:09 +0800
committercrupest <crupest@outlook.com>2018-09-29 17:35:09 +0800
commit20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3 (patch)
tree40285fea213ab85fba79a9a13132c8497e36338e /src/base.h
parent398b8f3ba535bb43c4b8593e3027c14894a7a211 (diff)
downloadcru-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.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/base.h b/src/base.h
index 7ef78014..ce7a781d 100644
--- a/src/base.h
+++ b/src/base.h
@@ -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_;
+ };
}