FOUND
Loading...
Searching...
No Matches
stages.hpp
1#ifndef SRC_COMMON_PIPELINE_STAGES_HPP_
2#define SRC_COMMON_PIPELINE_STAGES_HPP_
3
4#include <type_traits>
5
6namespace found {
7
10template<typename T>
11using raw_type = std::remove_cv_t<std::remove_reference_t<T>>;
12
17class Action {
18 public:
22 virtual void DoAction() = 0;
23};
24
34template<typename Input, typename Output>
35class Stage : public Action {
36 public:
44 virtual Output Run(Input input) = 0;
45};
46
55template<typename Input, typename Output>
56class FunctionStage : public Stage<const raw_type<Input> &, raw_type<Output>> {
57 public:
61 FunctionStage() = default;
62
66 virtual ~FunctionStage() = default;
67
73 void DoAction() override {
74 *this->product = this->Run(this->resource);
75 };
76
82 Input &GetResource() {return resource;}
83
90 Output *&GetProduct() {return product;}
91
92 protected:
94 Input resource;
96 Output *product = nullptr;
97};
98
104template<typename T>
105class ModifyingStage : public Stage<raw_type<T> &, void> {
106 public:
110 ModifyingStage() = default;
111
115 virtual ~ModifyingStage() = default;
116
120 void DoAction() override {
121 this->Run(*this->resource);
122 };
123
132 void SetResource(T &resource) {this->resource = &resource;}
133
134 private:
136 T *resource = nullptr;
137};
138
139} // namespace found
140
141
142#endif // SRC_COMMON_PIPELINE_STAGES_HPP_
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
FunctionStage()=default
Constructs a new Stage.
void DoAction() override
Executes Run (with a stored input and storing the output)
Definition stages.hpp:73
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
virtual ~FunctionStage()=default
Destroys this.
ModifyingStage is a stage that modifies a resource.
Definition stages.hpp:105
T * resource
The pointer to the resource.
Definition stages.hpp:136
virtual ~ModifyingStage()=default
Destroys this.
ModifyingStage()=default
Constructs a new ModifyingStage.
void SetResource(T &resource)
Sets the resource to modify.
Definition stages.hpp:132
void DoAction() override
Executes Run (with void return)
Definition stages.hpp:120
Stage is an interface that wraps an SISO function.
Definition stages.hpp:35
virtual Output Run(Input input)=0
Runs this stage.