forked from TranslucentTB/TranslucentTB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropertyChangedBase.hpp
More file actions
43 lines (38 loc) · 1.04 KB
/
Copy pathPropertyChangedBase.hpp
File metadata and controls
43 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <type_traits>
#include "winrt.hpp"
#include <winrt/Windows.UI.Xaml.Data.h>
#include "event.h"
#include "util/string_macros.hpp"
#define PROPERTY_CHANGED_FIELD(NAME) m_ ## NAME ## Property_
#define DECL_PROPERTY_CHANGED_FUNCS(TYPE, NAME, FIELD) \
TYPE NAME() const noexcept(std::is_nothrow_copy_constructible_v<TYPE>) \
{ \
return FIELD; \
}\
\
void NAME(const TYPE &value) \
{ \
compare_assign(FIELD, value, UTIL_STRINGIFY(NAME)); \
}
#define DECL_PROPERTY_CHANGED_PROP(TYPE, NAME) \
private: \
TYPE PROPERTY_CHANGED_FIELD(NAME); \
\
public: \
DECL_PROPERTY_CHANGED_FUNCS(TYPE, NAME, PROPERTY_CHANGED_FIELD(NAME))
template<typename T>
class PropertyChangedBase {
public:
DECL_EVENT(wux::Data::PropertyChangedEventHandler, PropertyChanged, m_propertyChanged);
protected:
template<typename U>
void compare_assign(U &value, const U &new_value, std::wstring_view name)
{
if (value != new_value)
{
value = new_value;
m_propertyChanged(*static_cast<T *>(this), wux::Data::PropertyChangedEventArgs(name));
}
}
};