|
| 1 | + |
| 2 | +// Decorators taken from Java |
| 3 | + |
| 4 | +#define DECORATOR_NOTE \ |
| 5 | + "\n" \ |
| 6 | + "Note: This decorator works by composing this command within a CommandGroup. The command\n" \ |
| 7 | + "cannot be used independently after being decorated, or be re-decorated with a different\n" \ |
| 8 | + "decorator, unless it is manually cleared from the list of grouped commands with Command.setGrouped(False)\n" \ |
| 9 | + "The decorated command can, however, be further decorated without issue\n" |
| 10 | + |
| 11 | + |
| 12 | +cls_Command |
| 13 | + .def("andThen", |
| 14 | + [](Command* self, py::args cmds) { |
| 15 | + std::vector<std::shared_ptr<Command>> commands; |
| 16 | + commands.emplace_back(self->shared_from_this()); |
| 17 | + for (auto cmd : cmds) { |
| 18 | + auto cmdptr = py::cast<std::shared_ptr<Command>>(cmd); |
| 19 | + commands.emplace_back(cmdptr); |
| 20 | + } |
| 21 | + return std::make_shared<SequentialCommandGroup>(std::move(commands)); |
| 22 | + }, |
| 23 | + "Decorates this command with a set of commands to run after it in sequence. Often more\n" |
| 24 | + "convenient/less-verbose than constructing a new {@link SequentialCommandGroup} explicitly.\n" |
| 25 | + DECORATOR_NOTE) |
| 26 | + .def("alongWith", |
| 27 | + [](Command* self, py::args cmds) { |
| 28 | + std::vector<std::shared_ptr<Command>> commands; |
| 29 | + commands.emplace_back(self->shared_from_this()); |
| 30 | + for (auto cmd : cmds) { |
| 31 | + auto cmdptr = py::cast<std::shared_ptr<Command>>(cmd); |
| 32 | + commands.emplace_back(cmdptr); |
| 33 | + } |
| 34 | + return std::make_shared<ParallelCommandGroup>(std::move(commands)); |
| 35 | + }, |
| 36 | + "Decorates this command with a set of commands to run parallel to it, " |
| 37 | + "ending when the last\n" |
| 38 | + "command ends. Often more convenient/less-verbose than constructing a new\n" |
| 39 | + "ParallelCommandGroup explicitly.\n" |
| 40 | + DECORATOR_NOTE) |
| 41 | + .def("deadlineWith", |
| 42 | + [](Command* self, py::args cmds) { |
| 43 | + return std::make_shared<ParallelDeadlineGroup>( |
| 44 | + self->shared_from_this(), std::move(pyargs2cmdList(cmds))); |
| 45 | + }, |
| 46 | + "Decorates this command with a set of commands to run parallel to it, ending when the calling\n" |
| 47 | + "command ends and interrupting all the others. Often more convenient/less-verbose than\n" |
| 48 | + "constructing a new {@link ParallelDeadlineGroup} explicitly.\n" |
| 49 | + DECORATOR_NOTE) |
| 50 | + .def("raceWith", |
| 51 | + [](Command* self, py::args cmds) { |
| 52 | + std::vector<std::shared_ptr<Command>> commands; |
| 53 | + commands.emplace_back(self->shared_from_this()); |
| 54 | + for (auto cmd : cmds) { |
| 55 | + auto cmdptr = py::cast<std::shared_ptr<Command>>(cmd); |
| 56 | + commands.emplace_back(cmdptr); |
| 57 | + } |
| 58 | + return std::make_shared<ParallelRaceGroup>(std::move(commands)); |
| 59 | + }, |
| 60 | + "Decorates this command with a set of commands to run parallel to it, ending when the first\n" |
| 61 | + "command ends. Often more convenient/less-verbose than constructing a new\n" |
| 62 | + "ParallelRaceGroup explicitly.\n" |
| 63 | + DECORATOR_NOTE) |
| 64 | + ; |
| 65 | + |
0 commit comments