[commands] C++: Add CommandPtr overload for SetDefaultCommand (#4488)

This commit is contained in:
Starlight220
2022-10-21 16:35:58 +03:00
committed by GitHub
parent 0ca274866b
commit 9c7e66a27d
4 changed files with 46 additions and 0 deletions

View File

@@ -296,6 +296,20 @@ void CommandScheduler::UnregisterSubsystem(
}
}
void CommandScheduler::SetDefaultCommand(Subsystem* subsystem,
CommandPtr&& defaultCommand) {
if (!defaultCommand.get()->HasRequirement(subsystem)) {
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
"Default commands must require their subsystem!");
}
if (defaultCommand.get()->IsFinished()) {
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
"Default commands should not end!");
}
SetDefaultCommandImpl(subsystem, std::move(defaultCommand).Unwrap());
}
Command* CommandScheduler::GetDefaultCommand(const Subsystem* subsystem) const {
auto&& find = m_impl->subsystems.find(subsystem);
if (find != m_impl->subsystems.end()) {