Loading...
Searching...
No Matches
GenericProcessFactory.hpp
1#pragma once
2#include <Process/ProcessFactory.hpp>
3
5#include <score/tools/SafeCast.hpp>
6
7namespace Process
8{
10{
11};
12
13template <typename Model_T>
15{
16public:
17 virtual ~ProcessFactory_T() = default;
18
19 UuidKey<Process::ProcessModel> concreteKey() const noexcept override
20 {
22 }
23 QString prettyName() const noexcept override
24 {
26 }
27 QString category() const noexcept override
28 {
30 }
31 Descriptor descriptor(QString) const noexcept override
32 {
34 }
35 ProcessFlags flags() const noexcept override
36 {
38 }
39
40 Model_T* make(
41 const TimeVal& duration, const QString& data, const Id<Process::ProcessModel>& id,
42 const score::DocumentContext& ctx, QObject* parent) final override;
43
44 Model_T* load(
45 const VisitorVariant& vis, const score::DocumentContext& ctx,
46 QObject* parent) final override;
47};
48
49template <typename Model_T>
51 const TimeVal& duration, const QString& data, const Id<Process::ProcessModel>& id,
52 const score::DocumentContext& ctx, QObject* parent)
53{
54 if constexpr(std::is_constructible_v<
55 Model_T, TimeVal, QString, Id<Process::ProcessModel>, QObject*>)
56 {
57 if(!data.isEmpty())
58 {
59 return new Model_T{duration, data, id, parent};
60 }
61 else
62 {
63 if constexpr(std::is_constructible_v<
65 const score::DocumentContext&, QObject*>)
66 {
67 return new Model_T{duration, id, ctx, parent};
68 }
69 else if constexpr(std::is_constructible_v<
71 const score::DocumentContext&, QObject*>)
72 {
73 return new Model_T{duration, id, parent};
74 }
75 else
76 {
77 return new Model_T{duration, data, id, parent};
78 }
79 }
80 }
81 else if constexpr(std::is_constructible_v<
83 const score::DocumentContext&, QObject*>)
84 return new Model_T{duration, id, ctx, parent};
85 else
86 return new Model_T{duration, id, parent};
87}
88
89template <typename Model_T>
90Model_T* ProcessFactory_T<Model_T>::load(
91 const VisitorVariant& vis, const score::DocumentContext& ctx, QObject* parent)
92{
93 return score::deserialize_dyn(vis, [&](auto&& deserializer) {
94 if constexpr(std::is_constructible_v<
95 Model_T, decltype(deserializer), const score::DocumentContext&,
96 QObject*>)
97 return new Model_T{deserializer, ctx, parent};
98 else
99 return new Model_T{deserializer, parent};
100 });
101}
102
103template <
104 typename Model_T, typename LayerPresenter_T, typename LayerView_T,
105 typename HeaderDelegate_T = default_t>
107{
108public:
109 virtual ~LayerFactory_T() = default;
110
111private:
112 UuidKey<Process::ProcessModel> concreteKey() const noexcept override
113 {
115 }
116
117 std::optional<double> recommendedHeight() const noexcept override
118 {
119 if constexpr(bool(LayerPresenter_T::recommendedHeight))
120 {
121 return LayerPresenter_T::recommendedHeight;
122 }
123 return LayerFactory::recommendedHeight();
124 }
125
126 LayerView_T* makeLayerView(
127 const Process::ProcessModel& viewmodel, const Process::Context& context,
128 QGraphicsItem* parent) const final override
129 {
130 if constexpr(std::is_constructible_v<
131 LayerView_T, const Model_T&, const Process::Context&,
132 QGraphicsItem*>)
133 return new LayerView_T{safe_cast<const Model_T&>(viewmodel), context, parent};
134 else if constexpr(std::is_constructible_v<
135 LayerView_T, const Model_T&, QGraphicsItem*>)
136 return new LayerView_T{safe_cast<const Model_T&>(viewmodel), parent};
137 else
138 return new LayerView_T{parent};
139 }
140
141 LayerPresenter_T* makeLayerPresenter(
143 const Process::Context& context, QObject* parent) const final override
144 {
145 return new LayerPresenter_T{
146 safe_cast<const Model_T&>(lm), safe_cast<LayerView_T*>(v), context, parent};
147 }
148
149 bool matches(const UuidKey<Process::ProcessModel>& p) const override
150 {
152 }
153
154 HeaderDelegate* makeHeaderDelegate(
155 const ProcessModel& model, const Process::Context& ctx,
156 QGraphicsItem* parent) const override
157 {
158 if constexpr(std::is_same_v<HeaderDelegate_T, default_t>)
159 return LayerFactory::makeHeaderDelegate(model, ctx, parent);
160 else
161 return new HeaderDelegate_T{model, ctx};
162 }
163};
164
165template <typename Model_T>
167 : // final :
169{
170public:
171 virtual ~LayerFactory_T() = default;
172
173private:
174 UuidKey<Process::ProcessModel> concreteKey() const noexcept override
175 {
177 }
178
179 bool matches(const UuidKey<Process::ProcessModel>& p) const override
180 {
182 }
183};
184
185template <typename Model_T>
188}
Definition HeaderDelegate.hpp:16
Definition GenericProcessFactory.hpp:107
Definition score-lib-process/Process/ProcessFactory.hpp:59
Definition LayerView.hpp:21
Definition GenericProcessFactory.hpp:15
The ProcessFactory class.
Definition score-lib-process/Process/ProcessFactory.hpp:35
The Process class.
Definition score-lib-process/Process/Process.hpp:61
Definition UuidKey.hpp:343
The id_base_t class.
Definition Identifier.hpp:57
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
ProcessFlags
Various settings for processes.
Definition ProcessFlags.hpp:17
Static metadata implementation.
Definition lib/score/tools/Metadata.hpp:36
Definition ProcessContext.hpp:12
Definition score-lib-process/Process/ProcessMetadata.hpp:37
Definition GenericProcessFactory.hpp:10
Definition TimeValue.hpp:21
The VisitorVariant struct.
Definition VisitorInterface.hpp:26
Definition ObjectMatches.hpp:6
Definition DocumentContext.hpp:18