28 virtual bool test() = 0;
33 static constexpr double default_timeout = 10.0;
39 virtual bool run() {
return true; }
43 virtual void on_timeout() {}
44 AutoCommand *withTimeout(
double t_seconds) {
45 if (this->timeout_seconds < 0) {
49 this->timeout_seconds = t_seconds;
52 AutoCommand *withCancelCondition(
Condition *true_to_end) {
53 this->true_to_end = true_to_end;
65 double timeout_seconds = default_timeout;
76 bool run() {
return f(); }
79 std::function<bool(
void)> f;
88class TimesTestedCondition :
public Condition {
90 TimesTestedCondition(
size_t N) : max(N) {}
91 bool test()
override {
108 std::function<
bool()> cond, std::function<
void(
void)> timeout = []() {})
109 : cond(cond), timeout(timeout) {}
110 bool test()
override;
113 std::function<bool()> cond;
114 std::function<void(
void)> timeout;
122 bool test()
override;
133 bool run()
override {
return cond->test(); }
147 InOrder(std::queue<AutoCommand *> cmds);
148 InOrder(std::initializer_list<AutoCommand *> cmds);
150 void on_timeout()
override;
153 AutoCommand *current_command =
nullptr;
154 std::queue<AutoCommand *> cmds;
162 Parallel(std::initializer_list<AutoCommand *> cmds);
164 void on_timeout()
override;
167 std::vector<AutoCommand *> cmds;
168 std::vector<vex::task *> runners;
176 Branch(
Condition *cond, AutoCommand *false_choice, AutoCommand *true_choice);
179 void on_timeout()
override;
182 AutoCommand *false_choice;
183 AutoCommand *true_choice;
195 Async(AutoCommand *cmd) : cmd(cmd) {}
199 AutoCommand *cmd =
nullptr;
202class RepeatUntil :
public AutoCommand {
207 RepeatUntil(
InOrder cmds,
size_t repeats);
213 void on_timeout()
override;
Async runs a command asynchronously will simply let it go and never look back THIS HAS A VERY NICHE U...
Definition auto_command.h:193
Branch chooses from multiple options at runtime. the function decider returns an index into the choic...
Definition auto_command.h:174
Definition auto_command.h:24
Definition auto_command.h:73
FunctionCondition is a quick and dirty Condition to wrap some expression that should be evaluated at ...
Definition auto_command.h:105
IfTimePassed tests based on time since the command controller was constructed. Returns true if elapse...
Definition auto_command.h:119
InOrder runs its commands sequentially then continues. How to handle timeout in this case....
Definition auto_command.h:144
Parallel runs multiple commands in parallel and waits for all to finish before continuing....
Definition auto_command.h:160
Waits until the condition is true.
Definition auto_command.h:130