WPILibC++ 2023.4.3-108-ge5452e3
|
A wrapper around std::unique_ptr<Command> so commands have move-only semantics. More...
#include <frc2/command/CommandPtr.h>
Public Member Functions | |
CommandPtr (std::unique_ptr< CommandBase > &&command) | |
template<std::derived_from< Command > T> | |
CommandPtr (T &&command) | |
CommandPtr (CommandPtr &&)=default | |
CommandPtr & | operator= (CommandPtr &&)=default |
CommandPtr | Repeatedly () && |
Decorates this command to run repeatedly, restarting it when it ends, until this command is interrupted. More... | |
CommandPtr | AsProxy () && |
Decorates this command to run "by proxy" by wrapping it in a ProxyCommand. More... | |
CommandPtr | IgnoringDisable (bool doesRunWhenDisabled) && |
Decorates this command to run or stop when disabled. More... | |
CommandPtr | WithInterruptBehavior (Command::InterruptionBehavior interruptBehavior) && |
Decorates this command to have a different interrupt behavior. More... | |
CommandPtr | AndThen (std::function< void()> toRun, std::span< Subsystem *const > requirements={}) && |
Decorates this command with a runnable to run after the command finishes. More... | |
CommandPtr | AndThen (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements) && |
Decorates this command with a runnable to run after the command finishes. More... | |
CommandPtr | AndThen (CommandPtr &&next) && |
Decorates this command with a set of commands to run after it in sequence. More... | |
CommandPtr | BeforeStarting (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements) && |
Decorates this command with a runnable to run before this command starts. More... | |
CommandPtr | BeforeStarting (std::function< void()> toRun, std::span< Subsystem *const > requirements={}) && |
Decorates this command with a runnable to run before this command starts. More... | |
CommandPtr | BeforeStarting (CommandPtr &&before) && |
Decorates this command with another command to run before this command starts. More... | |
CommandPtr | WithTimeout (units::second_t duration) && |
Decorates this command with a timeout. More... | |
CommandPtr | Until (std::function< bool()> condition) && |
Decorates this command with an interrupt condition. More... | |
CommandPtr | OnlyWhile (std::function< bool()> condition) && |
Decorates this command with a run condition. More... | |
CommandPtr | Unless (std::function< bool()> condition) && |
Decorates this command to only run if this condition is not met. More... | |
CommandPtr | OnlyIf (std::function< bool()> condition) && |
Decorates this command to only run if this condition is met. More... | |
CommandPtr | DeadlineWith (CommandPtr &¶llel) && |
Decorates this command with a set of commands to run parallel to it, ending when the calling command ends and interrupting all the others. More... | |
CommandPtr | AlongWith (CommandPtr &¶llel) && |
Decorates this command with a set of commands to run parallel to it, ending when the last command ends. More... | |
CommandPtr | RaceWith (CommandPtr &¶llel) && |
Decorates this command with a set of commands to run parallel to it, ending when the first command ends. More... | |
CommandPtr | FinallyDo (std::function< void(bool)> end) && |
Decorates this command with a lambda to call on interrupt or end, following the command's inherent Command::End(bool) method. More... | |
CommandPtr | HandleInterrupt (std::function< void()> handler) && |
Decorates this command with a lambda to call on interrupt, following the command's inherent Command::End(bool) method. More... | |
CommandPtr | WithName (std::string_view name) && |
Decorates this Command with a name. More... | |
CommandBase * | get () const & |
Get a raw pointer to the held command. More... | |
CommandBase * | get () &&=delete |
std::unique_ptr< CommandBase > | Unwrap () && |
Convert to the underlying unique_ptr. More... | |
void | Schedule () const & |
Schedules this command. More... | |
void | Schedule () &&=delete |
void | Cancel () const & |
Cancels this command. More... | |
void | Cancel () &&=delete |
bool | IsScheduled () const & |
Whether or not the command is currently scheduled. More... | |
void | IsScheduled () &&=delete |
bool | HasRequirement (Subsystem *requirement) const & |
Whether the command requires a given subsystem. More... | |
void | HasRequirement (Subsystem *requirement) &&=delete |
operator bool () const & | |
Check if this CommandPtr object is valid and wasn't moved-from. More... | |
operator bool () &&=delete | |
Static Public Member Functions | |
static std::vector< std::unique_ptr< Command > > | UnwrapVector (std::vector< CommandPtr > &&vec) |
Convert a vector of CommandPtr objects to their underlying unique_ptrs. More... | |
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Commands should only be stored and passed around when held in a CommandPtr instance. For more info, see https://github.com/wpilibsuite/allwpilib/issues/4303.
Various classes in the command-based library accept a std::unique_ptr<Command>, use CommandPtr::Unwrap to convert. CommandPtr::UnwrapVector does the same for vectors.
|
inlineexplicit |
|
inlineexplicit |
|
default |
CommandPtr frc2::CommandPtr::AlongWith | ( | CommandPtr && | parallel | ) | && |
Decorates this command with a set of commands to run parallel to it, ending when the last command ends.
Often more convenient/less-verbose than constructing a new ParallelCommandGroup
explicitly.
parallel | the commands to run in parallel |
CommandPtr frc2::CommandPtr::AndThen | ( | CommandPtr && | next | ) | && |
Decorates this command with a set of commands to run after it in sequence.
Often more convenient/less-verbose than constructing a new SequentialCommandGroup
explicitly.
next | the commands to run next |
CommandPtr frc2::CommandPtr::AndThen | ( | std::function< void()> | toRun, |
std::initializer_list< Subsystem * > | requirements | ||
) | && |
Decorates this command with a runnable to run after the command finishes.
toRun | the Runnable to run |
requirements | the required subsystems |
CommandPtr frc2::CommandPtr::AndThen | ( | std::function< void()> | toRun, |
std::span< Subsystem *const > | requirements = {} |
||
) | && |
Decorates this command with a runnable to run after the command finishes.
toRun | the Runnable to run |
requirements | the required subsystems |
CommandPtr frc2::CommandPtr::AsProxy | ( | ) | && |
Decorates this command to run "by proxy" by wrapping it in a ProxyCommand.
This is useful for "forking off" from command groups when the user does not wish to extend the command's requirements to the entire command group.
CommandPtr frc2::CommandPtr::BeforeStarting | ( | CommandPtr && | before | ) | && |
Decorates this command with another command to run before this command starts.
before | the command to run before this one |
CommandPtr frc2::CommandPtr::BeforeStarting | ( | std::function< void()> | toRun, |
std::initializer_list< Subsystem * > | requirements | ||
) | && |
Decorates this command with a runnable to run before this command starts.
toRun | the Runnable to run |
requirements | the required subsystems |
CommandPtr frc2::CommandPtr::BeforeStarting | ( | std::function< void()> | toRun, |
std::span< Subsystem *const > | requirements = {} |
||
) | && |
Decorates this command with a runnable to run before this command starts.
toRun | the Runnable to run |
requirements | the required subsystems |
|
delete |
void frc2::CommandPtr::Cancel | ( | ) | const & |
Cancels this command.
Will call End(true). Commands will be canceled regardless of interruption behavior.
CommandPtr frc2::CommandPtr::DeadlineWith | ( | CommandPtr && | parallel | ) | && |
Decorates this command with a set of commands to run parallel to it, ending when the calling command ends and interrupting all the others.
Often more convenient/less-verbose than constructing a new ParallelDeadlineGroup
explicitly.
parallel | the commands to run in parallel |
CommandPtr frc2::CommandPtr::FinallyDo | ( | std::function< void(bool)> | end | ) | && |
Decorates this command with a lambda to call on interrupt or end, following the command's inherent Command::End(bool) method.
end | a lambda accepting a boolean parameter specifying whether the command was interrupted |
|
delete |
CommandBase * frc2::CommandPtr::get | ( | ) | const & |
Get a raw pointer to the held command.
CommandPtr frc2::CommandPtr::HandleInterrupt | ( | std::function< void()> | handler | ) | && |
Decorates this command with a lambda to call on interrupt, following the command's inherent Command::End(bool) method.
handler | a lambda to run when the command is interrupted |
|
delete |
bool frc2::CommandPtr::HasRequirement | ( | Subsystem * | requirement | ) | const & |
Whether the command requires a given subsystem.
Named "HasRequirement" rather than "requires" to avoid confusion with Command::Requires(Subsystem) – this may be able to be changed in a few years.
requirement | the subsystem to inquire about |
CommandPtr frc2::CommandPtr::IgnoringDisable | ( | bool | doesRunWhenDisabled | ) | && |
Decorates this command to run or stop when disabled.
doesRunWhenDisabled | true to run when disabled |
|
delete |
bool frc2::CommandPtr::IsScheduled | ( | ) | const & |
Whether or not the command is currently scheduled.
Note that this does not detect whether the command is in a composition, only whether it is directly being run by the scheduler.
CommandPtr frc2::CommandPtr::OnlyIf | ( | std::function< bool()> | condition | ) | && |
Decorates this command to only run if this condition is met.
If the command is already running and the condition changes to false, the command will not stop running. The requirements of this command will be kept for the new conditional command.
condition | the condition that will allow the command to run |
CommandPtr frc2::CommandPtr::OnlyWhile | ( | std::function< bool()> | condition | ) | && |
Decorates this command with a run condition.
If the specified condition becomes false before the command finishes normally, the command will be interrupted and un-scheduled.
condition | the run condition |
|
explicitdelete |
|
explicit |
Check if this CommandPtr object is valid and wasn't moved-from.
|
default |
CommandPtr frc2::CommandPtr::RaceWith | ( | CommandPtr && | parallel | ) | && |
Decorates this command with a set of commands to run parallel to it, ending when the first command ends.
Often more convenient/less-verbose than constructing a new ParallelRaceGroup
explicitly.
parallel | the commands to run in parallel |
CommandPtr frc2::CommandPtr::Repeatedly | ( | ) | && |
Decorates this command to run repeatedly, restarting it when it ends, until this command is interrupted.
The decorated command can still be canceled.
|
delete |
void frc2::CommandPtr::Schedule | ( | ) | const & |
Schedules this command.
CommandPtr frc2::CommandPtr::Unless | ( | std::function< bool()> | condition | ) | && |
Decorates this command to only run if this condition is not met.
If the command is already running and the condition changes to true, the command will not stop running. The requirements of this command will be kept for the new conditional command.
condition | the condition that will prevent the command from running |
CommandPtr frc2::CommandPtr::Until | ( | std::function< bool()> | condition | ) | && |
Decorates this command with an interrupt condition.
If the specified condition becomes true before the command finishes normally, the command will be interrupted and un-scheduled.
condition | the interrupt condition |
std::unique_ptr< CommandBase > frc2::CommandPtr::Unwrap | ( | ) | && |
Convert to the underlying unique_ptr.
|
static |
Convert a vector of CommandPtr objects to their underlying unique_ptrs.
CommandPtr frc2::CommandPtr::WithInterruptBehavior | ( | Command::InterruptionBehavior | interruptBehavior | ) | && |
Decorates this command to have a different interrupt behavior.
interruptBehavior | the desired interrupt behavior |
CommandPtr frc2::CommandPtr::WithName | ( | std::string_view | name | ) | && |
Decorates this Command with a name.
Is an inline function for Command::SetName(std::string_view);
name | name |
CommandPtr frc2::CommandPtr::WithTimeout | ( | units::second_t | duration | ) | && |
Decorates this command with a timeout.
If the specified timeout is exceeded before the command finishes normally, the command will be interrupted and un-scheduled.
duration | the timeout duration |