@@ -39,6 +39,14 @@ enum TypeOfTask : uint8_t {
3939 kUnknown
4040};
4141
42+ enum class PipelineStage {
43+ None,
44+ Validation,
45+ PreProcessing,
46+ Run,
47+ Done
48+ };
49+
4250// / @brief Indicates whether a task is enabled or disabled.
4351enum StatusOfTask : uint8_t {
4452 // / Task is enabled and should be executed
@@ -104,39 +112,44 @@ template <typename InType, typename OutType>
104112// / @tparam OutType Output data type.
105113class Task {
106114 public:
107- // / @brief Constructs a new Task object.
108- explicit Task (StateOfTesting /* state_of_testing*/ = StateOfTesting::kFunc ) { functions_order_.clear (); }
109-
110115 // / @brief Validates input data and task attributes before execution.
111116 // / @return True if validation is successful.
112117 virtual bool Validation () final {
113- InternalOrderTest (ppc::util::FuncName ());
118+ if (stage_ == PipelineStage::None) {
119+ stage_ = PipelineStage::Validation;
120+ }
114121 return ValidationImpl ();
115122 }
116123
117124 // / @brief Performs preprocessing on the input data.
118125 // / @return True if preprocessing is successful.
119126 virtual bool PreProcessing () final {
120- InternalOrderTest (ppc::util::FuncName ());
127+ if (stage_ == PipelineStage::Validation) {
128+ stage_ = PipelineStage::PreProcessing;
129+ }
121130 if (state_of_testing_ == StateOfTesting::kFunc ) {
122- InternalTimeTest (ppc::util::FuncName () );
131+ InternalTimeTest ();
123132 }
124133 return PreProcessingImpl ();
125134 }
126135
127136 // / @brief Executes the main logic of the task.
128137 // / @return True if execution is successful.
129138 virtual bool Run () final {
130- InternalOrderTest (ppc::util::FuncName ());
139+ if (stage_ == PipelineStage::PreProcessing || stage_ == PipelineStage::Run) {
140+ stage_ = PipelineStage::Run;
141+ }
131142 return RunImpl ();
132143 }
133144
134145 // / @brief Performs postprocessing on the output data.
135146 // / @return True if postprocessing is successful.
136147 virtual bool PostProcessing () final {
137- InternalOrderTest (ppc::util::FuncName ());
148+ if (stage_ == PipelineStage::Run) {
149+ stage_ = PipelineStage::Done;
150+ }
138151 if (state_of_testing_ == StateOfTesting::kFunc ) {
139- InternalTimeTest (ppc::util::FuncName () );
152+ InternalTimeTest ();
140153 }
141154 return PostProcessingImpl ();
142155 }
@@ -172,39 +185,25 @@ class Task {
172185 // / @brief Destructor. Verifies that the pipeline was executed in the correct order.
173186 // / @note Terminates the program if pipeline order is incorrect or incomplete.
174187 virtual ~Task () {
175- if (!functions_order_.empty () || !was_worked_) {
176- std::cerr << " ORDER OF FUNCTIONS IS NOT RIGHT! \n Expected - \" Validation\" , \" PreProcessing\" , \" Run\" , "
177- " \" PostProcessing\" \n " ;
188+ if (stage_ != PipelineStage::Done) {
189+ std::cerr << " ORDER OF FUNCTIONS IS NOT RIGHT" << std::endl;
178190 std::terminate ();
179- } else {
180- functions_order_.clear ();
181191 }
182192#if _OPENMP >= 201811
183193 omp_pause_resource_all (omp_pause_soft);
184194#endif
185195 }
186196
187197 protected:
188- // / @brief Verifies the correct order of pipeline method calls.
189- // / @param str Name of the method being called.
190- virtual void InternalOrderTest (const std::string &str) final {
191- functions_order_.push_back (str);
192- if (str == " PostProcessing" && IsFullPipelineStage ()) {
193- functions_order_.clear ();
194- } else {
195- was_worked_ = true ;
196- }
197- }
198-
199198 // / @brief Measures execution time between preprocessing and postprocessing steps.
200199 // / @param str Name of the method being timed.
201200 // / @throws std::runtime_error If execution exceeds the allowed time limit.
202- virtual void InternalTimeTest (const std::string &str ) final {
203- if (str == " PreProcessing" ) {
201+ virtual void InternalTimeTest () final {
202+ if (stage_ == PipelineStage:: PreProcessing) {
204203 tmp_time_point_ = std::chrono::high_resolution_clock::now ();
205204 }
206205
207- if (str == " PostProcessing " ) {
206+ if (stage_ == PipelineStage::Done ) {
208207 auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now () -
209208 tmp_time_point_)
210209 .count ();
@@ -244,26 +243,9 @@ class Task {
244243 StateOfTesting state_of_testing_ = kFunc ;
245244 TypeOfTask type_of_task_ = kUnknown ;
246245 StatusOfTask status_of_task_ = kEnabled ;
247- std::vector<std::string> functions_order_;
248- std::vector<std::string> right_functions_order_ = {" Validation" , " PreProcessing" , " Run" , " PostProcessing" };
249246 static constexpr double kMaxTestTime = 1.0 ;
250247 std::chrono::high_resolution_clock::time_point tmp_time_point_;
251- bool was_worked_ = false ;
252-
253- bool IsFullPipelineStage () {
254- if (functions_order_.size () < 4 ) {
255- return false ;
256- }
257-
258- auto it = std::adjacent_find (functions_order_.begin () + 2 ,
259- functions_order_.begin () + static_cast <long >(functions_order_.size () - 2 ),
260- std::not_equal_to<>());
261-
262- return (functions_order_[0 ] == " Validation" && functions_order_[1 ] == " PreProcessing" &&
263- functions_order_[2 ] == " Run" &&
264- it == (functions_order_.begin () + static_cast <long >(functions_order_.size () - 2 )) &&
265- functions_order_[functions_order_.size () - 1 ] == " PostProcessing" );
266- }
248+ PipelineStage stage_ = PipelineStage::None;
267249};
268250
269251// / @brief Smart pointer alias for Task.
0 commit comments