Chatterino
Command.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <QString>
6 #include <pajlada/serialize.hpp>
7 
8 namespace chatterino {
9 
10 struct Command {
11  QString name;
12  QString func;
14 
15  Command() = default;
16  explicit Command(const QString &text);
17  Command(const QString &name, const QString &func,
18  bool showInMsgContextMenu = false);
19 
20  QString toString() const;
21 };
22 
23 } // namespace chatterino
24 
25 namespace pajlada {
26 
27 template <>
28 struct Serialize<chatterino::Command> {
29  static rapidjson::Value get(const chatterino::Command &value,
30  rapidjson::Document::AllocatorType &a)
31  {
32  rapidjson::Value ret(rapidjson::kObjectType);
33 
34  chatterino::rj::set(ret, "name", value.name, a);
35  chatterino::rj::set(ret, "func", value.func, a);
36  chatterino::rj::set(ret, "showInMsgContextMenu",
37  value.showInMsgContextMenu, a);
38 
39  return ret;
40  }
41 };
42 
43 template <>
44 struct Deserialize<chatterino::Command> {
45  static chatterino::Command get(const rapidjson::Value &value,
46  bool *error = nullptr)
47  {
48  chatterino::Command command;
49 
50  if (!value.IsObject())
51  {
52  PAJLADA_REPORT_ERROR(error);
53  return command;
54  }
55 
56  if (!chatterino::rj::getSafe(value, "name", command.name))
57  {
58  PAJLADA_REPORT_ERROR(error);
59  return command;
60  }
61  if (!chatterino::rj::getSafe(value, "func", command.func))
62  {
63  PAJLADA_REPORT_ERROR(error);
64  return command;
65  }
66  if (!chatterino::rj::getSafe(value, "showInMsgContextMenu",
67  command.showInMsgContextMenu))
68  {
69  command.showInMsgContextMenu = false;
70 
71  PAJLADA_REPORT_ERROR(error);
72 
73  return command;
74  }
75 
76  return command;
77  }
78 };
79 
80 } // namespace pajlada
Definition: Command.hpp:10
bool showInMsgContextMenu
Definition: Command.hpp:13
Definition: Application.cpp:48
void set(rapidjson::Value &obj, const char *key, const Type &value, rapidjson::Document::AllocatorType &a)
Definition: RapidjsonHelpers.hpp:22
QString toString() const
Definition: Command.cpp:29
Definition: Command.hpp:25
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
Definition: RapidjsonHelpers.hpp:73
QString func
Definition: Command.hpp:12
QString name
Definition: Command.hpp:11