MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_event_handle.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_EVENT_HANDLE_H_1608697773
12#define INCGUARD_MGL_EVENT_HANDLE_H_1608697773
13
15
16namespace MGL::Event
17{
18
20class Handle
21{
22public:
23 Handle() noexcept;
24 Handle(NotifyType type, CallbackFunction callback, void *callbackArg) noexcept;
25 ~Handle() noexcept;
26
27 void Set(NotifyType type, UniqueID id) noexcept;
28
29 /* ------------------------------------------------------------------------- */
34 /* ------------------------------------------------------------------------- */
35 [[nodiscard]] constexpr NotifyType GetType() const noexcept
36 {
37 return _type;
38 }
39
40 /* ------------------------------------------------------------------------- */
45 /* ------------------------------------------------------------------------- */
46 [[nodiscard]] constexpr UniqueID GetUniqueID() const noexcept
47 {
48 return _id;
49 }
50
51 /* ------------------------------------------------------------------------- */
57 /* ------------------------------------------------------------------------- */
58 [[nodiscard]] constexpr bool IsValid() const noexcept
59 {
60 return ((_type < NotifyType::Reserve_Start) && (_id != 0));
61 }
62
63 void Unregister() noexcept;
64
65 // コピー禁止
66 Handle(const Handle &) = delete;
67 Handle &operator=(const Handle &) = delete;
68
69 /* ------------------------------------------------------------------------- */
74 /* ------------------------------------------------------------------------- */
75 constexpr Handle(Handle &&other) noexcept
76 : _type(other._type)
77 , _id(other._id)
78 {
79 other._type = NotifyType::Reserve_Invalid;
80 other._id = 0;
81 }
82
83 /* ------------------------------------------------------------------------- */
88 /* ------------------------------------------------------------------------- */
89 constexpr Handle &operator=(Handle &&other) noexcept
90 {
91 if (this != &other)
92 {
93 Unregister();
94
95 _type = other._type;
96 _id = other._id;
97
98 other._type = NotifyType::Reserve_Invalid;
99 other._id = 0;
100 }
101
102 return *this;
103 }
104
105private:
106 NotifyType _type;
107 UniqueID _id;
108};
109
110} // namespace MGL::Event
111#endif // INCGUARD_MGL_EVENT_HANDLE_H_1608697773
112
113// vim: et ts=4 sw=4 sts=4
イベントハンドルクラス
Definition mgl_event_handle.h:21
void Set(NotifyType type, UniqueID id) noexcept
パラメータの設定
Definition mgl_event_handle.cc:62
constexpr bool IsValid() const noexcept
ハンドルの有効状態を取得
Definition mgl_event_handle.h:58
constexpr NotifyType GetType() const noexcept
通知タイプの取得
Definition mgl_event_handle.h:35
Handle() noexcept
コンストラクタ
Definition mgl_event_handle.cc:21
constexpr UniqueID GetUniqueID() const noexcept
ユニークIDを取得
Definition mgl_event_handle.h:46
~Handle() noexcept
デストラクタ
Definition mgl_event_handle.cc:49
void Unregister() noexcept
登録解除
Definition mgl_event_handle.cc:74
constexpr Handle & operator=(Handle &&other) noexcept
ムーブ代入演算
Definition mgl_event_handle.h:89
MGL イベント 型定義
NotifyType
通知タイプ
Definition mgl_event_types.h:21
void(*)(void *callbackArg, void *notifyArg) CallbackFunction
イベントコールバック関数
Definition mgl_event_types.h:68
uintptr_t UniqueID
イベント通知のユニークID型
Definition mgl_event_types.h:65