2 #include <score/model/Identifier.hpp>
3 #include <score/plugins/UuidKey.hpp>
4 #include <score/serialization/CommonTypes.hpp>
5 #include <score/serialization/DataStreamFwd.hpp>
6 #include <score/serialization/DataStreamHelpers.hpp>
7 #include <score/serialization/VisitorInterface.hpp>
8 #include <score/serialization/VisitorTags.hpp>
9 #include <score/tools/std/HashMap.hpp>
10 #include <score/tools/std/Optional.hpp>
12 #include <ossia/detail/flat_set.hpp>
13 #include <ossia/detail/small_vector.hpp>
17 template <
typename model>
21 template <
typename model>
23 class ApplicationComponents;
30 using is_visitor_tag = std::integral_constant<bool, true>;
64 void readFrom(
const QByteArray& obj) { m_stream_impl << obj; }
73 readFrom((
const typename T::score_base_type&)obj);
78 (is_template<T>::value && !abstract_base<T> && !identified_object<T>)
79 || is_custom_serialized<T>::value)
84 identified_object<T> && !identified_entity<T> && !abstract_base<T>
85 && !is_custom_serialized<T>::value)
89 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
95 identified_entity<T> && !abstract_base<T> && !is_custom_serialized<T>::value)
99 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
105 !identified_object<T> && abstract_base<T> && !is_custom_serialized<T>::value)
113 identified_object<T> && !identified_entity<T> && abstract_base<T>
114 && !is_custom_serialized<T>::value)
119 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
126 identified_entity<T> && abstract_base<T> && !is_custom_serialized<T>::value)
131 if constexpr(is_custom_serialized<T>::value || is_template<T>::value)
137 else if constexpr(std::is_enum<T>::value)
140 m_stream << (int32_t)obj;
158 auto& stream() {
return m_stream; }
162 template <
typename T>
166 template <
typename T,
typename Fun>
167 void readFromAbstract(
const T& obj, Fun f)
176 SCORE_DEBUG_INSERT_DELIMITER2(sub);
177 sub.readFrom(obj.concreteKey().impl());
178 SCORE_DEBUG_INSERT_DELIMITER2(sub);
185 obj.serialize_impl(sub.toVariant());
188 SCORE_DEBUG_INSERT_DELIMITER2(sub);
191 m_stream << std::move(b);
194 QDataStream m_stream_impl;
205 using is_visitor_tag = std::integral_constant<bool, true>;
206 using is_deserializer_tag = std::integral_constant<bool, true>;
208 VisitorVariant toVariant() {
return {*
this, DataStream::type()}; }
217 template <
typename T>
218 static auto unmarshall(
const QByteArray& arr)
228 template <
typename T>
231 void writeTo(QByteArray& obj) { m_stream_impl >> obj; }
233 template <
typename T>
237 (is_template<T>::value && !abstract_base<T> && !identified_object<T>)
238 || is_custom_serialized<T>::value)
242 else if constexpr(std::is_enum<T>::value)
247 obj =
static_cast<T
>(e);
261 void checkDelimiter();
263 auto& stream() {
return m_stream; }
269 QDataStream m_stream_impl;
272 template <
typename T>
273 requires(!std::is_enum_v<T>)
277 reader.readFrom(obj);
281 template <
typename T>
282 requires(!std::is_enum_v<T>)
290 template <
typename U>
295 s.stream() << obj.val();
296 SCORE_DEBUG_INSERT_DELIMITER2(s);
304 SCORE_DEBUG_CHECK_DELIMITER2(s);
308 template <
typename T>
311 template <
typename U>
314 SCORE_DEBUG_INSERT_DELIMITER2(s);
315 s.stream() << obj.objectName();
316 SCORE_DEBUG_INSERT_DELIMITER2(s);
317 s.readFrom(obj.id());
318 SCORE_DEBUG_INSERT_DELIMITER2(s);
321 template <
typename U>
326 SCORE_DEBUG_CHECK_DELIMITER2(s);
328 SCORE_DEBUG_CHECK_DELIMITER2(s);
329 obj.setObjectName(name);
331 obj.setId(std::move(
id));
332 SCORE_DEBUG_CHECK_DELIMITER2(s);
336 template <
typename T>
341 s.stream() <<
static_cast<bool>(obj);
347 SCORE_DEBUG_INSERT_DELIMITER2(s);
365 SCORE_DEBUG_CHECK_DELIMITER2(s);
369 template <
typename T>
376 template <
typename T, std::
size_t N>
381 for(std::size_t i = 0U; i < N; i++)
382 s.stream() << arr[i];
384 SCORE_DEBUG_INSERT_DELIMITER2(s);
389 for(std::size_t i = 0U; i < N; i++)
390 s.stream() >> arr[i];
392 SCORE_DEBUG_CHECK_DELIMITER2(s);
396 #if defined(OSSIA_SMALL_VECTOR)
397 template <
typename T, std::
size_t N>
402 s.stream() << (int32_t)arr.size();
403 for(std::size_t i = 0U; i < arr.size(); i++)
404 s.stream() << arr[i];
406 SCORE_DEBUG_INSERT_DELIMITER2(s);
415 for(int32_t i = 0; i < sz; i++)
416 s.stream() >> arr[i];
418 SCORE_DEBUG_CHECK_DELIMITER2(s);
422 template <
typename T, std::
size_t N>
427 s.stream() << (int32_t)arr.size();
428 for(int32_t i = 0U; i < arr.size(); i++)
429 s.stream() << arr[i];
431 SCORE_DEBUG_INSERT_DELIMITER2(s);
440 for(int32_t i = 0U; i < sz; i++)
441 s.stream() >> arr[i];
443 SCORE_DEBUG_CHECK_DELIMITER2(s);
447 template <
typename T, std::
size_t N>
448 OSSIA_INLINE QDataStream&
449 operator<<(QDataStream& stream,
const ossia::small_vector<T, N>& obj)
456 template <
typename T, std::
size_t N>
457 OSSIA_INLINE QDataStream& operator>>(QDataStream& stream, ossia::small_vector<T, N>& obj)
466 template <
typename T,
typename Alloc>
468 !is_QDataStreamSerializable<
typename std::vector<T, Alloc>::value_type>
469 && !std::is_pointer_v<T> && !is_shared_ptr_v<T>)
474 s.stream() << (int32_t)vec.size();
475 for(
const auto& elt : vec)
478 SCORE_DEBUG_INSERT_DELIMITER2(s);
488 for(int32_t i = 0; i < n; i++)
493 SCORE_DEBUG_CHECK_DELIMITER2(s);
497 template <
typename T,
typename Alloc>
499 !is_QDataStreamSerializable<
typename std::vector<T, Alloc>::value_type>
500 && !std::is_pointer_v<T> && !is_shared_ptr_v<T>)
506 s.stream() << (int32_t)vec.size();
507 for(
const auto& elt : vec)
510 SCORE_DEBUG_INSERT_DELIMITER2(s);
521 for(int32_t i = 0; i < n; i++)
526 SCORE_DEBUG_CHECK_DELIMITER2(s);
535 s.stream() << (int32_t)vec.size();
539 SCORE_DEBUG_INSERT_DELIMITER2(s);
549 for(
int i = 0; i < n; i++)
556 SCORE_DEBUG_CHECK_DELIMITER2(s);
560 template <
typename T,
typename Alloc>
561 requires(is_QDataStreamSerializable<
typename std::vector<T, Alloc>::value_type>)
566 s.stream() << (int32_t)vec.size();
567 for(
const auto& elt : vec)
570 SCORE_DEBUG_INSERT_DELIMITER2(s);
580 for(int32_t i = 0; i < n; i++)
582 s.stream() >> vec[i];
585 SCORE_DEBUG_CHECK_DELIMITER2(s);
589 template <
typename T,
typename Alloc>
590 requires(is_QDataStreamSerializable<
typename std::vector<T, Alloc>::value_type>)
596 s.stream() << (int32_t)vec.size();
597 for(
const auto& elt : vec)
600 SCORE_DEBUG_INSERT_DELIMITER2(s);
611 for(int32_t i = 0; i < n; i++)
613 s.stream() >> vec[i];
616 SCORE_DEBUG_CHECK_DELIMITER2(s);
620 template <
typename T>
623 using type = ossia::flat_set<T>;
626 s.stream() << (int32_t)obj.size();
627 for(
const auto& e : obj)
639 obj.insert(std::move(val));
644 template <
typename T,
typename U>
647 using type = std::pair<T, U>;
650 s.stream() << obj.first << obj.second;
655 s.stream() >> obj.first >> obj.second;
659 template <
typename T>
662 using type = std::shared_ptr<T>;
Definition: VisitorInterface.hpp:10
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
void readFrom(const T &obj)
Definition: DataStreamVisitor.hpp:67
void insertDelimiter()
insertDelimiter
Definition: DataStreamVisitor.hpp:156
Definition: DataStreamVisitor.hpp:202
The IdentifiedObject class.
Definition: IdentifiedObject.hpp:19
The id_base_t class.
Definition: Identifier.hpp:57
Definition: ApplicationComponents.hpp:68
Base for complex model objects.
Definition: EntityBase.hpp:24
Base toolkit upon which the software is built.
Definition: Application.cpp:90
auto marshall(const Object &obj)
marshall Serializes a single object
Definition: VisitorCommon.hpp:129
Definition: DataStreamHelpers.hpp:103
Definition: VisitorInterface.hpp:13
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26
Definition: VisitorTags.hpp:29
Definition: VisitorTags.hpp:152
Definition: VisitorTags.hpp:24