Loading...
Searching...
No Matches
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(
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(
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
66template <typename T, bool O>
68{
69};
70
71template <typename T, bool O>
73{
74};
75
76template <typename T>
78{
79};
80
81template <typename T>
83{
84};
Definition VisitorInterface.hpp:53
Definition DataStreamVisitor.hpp:27
void readFrom(const score::Entity< T > &obj)
Called by code that wants to serialize.
Definition DataStreamVisitor.hpp:53
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