|
3 | 3 | #define mirai_cpp_defs_qq_types_hpp_H_ |
4 | 4 |
|
5 | 5 | #include <exception> |
| 6 | +#include <iostream> |
6 | 7 | #include "serializable.hpp" |
7 | 8 | #include "mirai/exported.h" |
8 | 9 |
|
9 | 10 | namespace Cyan |
10 | 11 | { |
11 | | - // QQ 号码类型 |
12 | | - class QQ_t |
| 12 | + // QQ_t 和 GID_t 的基类型 |
| 13 | + class UID_t |
13 | 14 | { |
14 | 15 | public: |
15 | | - QQ_t() :QQ(-1) {} |
16 | | - explicit QQ_t(int64_t qq) :QQ(qq) {} |
17 | | - operator int64_t() const { return QQ; } |
18 | | - int64_t ToInt64() const { return QQ; } |
19 | | - private: |
20 | | - int64_t QQ; |
| 16 | + int64_t ToInt64() const |
| 17 | + { |
| 18 | + return data_; |
| 19 | + } |
| 20 | + explicit operator int64_t() const |
| 21 | + { |
| 22 | + return data_; |
| 23 | + } |
| 24 | + bool operator==(const UID_t& a) const |
| 25 | + { |
| 26 | + return this->data_ == a.data_; |
| 27 | + } |
| 28 | + bool operator!=(const UID_t& a) const |
| 29 | + { |
| 30 | + return !operator==(a); |
| 31 | + } |
| 32 | + virtual ~UID_t() = default; |
| 33 | + protected: |
| 34 | + explicit UID_t(int64_t id) : data_(id) {} |
| 35 | + virtual void __avoiding_object_slicing() const = 0; |
| 36 | + int64_t data_; |
21 | 37 | }; |
22 | | - |
23 | | - inline QQ_t operator "" _qq(unsigned long long int v) |
| 38 | + |
| 39 | + // 储存 QQ 号码的类型 |
| 40 | + class QQ_t : public UID_t |
24 | 41 | { |
25 | | - return QQ_t(int64_t(v)); |
26 | | - } |
| 42 | + public: |
| 43 | + QQ_t() : UID_t(-1) {} |
| 44 | + explicit QQ_t(int64_t id) : UID_t(id) {} |
| 45 | + private: |
| 46 | + virtual void __avoiding_object_slicing() const override {} |
| 47 | + }; |
27 | 48 |
|
28 | | - // 群号码类型 |
29 | | - class GID_t |
| 49 | + // 储存群号码的类型 |
| 50 | + class GID_t : public UID_t |
30 | 51 | { |
31 | 52 | public: |
32 | | - GID_t() :GID(-1) {} |
33 | | - explicit GID_t(int64_t gid) :GID(gid) {} |
34 | | - operator int64_t() const { return GID; } |
35 | | - int64_t ToInt64() const { return GID; } |
| 53 | + GID_t() : UID_t(-1) {} |
| 54 | + explicit GID_t(int64_t id) : UID_t(id) {} |
36 | 55 | private: |
37 | | - int64_t GID; |
| 56 | + virtual void __avoiding_object_slicing() const override {} |
38 | 57 | }; |
39 | 58 |
|
40 | | - inline GID_t operator "" _gid(unsigned long long int v) |
| 59 | + inline GID_t operator ""_gid(unsigned long long int id) |
| 60 | + { |
| 61 | + return (GID_t)(id); |
| 62 | + } |
| 63 | + |
| 64 | + inline QQ_t operator ""_qq(unsigned long long int id) |
| 65 | + { |
| 66 | + return (QQ_t)(id); |
| 67 | + } |
| 68 | + |
| 69 | + inline std::ostream& operator<<(std::ostream& o, const UID_t& uid) |
41 | 70 | { |
42 | | - return GID_t(int64_t(v)); |
| 71 | + o << (int64_t)(uid); |
| 72 | + return o; |
43 | 73 | } |
44 | 74 |
|
45 | 75 | // 消息 ID |
|
0 commit comments