32template<
typename Input,
typename Output>
52 virtual Output
Run(
const Input &input) = 0;
99template<
typename Input,
typename Output>
107 explicit Pipeline(std::vector<std::reference_wrapper<Action>> &stages)
108 : stages(stages), firstResource(nullptr), ready(false) {}
126 if (this->ready)
throw std::invalid_argument(
"Pipeline is already ready");
127 if (this->stages.empty()) {
128 if (!std::is_same<Input, I>::value)
throw std::invalid_argument(
"The initial input type is not correct");
129 this->firstResource =
reinterpret_cast<Input *
>(&stage.
GetResource());
132 *this->lastProduct =
static_cast<void *
>(&stage.
GetResource());
135 this->stages.push_back(stage);
137 this->lastProduct =
reinterpret_cast<void **
>(&stage.
GetProduct());
177 Output
Run(
const Input &input)
override {
178 if (!this->ready)
throw std::runtime_error(
"This is an illegal action: the pipeline is not ready yet");
180 *this->firstResource = input;
181 for (
Action &stage : this->stages) {
184 return this->finalProduct;
189 std::vector<std::reference_wrapper<Action>> stages;
191 Input *firstResource;
195 void **lastProduct =
nullptr;
Definition pipeline.hpp:16
virtual void DoAction()=0
Definition pipeline.hpp:100
Output Run(const Input &input) override
Definition pipeline.hpp:177
Pipeline & Complete(Stage< I, Output > &stage)
Definition pipeline.hpp:154
Pipeline & AddStage(Stage< I, O > &stage)
Definition pipeline.hpp:124
Pipeline(std::vector< std::reference_wrapper< Action > > &stages)
Definition pipeline.hpp:107
Definition pipeline.hpp:33
Input & GetResource()
Definition pipeline.hpp:66
Output * product
The pointer to the stored output for this.
Definition pipeline.hpp:80
Output *& GetProduct()
Definition pipeline.hpp:74
void DoAction() override
Definition pipeline.hpp:57
virtual Output Run(const Input &input)=0
Input resource
The stored input for this.
Definition pipeline.hpp:78
Definition converters.hpp:10