diff options
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_; + }; } |