EntityMapSerialization.hpp
1 #pragma once
2 #include <score/application/ApplicationComponents.hpp>
3 #include <score/model/EntityList.hpp>
4 #include <score/model/EntityMap.hpp>
5 #include <score/plugins/SerializableHelpers.hpp>
7 #include <score/serialization/JSONVisitor.hpp>
8 
10 {
11 
12  template <typename T>
13  static void readFrom(DataStream::Serializer& s, const T& obj)
14  {
15  s.m_stream << (int32_t)obj.size();
16  for(const auto& child : obj)
17  s.readFrom(child);
18  }
19 
20  template <typename List, typename T>
21  static void writeTo(
22  DataStream::Deserializer& s, T& obj, const score::DocumentContext& ctx,
23  QObject* parent)
24  {
25  int32_t sz;
26  s.m_stream >> sz;
27  auto& pl = s.components.template interfaces<List>();
28  for(; sz-- > 0;)
29  {
30  auto proc = deserialize_interface(pl, s, ctx, parent);
31  if(proc)
32  obj.add(proc);
33  else
34  SCORE_TODO;
35  }
36  }
37 
38  template <typename T>
39  static void readFrom(JSONObject::Serializer& s, const T& vec)
40  {
41  s.stream.StartArray();
42  for(const auto& elt : vec)
43  s.readFrom(elt);
44  s.stream.EndArray();
45  }
46  template <typename List, typename T>
47  static void writeTo(
48  JSONObject::Deserializer&& s, T& obj, const score::DocumentContext& ctx,
49  QObject* parent)
50  {
51  auto& pl = s.components.interfaces<List>();
52 
53  const auto& array = s.base.GetArray();
54  for(const auto& json_vref : array)
55  {
56  JSONObject::Deserializer deserializer{json_vref};
57  auto proc = deserialize_interface(pl, deserializer, ctx, parent);
58  if(proc)
59  obj.add(proc);
60  else
61  SCORE_TODO;
62  }
63  }
64 };
65 
66 template <typename T, bool O>
67 struct TSerializer<DataStream, score::EntityMap<T, O>> : EntityMapSerializer
68 {
69 };
70 
71 template <typename T, bool O>
72 struct TSerializer<JSONObject, score::EntityMap<T, O>> : EntityMapSerializer
73 {
74 };
75 
76 template <typename T>
78 {
79 };
80 
81 template <typename T>
83 {
84 };
Definition: VisitorInterface.hpp:53
Definition: DataStreamVisitor.hpp:27
Definition: DataStreamVisitor.hpp:202
Definition: VisitorInterface.hpp:61
Definition: JSONVisitor.hpp:52
Definition: JSONVisitor.hpp:423
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: EntityMapSerialization.hpp:10
Definition: VisitorInterface.hpp:13
Definition: DocumentContext.hpp:18