1#ifndef SRC_COMMON_PIPELINE_PIPELINES_HPP_
2#define SRC_COMMON_PIPELINE_PIPELINES_HPP_
8#include "common/pipeline/stages.hpp"
11#define DEFAULT_NUM_STAGES 10
25template<
typename Input,
27 size_t N = DEFAULT_NUM_STAGES>
60 virtual Output
Run(
const Input &input) = 0;
84 if (this->ready)
throw std::invalid_argument(
"Pipeline is already ready");
85 this->stages[
size++] = &stage;
103 assert(this->size < N);
104 if (this->ready)
throw std::invalid_argument(
"Pipeline is already ready");
105 this->stages[
size++] = &stage;
115 for (
size_t i = 0; i < this->
size; i++) {
141template<
typename Input,
typename Output,
size_t N = DEFAULT_NUM_STAGES>
166 if (this->
size == 0) {
167 if (!std::is_same<Input, I>::value) {
168 throw std::invalid_argument(
"The initial input type is not correct");
199 assert(this->
size < N);
200 if (this->
ready)
throw std::invalid_argument(
"Pipeline is already ready");
222 Output
Run(
const Input &input)
override {
226 throw std::runtime_error(
"This is an illegal action: the pipeline is not ready yet");
231 if (this->
product ==
nullptr) {
257template<
typename T,
size_t N = DEFAULT_NUM_STAGES>
273 assert(this->
size < N - 1);
289 assert(this->
size < N);
302 T
Run(
const T &input)
override {
305 throw std::runtime_error(
"This is an illegal action: the pipeline is not ready yet");
308 if (this->
product ==
nullptr) {
314 for (
size_t i = 0; i < this->
size; i++) {
Action is an interface that wraps a function that does something.
Definition stages.hpp:17
virtual void DoAction()=0
Performs some action.
A FunctionStage is a data structure that wraps a function, and taking in parameter Input and returnin...
Definition stages.hpp:56
Output * product
The pointer to the stored output for this.
Definition stages.hpp:96
Input & GetResource()
Returns the stored input of this.
Definition stages.hpp:82
Output *& GetProduct()
Returns the stored output of this.
Definition stages.hpp:90
Input resource
The stored input for this.
Definition stages.hpp:94
A ModifyingPipeline modifies a resource with a given set of stages.
Definition pipelines.hpp:258
ModifyingPipeline & Complete(ModifyingStage< T > &stage)
Completes a pipeline with a stage.
Definition pipelines.hpp:288
ModifyingPipeline()=default
Constructs a ModifyingPipeline.
T Run(const T &input) override
Executes this Modifying Pipeline.
Definition pipelines.hpp:302
ModifyingPipeline & AddStage(ModifyingStage< T > &stage)
Adds a stage to this.
Definition pipelines.hpp:272
ModifyingStage is a stage that modifies a resource.
Definition stages.hpp:105
A Pipeline<Input, Output, N> is an abstract Pipeline that takes an Input, outputs an Output,...
Definition pipelines.hpp:28
void DoActionHelper()
Runs the entire pipeline.
Definition pipelines.hpp:114
std::optional< Output > finalProduct
The final product. This is only sometimes used.
Definition pipelines.hpp:70
size_t size
The number of stages.
Definition pipelines.hpp:66
void AddStageHelper(Action &stage)
Adds a stage to this pipeline.
Definition pipelines.hpp:83
virtual Output Run(const Input &input)=0
Runs this Pipeline.
void CompleteHelper(Action &stage)
Completes a pipeline with a stage.
Definition pipelines.hpp:102
Action * stages[N]
The stages of this.
Definition pipelines.hpp:64
void DoAction() override
Runs a Pipeline.
Definition pipelines.hpp:40
bool ready
Whether we're complete.
Definition pipelines.hpp:68
SequentialPipeline is composite Stage (i.e.
Definition pipelines.hpp:142
void ** lastProduct
A temporary variable that always points to the last Stage's product field.
Definition pipelines.hpp:247
SequentialPipeline & Complete(FunctionStage< I, Output > &stage)
Adds a stage to the pipeline and marks it as the last stage, preventing further manipulation of the S...
Definition pipelines.hpp:198
SequentialPipeline()=default
Constructs an empty SequentialPipeline.
SequentialPipeline & AddStage(FunctionStage< I, O > &stage)
Adds a stage to this pipeline.
Definition pipelines.hpp:165
Input * firstResource
The pointer to the variable that will store the first input.
Definition pipelines.hpp:245
Output Run(const Input &input) override
Executes this SequentialPipeline.
Definition pipelines.hpp:222