2 #include <score/model/Component.hpp>
3 #if defined(SCORE_SERIALIZABLE_COMPONENTS)
4 #include <score/plugins/InterfaceList.hpp>
5 #include <score/plugins/SerializableInterface.hpp>
18 class SCORE_LIB_BASE_EXPORT DataStreamSerializedComponents :
public score::Component
20 COMMON_COMPONENT_METADATA(
"a0c8de61-c18f-4aca-8b21-cf71451f4970")
22 static const constexpr
bool is_unique = true;
23 DataStreamSerializedComponents(
24 const
Id<
score::Component>&
id, DataStreamComponents obj, QObject* parent);
25 virtual ~DataStreamSerializedComponents();
28 bool deserializeRemaining(
score::Components& comps, QObject* entity);
30 bool finished()
const {
return data.empty(); }
32 DataStreamComponents data;
35 class SCORE_LIB_BASE_EXPORT JSONSerializedComponents :
public score::Component
37 COMMON_COMPONENT_METADATA(
"37939615-7165-4bb0-9cdd-e7426153d222")
39 static const constexpr
bool is_unique = true;
40 JSONSerializedComponents(
41 const
Id<
score::Component>&
id, JSONComponents obj, QObject* parent);
43 virtual ~JSONSerializedComponents();
46 bool deserializeRemaining(
score::Components& comps, QObject* entity);
48 bool finished()
const {
return data.empty(); }
53 class SCORE_LIB_BASE_EXPORT SerializableComponent
58 using score::Component::Component;
60 template <
typename Vis>
61 SerializableComponent(Vis& vis, QObject* parent)
62 :
score::Component{vis, parent}
66 virtual InterfaceKey interfaceKey()
const = 0;
71 SCORE_INTERFACE(SerializableComponentFactory,
"ffafadc2-0ce7-45d8-b673-d9238c37d018")
73 ~SerializableComponentFactory() override;
74 virtual
score::SerializableComponent* make(
75 const
Id<
score::Component>&
id, const
score::DocumentContext& ctx, QObject* parent)
78 virtual
score::SerializableComponent*
83 struct SCORE_LIB_BASE_EXPORT SerializableComponentFactoryList
84 : public
score::InterfaceList<SerializableComponentFactory>
86 using object_type = score::SerializableComponent;
87 ~SerializableComponentFactoryList();
88 score::SerializableComponent* loadMissing(
90 QObject* parent)
const;
93 template <
typename System_T>
94 class GenericSerializableComponent :
public score::SerializableComponent
97 template <
typename... Args>
98 GenericSerializableComponent(System_T& sys, Args&&... args)
99 :
score::SerializableComponent{std::forward<Args>(args)...}
104 System_T& system()
const {
return m_system; }
110 struct serializable_tag
113 struct not_serializable_tag
117 template <
typename T,
typename =
void>
118 struct is_component_serializable
120 using type = score::not_serializable_tag;
121 static constexpr
bool value =
false;
124 template <
typename T>
125 struct is_component_serializable<
126 T, std::enable_if_t<std::is_base_of<score::SerializableComponent, T>::value>>
128 using type = score::serializable_tag;
129 static constexpr
bool value =
true;
132 template <
typename Component_T,
typename Fun>
135 if(
auto datastream_ser = findComponent<DataStreamSerializedComponents>(comps))
137 auto& data = datastream_ser->data;
138 auto it = data.find(Component_T::static_key());
150 else if(
auto json_ser = findComponent<JSONSerializedComponents>(comps))
152 auto& data = json_ser->data;
153 auto it = data.find(Component_T::static_key());
167 SCORE_LIB_BASE_EXPORT
Definition: DataStreamVisitor.hpp:202
Definition: JSONVisitor.hpp:423
The id_base_t class.
Definition: Identifier.hpp:57
A component adds custom data to an Entity.
Definition: lib/score/model/Component.hpp:25
Base class for plug-in interfaces.
Definition: Interface.hpp:52
Generic serialization method for abstract classes.
Definition: SerializableInterface.hpp:21
Base toolkit upon which the software is built.
Definition: Application.cpp:90
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26
Definition: lib/score/model/Component.hpp:41
Definition: DocumentContext.hpp:18