Chatterino
Container.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QString>
4 #include <pajlada/serialize.hpp>
5 
6 #include <unordered_map>
7 
8 namespace pajlada {
9 
10 template <typename ValueType, typename RJValue>
11 struct Serialize<std::unordered_map<QString, ValueType>, RJValue> {
12  static RJValue get(const std::unordered_map<QString, ValueType> &value,
13  typename RJValue::AllocatorType &a)
14  {
15  RJValue ret(rapidjson::kObjectType);
16 
17  for (auto it = value.begin(); it != value.end(); ++it)
18  {
19  detail::AddMember<ValueType, RJValue>(ret, it->first.toUtf8(),
20  it->second, a);
21  }
22 
23  return ret;
24  }
25 };
26 
27 template <typename ValueType, typename RJValue>
28 struct Deserialize<std::unordered_map<QString, ValueType>, RJValue> {
29  static std::unordered_map<QString, ValueType> get(const RJValue &value,
30  bool *error = nullptr)
31  {
32  std::unordered_map<QString, ValueType> ret;
33 
34  if (!value.IsObject())
35  {
36  PAJLADA_REPORT_ERROR(error)
37  return ret;
38  }
39 
40  for (typename RJValue::ConstMemberIterator it = value.MemberBegin();
41  it != value.MemberEnd(); ++it)
42  {
43  ret.emplace(it->name.GetString(),
44  Deserialize<ValueType, RJValue>::get(it->value, error));
45  }
46 
47  return ret;
48  }
49 };
50 
51 } // namespace pajlada
Definition: SeventvEventAPISubscription.hpp:67
Definition: Command.hpp:25