-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathhelpers.cpp
42 lines (36 loc) · 1.25 KB
/
helpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "helpers.h"
std::vector<std::shared_ptr<frc2::Command>> pyargs2cmdList(py::args cmds) {
std::vector<std::shared_ptr<frc2::Command>> commands;
for (auto cmd : cmds) {
commands.emplace_back(py::cast<std::shared_ptr<frc2::Command>>(cmd));
}
return commands;
}
std::vector<std::shared_ptr<frc2::Subsystem>> pyargs2SharedSubsystemList(py::args subs) {
std::vector<std::shared_ptr<frc2::Subsystem>> subsystems;
for (auto sub : subs) {
subsystems.emplace_back(py::cast<std::shared_ptr<frc2::Subsystem>>(sub));
}
return subsystems;
}
std::vector<frc2::Subsystem*> pyargs2SubsystemList(py::args subs) {
std::vector<frc2::Subsystem*> subsystems;
for (auto sub : subs) {
subsystems.emplace_back(py::cast<frc2::Subsystem*>(sub));
}
return subsystems;
}
CommandIterator::CommandIterator(std::shared_ptr<frc2::Command> cmd) : cmd(cmd) {}
std::shared_ptr<frc2::Command> CommandIterator::operator*() const { return cmd; }
CommandIterator& CommandIterator::operator++() {
if (!called_initialize) {
cmd->Initialize();
called_initialize = true;
return *this;
}
cmd->Execute();
return *this;
}
bool operator==(const CommandIterator& it, const CommandIteratorSentinel&) {
return it.called_initialize && it.cmd->IsFinished();
}