Grok 20.3.2
FlowComponent.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2026 Grok Image Compression Inc.
3 *
4 * This source code is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This source code is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#pragma once
19
20#include "grk_taskflow.h"
21
27class FlowComponent : public tf::Taskflow
28{
29public:
36 void addTo(tf::Taskflow& composition)
37 {
38 compositionTask_ = composition.composed_of(*this);
39 }
40
47 void precede(FlowComponent& successor)
48 {
49 compositionTask_.precede(successor.compositionTask_);
50 }
51
58 void precede(tf::Task& successor)
59 {
60 compositionTask_.precede(successor);
61 }
62
63 tf::Task& getCompositionTask(void)
64 {
65 return compositionTask_;
66 }
67
79 std::function<int()> condition_lambda)
80 {
81 auto condition = root->emplace(condition_lambda).name("condition");
82 auto noop = root->emplace([]() {}).name("noop");
83
84 precede(condition);
85 condition.precede(successor->getCompositionTask(), noop);
86 }
87
94 FlowComponent* name(const std::string& name)
95 {
96 if(!name.empty())
97 {
99 }
100 else
101 {
102 compositionTask_.name("UnnamedFlowComponent");
103 }
104 return this;
105 }
106
112 tf::Task& nextTask()
113 {
114 auto task = placeholder();
115 componentTasks_.emplace_back(std::move(task));
116 return componentTasks_.back();
117 }
118
119private:
124 std::vector<tf::Task> componentTasks_;
125
132};
A collection of tasks which can be scheduled as a single task.
Definition FlowComponent.h:28
void conditional_precede(FlowComponent *root, FlowComponent *successor, std::function< int()> condition_lambda)
Conditionally schedule successor based on condition_lambda.
Definition FlowComponent.h:78
tf::Task & nextTask()
Gets next task placeholder for componentFlow_.
Definition FlowComponent.h:112
tf::Task compositionTask_
tf::Task for the composition of this tf::Taskflow with another tf::Taskflow
Definition FlowComponent.h:131
FlowComponent * name(const std::string &name)
Gets name of composition task.
Definition FlowComponent.h:94
void addTo(tf::Taskflow &composition)
Composes this FlowComponent's tf::Taskflow with another tf::Taskflow.
Definition FlowComponent.h:36
tf::Task & getCompositionTask(void)
Definition FlowComponent.h:63
void precede(FlowComponent &successor)
Schedule this FlowComponent before another FlowComponent.
Definition FlowComponent.h:47
void precede(tf::Task &successor)
Schedule this Taskflow before another FlowComponent.
Definition FlowComponent.h:58
std::vector< tf::Task > componentTasks_
A std::vector of tf::Task belonging to this FlowComponent.
Definition FlowComponent.h:124