|
| 1 | +#pragma once |
| 2 | +#ifndef mirai_cpp_defs_messages_marketface_message_hpp_H_ |
| 3 | +#define mirai_cpp_defs_messages_marketface_message_hpp_H_ |
| 4 | +#include <utility> |
| 5 | +#include "mirai/defs/IMessage.hpp" |
| 6 | + |
| 7 | +namespace Cyan |
| 8 | +{ |
| 9 | + class MarketFaceMessage : public IMessage |
| 10 | + { |
| 11 | + public: |
| 12 | + MarketFaceMessage() : id_(0), name_() {} |
| 13 | + MarketFaceMessage(const int& id) : id_(id), name_() {} |
| 14 | + MarketFaceMessage(const string& name) : id_(0), name_(name) {} |
| 15 | + template<int N> |
| 16 | + MarketFaceMessage(const char(&name)[N]) : id_(0), name_(name,N) {} |
| 17 | + MarketFaceMessage(const MarketFaceMessage& m) :id_(m.id_), name_(m.name_) {} |
| 18 | + MarketFaceMessage(MarketFaceMessage&& m) noexcept |
| 19 | + { |
| 20 | + std::swap(this->id_,m.id_); |
| 21 | + std::swap(this->name_, m.name_); |
| 22 | + } |
| 23 | + virtual const string& GetType() const override |
| 24 | + { |
| 25 | + return type_; |
| 26 | + } |
| 27 | + virtual bool operator==(const IMessage& m) const override |
| 28 | + { |
| 29 | + if (auto m_ptr = dynamic_cast<const MarketFaceMessage*>(&m)) |
| 30 | + { |
| 31 | + return m_ptr->id_ == this->id_; |
| 32 | + } |
| 33 | + return false; |
| 34 | + } |
| 35 | + virtual bool operator!=(const IMessage& m) const override |
| 36 | + { |
| 37 | + return !(*this == m); |
| 38 | + } |
| 39 | + virtual bool Set(const json& json) override |
| 40 | + { |
| 41 | + if (json["type"].is_null() || json["type"].get<string>() != this->GetType()) |
| 42 | + throw std::runtime_error("给定的json不正确"); |
| 43 | + id_ = json["id"].get<int>(); |
| 44 | + name_ = json["name"].get<string>(); |
| 45 | + return true; |
| 46 | + } |
| 47 | + virtual json ToJson() const override |
| 48 | + { |
| 49 | + return |
| 50 | + { |
| 51 | + { "type", type_ }, |
| 52 | + { "id", id_ }, |
| 53 | + { "name",name_ } |
| 54 | + }; |
| 55 | + } |
| 56 | + virtual ~MarketFaceMessage() {} |
| 57 | + |
| 58 | + int FaceId() const { return id_; } |
| 59 | + void FaceId(int id) { this->id_ = id; } |
| 60 | + |
| 61 | + string Name() const { return name_; } |
| 62 | + void Name(const string& n) { this->name_ = n; } |
| 63 | + |
| 64 | + private: |
| 65 | + const string type_ = "MarketFace"; |
| 66 | + int id_; |
| 67 | + string name_; |
| 68 | + }; |
| 69 | + |
| 70 | +} |
| 71 | +#endif |
| 72 | + |
0 commit comments