MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_task_weak_node.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_TASK_WEAK_NODE_H_1622684892
12#define INCGUARD_MGL_TASK_WEAK_NODE_H_1622684892
13
15
16namespace MGL::Task
17{
20{
21public:
22 /* ------------------------------------------------------------------------- */
26 /* ------------------------------------------------------------------------- */
27 constexpr WeakNode() noexcept = default;
28
29 WeakNode(size_t listIndex) noexcept;
30 WeakNode(const Node *node) noexcept;
31
32 bool Set(size_t listIndex) noexcept;
33 bool Set(const Node *node) noexcept;
34 [[nodiscard]] Node *Get() const noexcept;
35
36 /* ------------------------------------------------------------------------- */
42 /* ------------------------------------------------------------------------- */
43 [[nodiscard]] bool IsValid() const noexcept
44 {
45 return Get() != nullptr;
46 }
47
48 /* ------------------------------------------------------------------------- */
54 /* ------------------------------------------------------------------------- */
55 explicit operator bool() const noexcept
56 {
57 return IsValid();
58 }
59
60 /* ------------------------------------------------------------------------- */
66 /* ------------------------------------------------------------------------- */
67 bool operator!() const noexcept
68 {
69 return !IsValid();
70 }
71
72 /* ------------------------------------------------------------------------- */
82 /* ------------------------------------------------------------------------- */
83 template <class T, Identifier identifier = Identifier(T::kTaskIdentifier)>
84 [[nodiscard]] T *Get() const noexcept
85 {
86 if (auto *node = Get(); node != nullptr)
87 {
88 if (node->GetIdentifier() == identifier)
89 {
90 return reinterpret_cast<T *>(node);
91 }
92 }
93
94 return nullptr;
95 }
96
97 /* ------------------------------------------------------------------------- */
106 /* ------------------------------------------------------------------------- */
107 template <typename EventIDType>
108 bool NotifyEvent(EventIDType event, void *argument) noexcept
109 {
110 if (auto *node = Get(); node != nullptr)
111 {
112 node->NotifyEvent(event, argument);
113 return true;
114 }
115
116 return false;
117 }
118
119 /* ------------------------------------------------------------------------- */
126 /* ------------------------------------------------------------------------- */
127 bool Kill(ResideLevel resideLevel = ResideLevel::NoResident) noexcept
128 {
129 if (auto *node = Get(); node != nullptr)
130 {
131 if (node->GetResideLevel() <= resideLevel)
132 {
133 node->Kill();
134 return true;
135 }
136 }
137
138 return false;
139 }
140
141private:
142 size_t _listIndex{0};
143 Identifier _identifier{0};
144 UniqueIdentifier _uniqueID{UniqueIdentifier::Invalid};
145};
146
147}; // namespace MGL::Task
148
149#endif // INCGUARD_MGL_TASK_WEAK_NODE_H_1622684892
150
151// vim: et ts=4 sw=4 sts=4
タスクノード
Definition mgl_task_node.h:20
弱参照タスクノード
Definition mgl_task_weak_node.h:20
T * Get() const noexcept
指定したタスクノードにキャストして取得
Definition mgl_task_weak_node.h:84
bool IsValid() const noexcept
参照先の有効状態を取得
Definition mgl_task_weak_node.h:43
bool operator!() const noexcept
有効状態を否定演算子で取得
Definition mgl_task_weak_node.h:67
bool Set(size_t listIndex) noexcept
ノードの設定
Definition mgl_task_weak_node.cc:51
bool Kill(ResideLevel resideLevel=ResideLevel::NoResident) noexcept
参照先タスクを削除
Definition mgl_task_weak_node.h:127
Node * Get() const noexcept
ノードの取得
Definition mgl_task_weak_node.cc:111
constexpr WeakNode() noexcept=default
コンストラクタ
bool NotifyEvent(EventIDType event, void *argument) noexcept
タスクへのイベント通知
Definition mgl_task_weak_node.h:108
ResideLevel
常駐レベル
Definition mgl_task_defs.h:109
MGL タスクノード