FOUND Coverage Report


src/
File: common/pipeline/stages.hpp
Date: 2026-03-24 21:41:51
Lines:
13/13
100.0%
Functions:
128/128
100.0%
Branches:
1/1
100.0%

Line Branch Exec Source
1 #ifndef SRC_COMMON_PIPELINE_STAGES_HPP_
2 #define SRC_COMMON_PIPELINE_STAGES_HPP_
3
4 #include <type_traits>
5
6 namespace found {
7
8 /// Type Alias Template for resolving any type parameter
9 /// into its non-const non-lvalue
10 template<typename T>
11 using raw_type = std::remove_cv_t<std::remove_reference_t<T>>;
12
13 /**
14 * Action is an interface that
15 * wraps a function that does something
16 */
17 class Action {
18 public:
19 /**
20 * Performs some action
21 */
22 virtual void DoAction() = 0;
23 };
24
25 /**
26 * Stage is an interface that
27 * wraps an SISO function
28 *
29 * @param Input The input type
30 * @param Output The output type
31 *
32 * @pre Input must be able to be default constructed
33 */
34 template<typename Input, typename Output>
35 class Stage : public Action {
36 public:
37 /**
38 * Runs this stage
39 *
40 * @param input The input to the stage
41 *
42 * @return The output of this stage
43 */
44 virtual Output Run(Input input) = 0;
45 };
46
47 /**
48 * A FunctionStage is a data structure that
49 * wraps a function, and taking in
50 * parameter Input and returning Output
51 *
52 * @param Input The parameter to accept to the Run function
53 * @param Output The parameter to return from the Run function
54 */
55 template<typename Input, typename Output>
56 class FunctionStage : public Stage<const raw_type<Input> &, raw_type<Output>> {
57 public:
58 /**
59 * Constructs a new Stage
60 */
61 430 FunctionStage() = default;
62
63 /**
64 * Destroys this
65 */
66 462 virtual ~FunctionStage() = default;
67
68 /**
69 * Executes Run (with a stored input and storing the output)
70 *
71 * @pre this->product points to a valid location
72 */
73 163 void DoAction() override {
74
1/1
✓ Branch 2 taken 25 times.
163 *this->product = this->Run(this->resource);
75 163 };
76
77 /**
78 * Returns the stored input of this
79 *
80 * @return The stored input of this
81 */
82 210 Input &GetResource() {return resource;}
83
84 /**
85 * Returns the stored output of this
86 *
87 * @return The pointer to the stored output
88 * of this
89 */
90 252 Output *&GetProduct() {return product;}
91
92 protected:
93 /// The stored input for this
94 Input resource;
95 /// The pointer to the stored output for this
96 Output *product = nullptr;
97 };
98
99 /**
100 * ModifyingStage is a stage that modifies a resource
101 *
102 * @param T The type of resource being modified
103 */
104 template<typename T>
105 class ModifyingStage : public Stage<raw_type<T> &, void> {
106 public:
107 /**
108 * Constructs a new ModifyingStage
109 */
110 34 ModifyingStage() = default;
111
112 /**
113 * Destroys this
114 */
115 34 virtual ~ModifyingStage() = default;
116
117 /**
118 * Executes Run (with void return)
119 */
120 26 void DoAction() override {
121 26 this->Run(*this->resource);
122 26 };
123
124 /**
125 * Sets the resource to modify
126 *
127 * @param resource The resource to modify
128 *
129 * @post When used in a ModifyingPipeline,
130 * this will modify resource via Run(T &)
131 */
132 26 void SetResource(T &resource) {this->resource = &resource;}
133
134 private:
135 /// The pointer to the resource
136 T *resource = nullptr;
137 };
138
139 } // namespace found
140
141
142 #endif // SRC_COMMON_PIPELINE_STAGES_HPP_
143