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:
19 virtual ~Action() = default;
23 virtual void DoAction() = 0;
24};
25
35template<typename Input, typename Output>
36class Stage : public Action {
37 public:
45 virtual Output Run(Input input) = 0;
46};
47
56template<typename Input, typename Output>
57class FunctionStage : public Stage<const raw_type<Input> &, raw_type<Output>> {
58 public:
62 FunctionStage() = default;
63
67 virtual ~FunctionStage() = default;
68
74 void DoAction() override {
75 *this->product = this->Run(this->resource);
76 };
77
83 Input &GetResource() {return resource;}
84
91 Output *&GetProduct() {return product;}
92
93 protected:
95 Input resource;
97 Output *product = nullptr;
98};
99
105template<typename T>
106class ModifyingStage : public Stage<raw_type<T> &, void> {
107 public:
111 ModifyingStage() = default;
112
116 virtual ~ModifyingStage() = default;
117
121 void DoAction() override {
122 this->Run(*this->resource);
123 };
124
133 void SetResource(T &resource) {this->resource = &resource;}
134
135 private:
137 T *resource = nullptr;
138};
139
140} // namespace found
141
142
143#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:57
Output * product
The pointer to the stored output for this.
Definition stages.hpp:97
FunctionStage()=default
Constructs a new Stage.
void DoAction() override
Executes Run (with a stored input and storing the output)
Definition stages.hpp:74
Input & GetResource()
Returns the stored input of this.
Definition stages.hpp:83
Output *& GetProduct()
Returns the stored output of this.
Definition stages.hpp:91
Input resource
The stored input for this.
Definition stages.hpp:95
virtual ~FunctionStage()=default
Destroys this.
ModifyingStage is a stage that modifies a resource.
Definition stages.hpp:106
T * resource
The pointer to the resource.
Definition stages.hpp:137
virtual ~ModifyingStage()=default
Destroys this.
ModifyingStage()=default
Constructs a new ModifyingStage.
void SetResource(T &resource)
Sets the resource to modify.
Definition stages.hpp:133
void DoAction() override
Executes Run (with void return)
Definition stages.hpp:121
Stage is an interface that wraps an SISO function.
Definition stages.hpp:36
virtual Output Run(Input input)=0
Runs this stage.