55 using is_visitor_tag = std::integral_constant<bool, true>;
66 static auto marshall(
const T& t)
73 bool empty()
const noexcept {
return this->buffer.GetLength() == 0; }
75 void read(
const QString&)
const noexcept =
delete;
76 void read(
const float&)
const noexcept =
delete;
77 void read(
const char&)
const noexcept =
delete;
78 void read(
const int&)
const noexcept =
delete;
79 void read(
const bool&)
const noexcept =
delete;
80 void read(
const std::string&)
const noexcept =
delete;
81 void read(
const unsigned int&)
const noexcept =
delete;
82 void read(
const unsigned char&)
const noexcept =
delete;
92 void readFrom(
const QString& obj)
noexcept { readFrom(obj.toUtf8()); }
93 void readFrom(
const QByteArray& t)
noexcept { stream.String(t.data(), t.size()); }
94 void readFrom(
const std::string& t)
noexcept { stream.String(t.data(), t.size()); }
95 void readFrom(int64_t t)
noexcept { stream.Int64(t); }
96 void readFrom(int32_t t)
noexcept { stream.Int(t); }
97 void readFrom(uint64_t t)
noexcept { stream.Uint64(t); }
98 void readFrom(uint32_t t)
noexcept { stream.Uint(t); }
99 void readFrom(
float t)
noexcept { stream.Double(t); }
100 void readFrom(
double t)
noexcept { stream.Double(t); }
101 void readFrom(
bool t)
noexcept { stream.Bool(t); }
102 void readFrom(
char t)
noexcept { stream.String(&t, 1); }
103 void readFrom(
const void*)
noexcept =
delete;
105 template <
typename T>
112 readFrom((
const typename T::score_base_type&)obj);
114 else if constexpr(std::is_enum_v<T>)
118 stream.Int(
static_cast<int32_t
>(obj));
124 || is_custom_serialized<T>::value)
130 && !is_custom_serialized<T>::value)
132 stream.StartObject();
135 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
145 stream.StartObject();
148 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
157 stream.StartObject();
158 readFromAbstract(obj, [](
JSONReader& sub,
const T& obj) {
166 && !is_custom_serialized<T>::value)
168 stream.StartObject();
169 readFromAbstract(obj, [](
JSONReader& sub,
const T& obj) {
172 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
182 stream.StartObject();
183 readFromAbstract(obj, [](
JSONReader& sub,
const T& obj) {
186 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
202 rapidjson::StringBuffer buffer;
203 JsonWriter stream{buffer};
208 assigner operator[](std::string_view str)
const noexcept;
209 template <std::
size_t N>
210 assigner operator[](
const char (&str)[N])
const noexcept;
211 assigner operator[](
const QString& str)
const noexcept;
217 QByteArray toByteArray()
const
219 SCORE_ASSERT(stream.IsComplete());
220 return QByteArray{buffer.GetString(), (int)buffer.GetLength()};
222 std::string toStdString()
const
224 SCORE_ASSERT(stream.IsComplete());
225 return std::string{buffer.GetString(), buffer.GetLength()};
227 QString toString()
const
229 SCORE_ASSERT(stream.IsComplete());
230 return QString::fromUtf8(buffer.GetString(), buffer.GetLength());
235 template <
typename T>
239 template <
typename T,
typename Fun>
240 void readFromAbstract(
const T& in, Fun f);
247 void operator=(int64_t t)
const noexcept { self.stream.Int64(t); }
248 void operator=(int32_t t)
const noexcept { self.stream.Int(t); }
249 void operator=(uint64_t t)
const noexcept { self.stream.Uint64(t); }
250 void operator=(uint32_t t)
const noexcept { self.stream.Uint(t); }
251 void operator=(
float t)
const noexcept { self.stream.Double(t); }
252 void operator=(
double t)
const noexcept { self.stream.Double(t); }
253 void operator=(
bool t)
const noexcept { self.stream.Bool(t); }
254 void operator=(
char t)
const noexcept { self.stream.String(&t, 1); }
255 void operator=(QPoint t)
const noexcept
257 self.stream.StartArray();
258 self.stream.Int(t.x());
259 self.stream.Int(t.y());
260 self.stream.EndArray();
262 void operator=(QPointF t)
const noexcept
264 self.stream.StartArray();
265 self.stream.Double(t.x());
266 self.stream.Double(t.y());
267 self.stream.EndArray();
269 void operator=(QSize t)
const noexcept
271 self.stream.StartArray();
272 self.stream.Int(t.width());
273 self.stream.Int(t.height());
274 self.stream.EndArray();
276 void operator=(QSizeF t)
const noexcept
278 self.stream.StartArray();
279 self.stream.Double(t.width());
280 self.stream.Double(t.height());
281 self.stream.EndArray();
283 void operator=(QRect t)
const noexcept
285 self.stream.StartArray();
286 self.stream.Int(t.x());
287 self.stream.Int(t.y());
288 self.stream.Int(t.width());
289 self.stream.Int(t.height());
290 self.stream.EndArray();
292 void operator=(QRectF t)
const noexcept
294 self.stream.StartArray();
295 self.stream.Double(t.x());
296 self.stream.Double(t.y());
297 self.stream.Double(t.width());
298 self.stream.Double(t.height());
299 self.stream.EndArray();
301 void operator=(
const QString& t)
const noexcept { *
this = t.toUtf8(); }
302 void operator=(
const QStringList& t)
const noexcept
304 self.stream.StartArray();
305 for(
const auto& str : t)
306 *
this = str.toUtf8();
307 self.stream.EndArray();
309 void operator=(
const QLatin1String& t)
const noexcept
311 self.stream.String(t.data(), t.size());
313 void operator=(
const std::string& t)
const noexcept
315 self.stream.String(t.data(), t.length());
317 void operator=(
const std::string_view& t)
const noexcept
319 self.stream.String(t.data(), t.length());
321 void operator=(
const QByteArray& t)
const noexcept
323 self.stream.String(t.data(), t.length());
325 void operator=(
const QVariantMap& t)
const noexcept { SCORE_ABORT; }
327 template <
typename T>
328 void operator=(
const T& t)
const noexcept
330 if constexpr(std::is_enum_v<T>)
334 self.stream.Int(
static_cast<int32_t
>(t));
595 template <
typename T>
598 s.stream.StartArray();
599 for(
const auto& elt : vec)
604 template <
typename T>
607 const auto& array = s.base.GetArray();
610 vec.reserve(array.Size());
611 for(
const auto& elt : array)
613 typename T::value_type v;
616 vec.push_back(std::move(v));
620 template <
typename Arg, std::
size_t N>
623 s.stream.StartArray();
624 for(
const auto& elt : vec)
629 template <
typename Arg, std::
size_t N>
632 const auto& array = s.base.GetArray();
633 SCORE_ASSERT(N >= array.Size());
635 auto it = vec.begin();
636 for(
const auto& elt : array)
644 template <std::
size_t N>
647 s.stream.StartArray();
649 s.stream.Double(elt);
653 template <std::
size_t N>
656 const auto& array = s.base.GetArray();
657 SCORE_ASSERT(N >= array.Size());
659 auto it = vec.begin();
660 for(
const auto& elt : array)
662 *it = elt.GetFloat();
667 template <
typename T>
670 s.stream.StartArray();
671 for(
const auto& elt : vec)
676 template <
typename T>
681 const auto& array = s.base.GetArray();
682 for(
const auto& elt : array)
687 vec.push_back(std::move(v));
692 template <
typename T>
695 s.stream.StartArray();
696 for(
const auto& elt : vec)
701 template <
typename T>
704 const auto& array = s.base.GetArray();
706 vec.reserve(array.Size());
708 for(
const auto& elt : array)
713 vec.push_back(std::move(v));
717 template <
template <
typename... Args>
typename T,
typename... Args>
720 s.stream.StartArray();
721 for(
const auto& elt : vec)
722 s.stream.String(elt.data(), elt.size());
726 template <
template <
typename... Args>
typename T,
typename... Args>
729 const auto& array = s.base.GetArray();
731 vec.reserve(array.Size());
732 for(
const auto& elt : array)
734 vec.push_back(std::string{elt.GetString(), elt.GetStringLength()});
738 template <
template <
typename... Args>
typename T,
typename... Args>
741 s.stream.StartArray();
742 for(
const auto& elt : vec)
744 const QByteArray& b = elt.toUtf8();
745 s.stream.String(b.data(), b.size());
750 template <
template <
typename... Args>
typename T,
typename... Args>
753 const auto& array = s.base.GetArray();
755 vec.reserve(array.Size());
756 for(
const auto& elt : array)
758 vec.push_back(QString::fromUtf8(elt.GetString(), elt.GetStringLength()));
762 template <
template <
typename... Args>
typename T,
typename... Args>
765 s.stream.StartArray();
771 template <
template <
typename... Args>
typename T,
typename... Args>
774 const auto& array = s.base.GetArray();
776 vec.resize(array.Size());
777 auto it = vec.begin();
778 for(
const auto& elt : array)
785 template <
template <
typename... Args>
typename T,
typename... Args>
788 s.stream.StartArray();
790 s.stream.String(&elt, 1);
794 template <
template <
typename... Args>
typename T,
typename... Args>
797 const auto& array = s.base.GetArray();
799 vec.resize(array.Size());
800 auto it = vec.begin();
801 for(
const auto& elt : array)
803 *it = elt.GetString()[0];
808 template <
template <
typename... Args>
typename T,
typename... Args>
811 s.stream.StartArray();
817 template <
template <
typename... Args>
typename T,
typename... Args>
820 const auto& array = s.base.GetArray();
822 vec.resize(array.Size());
823 auto it = vec.begin();
824 for(
const auto& elt : array)
826 *it = elt.GetInt64();
831 template <
template <
typename... Args>
typename T,
typename... Args>
834 s.stream.StartArray();
836 s.stream.Double(elt);
840 template <
template <
typename... Args>
typename T,
typename... Args>
843 const auto& array = s.base.GetArray();
845 vec.resize(array.Size());
846 auto it = vec.begin();
847 for(
const auto& elt : array)
849 *it = elt.GetFloat();
854 template <
template <
typename... Args>
typename T,
typename... Args>
857 s.stream.StartArray();
859 s.stream.Double(elt);
863 template <
template <
typename... Args>
typename T,
typename... Args>
866 const auto& array = s.base.GetArray();
868 vec.resize(array.Size());
869 auto it = vec.begin();
870 for(
const auto& elt : array)
872 *it = elt.GetDouble();
880 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
884 s.stream.StartArray();
891 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
895 const auto& array = s.base.GetArray();
897 vec.resize(array.Size());
898 auto it = vec.begin();
899 for(
const auto& elt : array)
907 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
911 s.stream.StartArray();
913 s.stream.String(&elt, 1);
918 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
922 const auto& array = s.base.GetArray();
924 vec.resize(array.Size());
925 auto it = vec.begin();
926 for(
const auto& elt : array)
928 *it = elt.GetString()[0];
934 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
938 s.stream.StartArray();
945 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
949 const auto& array = s.base.GetArray();
951 vec.resize(array.Size());
952 auto it = vec.begin();
953 for(
const auto& elt : array)
955 *it = elt.GetInt64();
961 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
965 s.stream.StartArray();
967 s.stream.Double(elt);
972 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
976 const auto& array = s.base.GetArray();
978 vec.resize(array.Size());
979 auto it = vec.begin();
980 for(
const auto& elt : array)
982 *it = elt.GetFloat();
988 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
992 s.stream.StartArray();
994 s.stream.Double(elt);
999 template <
typename, std::size_t,
typename...>
typename T, std::size_t N,
1003 const auto& array = s.base.GetArray();
1005 vec.resize(array.Size());
1006 auto it = vec.begin();
1007 for(
const auto& elt : array)
1009 *it = elt.GetDouble();