cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
IEvent.hpp
浏览该文件的文档.
1// Copyright (C) 2022 Numendacil and contributors
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU Affero General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16#ifndef MIRAI_EVENT_INTERFACE_HPP_
17#define MIRAI_EVENT_INTERFACE_HPP_
18
19#include <memory>
20#include <string>
22
23namespace Mirai
24{
25
26class MiraiClient;
27
28/**
29 * @brief Common interface for all event types
30 *
31 */
32template <class Event>
33class IEvent
34{
35private:
36 friend class MiraiClient;
37
38 /**
39 * @brief 指向 `MiraiClient` 的指针
40 *
41 * 对应于接收该事件的 `MiraiClient` ,方便对事件作出响应
42 */
43 MiraiClient* client_ = nullptr;
44
45 /// Sets the `MiraiClient` pointer
46 void SetClient_(MiraiClient* client) { this->client_ = client; }
47
48 Event& top_() { return *static_cast<Event*>(this); }
49 const Event& top_() const { return *static_cast<const Event*>(this); }
50
51protected:
52 IEvent() = default;
53 ~IEvent() = default;
54
55public:
56 IEvent(const IEvent&) = default;
57 IEvent& operator=(const IEvent&) = default;
58 IEvent(IEvent&&) = default;
59 IEvent& operator=(IEvent&&) = default;
60
61 /// 获取事件类型
62 static constexpr EventTypes GetType() { return Event::TYPE_; }
63
64 /// 获取接收该事件的 `MiraiClient` 的引用
65 MiraiClient& GetMiraiClient() const { return *client_; }
66};
67
68} // namespace Mirai
69
70#endif
Common interface for all event types
Definition: IEvent.hpp:34
IEvent(IEvent &&)=default
IEvent()=default
~IEvent()=default
IEvent(const IEvent &)=default
static constexpr EventTypes GetType()
获取事件类型
Definition: IEvent.hpp:62
MiraiClient & GetMiraiClient() const
获取接收该事件的 MiraiClient 的引用
Definition: IEvent.hpp:65
IEvent & operator=(IEvent &&)=default
IEvent & operator=(const IEvent &)=default
提供与mirai-api-http网络交互的封装
Definition: Client.hpp:61
所有mirai相关的对象的命名空间