Use wpi::span instead of wpi::ArrayRef across all libraries (#3414)

- Remove ArrayRef.h
- Add SpanExtras.h for a couple of convenience functions
This commit is contained in:
Peter Johnson
2021-06-06 19:51:14 -07:00
committed by GitHub
parent 2abbbd9e70
commit 64f5413253
167 changed files with 974 additions and 1433 deletions

View File

@@ -10,9 +10,9 @@
#include <string>
#include <units/time.h>
#include <wpi/ArrayRef.h>
#include <wpi/Demangle.h>
#include <wpi/SmallSet.h>
#include <wpi/span.h>
#include "frc2/command/Subsystem.h"
@@ -140,7 +140,7 @@ class Command {
*/
SequentialCommandGroup BeforeStarting(
std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {}) &&;
wpi::span<Subsystem* const> requirements = {}) &&;
/**
* Decorates this command with a runnable to run after the command finishes.
@@ -162,7 +162,7 @@ class Command {
*/
SequentialCommandGroup AndThen(
std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {}) &&;
wpi::span<Subsystem* const> requirements = {}) &&;
/**
* Decorates this command to run perpetually, ignoring its ordinary end

View File

@@ -10,8 +10,8 @@
#include <frc/smartdashboard/Sendable.h>
#include <frc/smartdashboard/SendableHelper.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallSet.h>
#include <wpi/span.h>
#include "frc2/command/Command.h"
@@ -35,7 +35,7 @@ class CommandBase : public Command,
*
* @param requirements the requirements to add
*/
void AddRequirements(wpi::ArrayRef<Subsystem*> requirements);
void AddRequirements(wpi::span<Subsystem* const> requirements);
void AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements);

View File

@@ -8,7 +8,7 @@
#include <memory>
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
@@ -25,10 +25,19 @@ class CommandGroupBase : public CommandBase {
* Requires that the specified command not have been already allocated to a
* CommandGroup. Reports an error if the command is already grouped.
*
* @param commands The command to check
* @param command The command to check
* @return True if all the command is ungrouped.
*/
static bool RequireUngrouped(Command& command);
static bool RequireUngrouped(const Command& command);
/**
* Requires that the specified command not have been already allocated to a
* CommandGroup. Reports an error if the command is already grouped.
*
* @param command The command to check
* @return True if all the command is ungrouped.
*/
static bool RequireUngrouped(const Command* command);
/**
* Requires that the specified commands not have been already allocated to a
@@ -37,7 +46,7 @@ class CommandGroupBase : public CommandBase {
* @param commands The commands to check
* @return True if all the commands are ungrouped.
*/
static bool RequireUngrouped(wpi::ArrayRef<std::unique_ptr<Command>>);
static bool RequireUngrouped(wpi::span<const std::unique_ptr<Command>>);
/**
* Requires that the specified commands not have been already allocated to a
@@ -46,7 +55,7 @@ class CommandGroupBase : public CommandBase {
* @param commands The commands to check
* @return True if all the commands are ungrouped.
*/
static bool RequireUngrouped(std::initializer_list<Command*>);
static bool RequireUngrouped(std::initializer_list<const Command*>);
/**
* Adds the given commands to the command group.

View File

@@ -13,8 +13,8 @@
#include <frc/smartdashboard/Sendable.h>
#include <frc/smartdashboard/SendableHelper.h>
#include <units/time.h>
#include <wpi/ArrayRef.h>
#include <wpi/FunctionExtras.h>
#include <wpi/span.h>
namespace frc2 {
class Command;
@@ -92,7 +92,7 @@ class CommandScheduler final : public frc::Sendable,
* @param interruptible whether the commands should be interruptible
* @param commands the commands to schedule
*/
void Schedule(bool interruptible, wpi::ArrayRef<Command*> commands);
void Schedule(bool interruptible, wpi::span<Command* const> commands);
/**
* Schedules multiple commands for execution. Does nothing if the command is
@@ -112,7 +112,7 @@ class CommandScheduler final : public frc::Sendable,
*
* @param commands the commands to schedule
*/
void Schedule(wpi::ArrayRef<Command*> commands);
void Schedule(wpi::span<Command* const> commands);
/**
* Schedules multiple commands for execution, with interruptible defaulted to
@@ -160,10 +160,10 @@ class CommandScheduler final : public frc::Sendable,
void UnregisterSubsystem(Subsystem* subsystem);
void RegisterSubsystem(std::initializer_list<Subsystem*> subsystems);
void RegisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems);
void RegisterSubsystem(wpi::span<Subsystem* const> subsystems);
void UnregisterSubsystem(std::initializer_list<Subsystem*> subsystems);
void UnregisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems);
void UnregisterSubsystem(wpi::span<Subsystem* const> subsystems);
/**
* Sets the default command for a subsystem. Registers that subsystem if it
@@ -223,7 +223,7 @@ class CommandScheduler final : public frc::Sendable,
*
* @param commands the commands to cancel
*/
void Cancel(wpi::ArrayRef<Command*> commands);
void Cancel(wpi::span<Command* const> commands);
/**
* Cancels commands. The scheduler will only call Command::End()
@@ -261,7 +261,7 @@ class CommandScheduler final : public frc::Sendable,
* @param commands the command to query
* @return whether the command is currently scheduled
*/
bool IsScheduled(wpi::ArrayRef<const Command*> commands) const;
bool IsScheduled(wpi::span<const Command* const> commands) const;
/**
* Whether the given commands are running. Note that this only works on

View File

@@ -7,7 +7,7 @@
#include <functional>
#include <initializer_list>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -52,7 +52,7 @@ class FunctionalCommand : public CommandHelper<CommandBase, FunctionalCommand> {
std::function<void()> onExecute,
std::function<void(bool)> onEnd,
std::function<bool()> isFinished,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
FunctionalCommand(FunctionalCommand&& other) = default;

View File

@@ -7,7 +7,7 @@
#include <functional>
#include <initializer_list>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -38,7 +38,7 @@ class InstantCommand : public CommandHelper<CommandBase, InstantCommand> {
* @param requirements the subsystems required by this command
*/
explicit InstantCommand(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
InstantCommand(InstantCommand&& other) = default;

View File

@@ -21,7 +21,7 @@
#include <units/length.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "CommandBase.h"
#include "CommandHelper.h"
@@ -204,7 +204,7 @@ class MecanumControllerCommand
std::function<void(units::volt_t, units::volt_t, units::volt_t,
units::volt_t)>
output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new MecanumControllerCommand that when executed will follow
@@ -257,7 +257,7 @@ class MecanumControllerCommand
std::function<void(units::volt_t, units::volt_t, units::volt_t,
units::volt_t)>
output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new MecanumControllerCommand that when executed will follow
@@ -373,7 +373,7 @@ class MecanumControllerCommand
units::meters_per_second_t,
units::meters_per_second_t)>
output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new MecanumControllerCommand that when executed will follow
@@ -413,7 +413,7 @@ class MecanumControllerCommand
units::meters_per_second_t,
units::meters_per_second_t)>
output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
void Initialize() override;

View File

@@ -9,7 +9,7 @@
#include <frc/Notifier.h>
#include <units/time.h>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -45,7 +45,7 @@ class NotifierCommand : public CommandHelper<CommandBase, NotifierCommand> {
* @param requirements the subsystems required by this command
*/
NotifierCommand(std::function<void()> toRun, units::second_t period,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
NotifierCommand(NotifierCommand&& other);

View File

@@ -8,6 +8,7 @@
#include <initializer_list>
#include <frc/controller/PIDController.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -53,7 +54,7 @@ class PIDCommand : public CommandHelper<CommandBase, PIDCommand> {
std::function<double()> measurementSource,
std::function<double()> setpointSource,
std::function<void(double)> useOutput,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Creates a new PIDCommand, which controls the given output with a
@@ -83,7 +84,7 @@ class PIDCommand : public CommandHelper<CommandBase, PIDCommand> {
PIDCommand(PIDController controller,
std::function<double()> measurementSource, double setpoint,
std::function<void(double)> useOutput,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
PIDCommand(PIDCommand&& other) = default;

View File

@@ -10,7 +10,7 @@
#include <frc/controller/ProfiledPIDController.h>
#include <units/time.h>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -70,7 +70,7 @@ class ProfiledPIDCommand
std::function<Distance_t()> measurementSource,
std::function<State()> goalSource,
std::function<void(double, State)> useOutput,
wpi::ArrayRef<Subsystem*> requirements = {})
wpi::span<Subsystem* const> requirements = {})
: m_controller{controller},
m_measurement{std::move(measurementSource)},
m_goal{std::move(goalSource)},
@@ -114,7 +114,7 @@ class ProfiledPIDCommand
std::function<Distance_t()> measurementSource,
std::function<Distance_t()> goalSource,
std::function<void(double, State)> useOutput,
wpi::ArrayRef<Subsystem*> requirements = {})
wpi::span<Subsystem* const> requirements = {})
: ProfiledPIDCommand(
controller, measurementSource,
[&goalSource]() {
@@ -153,7 +153,7 @@ class ProfiledPIDCommand
ProfiledPIDCommand(frc::ProfiledPIDController<Distance> controller,
std::function<Distance_t()> measurementSource, State goal,
std::function<void(double, State)> useOutput,
wpi::ArrayRef<Subsystem*> requirements = {})
wpi::span<Subsystem* const> requirements = {})
: ProfiledPIDCommand(
controller, measurementSource, [goal] { return goal; }, useOutput,
requirements) {}
@@ -191,7 +191,7 @@ class ProfiledPIDCommand
std::function<Distance_t()> measurementSource,
Distance_t goal,
std::function<void(double, State)> useOutput,
wpi::ArrayRef<Subsystem*> requirements = {})
wpi::span<Subsystem* const> requirements = {})
: ProfiledPIDCommand(
controller, measurementSource, [goal] { return goal; }, useOutput,
requirements) {}

View File

@@ -4,8 +4,8 @@
#pragma once
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -27,7 +27,9 @@ class ProxyScheduleCommand
*
* @param toSchedule the commands to schedule
*/
explicit ProxyScheduleCommand(wpi::ArrayRef<Command*> toSchedule);
explicit ProxyScheduleCommand(wpi::span<Command* const> toSchedule);
explicit ProxyScheduleCommand(Command* toSchedule);
ProxyScheduleCommand(ProxyScheduleCommand&& other) = default;

View File

@@ -17,7 +17,7 @@
#include <frc/trajectory/Trajectory.h>
#include <units/length.h>
#include <units/voltage.h>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -114,7 +114,7 @@ class RamseteCommand : public CommandHelper<CommandBase, RamseteCommand> {
frc2::PIDController leftController,
frc2::PIDController rightController,
std::function<void(units::volt_t, units::volt_t)> output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new RamseteCommand that, when executed, will follow the
@@ -162,7 +162,7 @@ class RamseteCommand : public CommandHelper<CommandBase, RamseteCommand> {
std::function<void(units::meters_per_second_t,
units::meters_per_second_t)>
output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
void Initialize() override;

View File

@@ -7,7 +7,7 @@
#include <functional>
#include <initializer_list>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -39,7 +39,7 @@ class RunCommand : public CommandHelper<CommandBase, RunCommand> {
* @param requirements the subsystems to require
*/
explicit RunCommand(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
RunCommand(RunCommand&& other) = default;

View File

@@ -4,8 +4,8 @@
#pragma once
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -26,7 +26,9 @@ class ScheduleCommand : public CommandHelper<CommandBase, ScheduleCommand> {
*
* @param toSchedule the commands to schedule
*/
explicit ScheduleCommand(wpi::ArrayRef<Command*> toSchedule);
explicit ScheduleCommand(wpi::span<Command* const> toSchedule);
explicit ScheduleCommand(Command* toSchedule);
ScheduleCommand(ScheduleCommand&& other) = default;

View File

@@ -59,7 +59,7 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
...);
for (auto&& command : foo) {
if (!CommandGroupBase::RequireUngrouped(command.second)) {
if (!CommandGroupBase::RequireUngrouped(*command.second)) {
return;
}
}
@@ -76,7 +76,7 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
std::vector<std::pair<Key, std::unique_ptr<Command>>>&& commands)
: m_selector{std::move(selector)} {
for (auto&& command : commands) {
if (!CommandGroupBase::RequireUngrouped(command.second)) {
if (!CommandGroupBase::RequireUngrouped(*command.second)) {
return;
}
}

View File

@@ -15,8 +15,6 @@
#include <utility>
#include <vector>
#include <wpi/ArrayRef.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandHelper.h"

View File

@@ -4,12 +4,12 @@
#pragma once
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/span.h>
namespace frc2 {
template <typename T>
void SetInsert(wpi::SmallVectorImpl<T*>& vector, wpi::ArrayRef<T*> toAdd) {
void SetInsert(wpi::SmallVectorImpl<T*>& vector, wpi::span<T* const> toAdd) {
for (auto addCommand : toAdd) {
bool exists = false;
for (auto existingCommand : vector) {

View File

@@ -7,7 +7,7 @@
#include <functional>
#include <initializer_list>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -42,7 +42,7 @@ class StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
* @param requirements the subsystems required by this command
*/
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
StartEndCommand(StartEndCommand&& other) = default;

View File

@@ -19,7 +19,7 @@
#include <units/length.h>
#include <units/time.h>
#include <units/voltage.h>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "CommandBase.h"
#include "CommandHelper.h"
@@ -167,7 +167,7 @@ class SwerveControllerCommand
std::function<frc::Rotation2d()> desiredRotation,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)>
output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new SwerveControllerCommand that when executed will follow the
@@ -205,7 +205,7 @@ class SwerveControllerCommand
frc::ProfiledPIDController<units::radians> thetaController,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)>
output,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
void Initialize() override;

View File

@@ -56,7 +56,7 @@ SwerveControllerCommand<NumModules>::SwerveControllerCommand(
frc::ProfiledPIDController<units::radians> thetaController,
std::function<frc::Rotation2d()> desiredRotation,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
wpi::ArrayRef<Subsystem*> requirements)
wpi::span<Subsystem* const> requirements)
: m_trajectory(std::move(trajectory)),
m_pose(std::move(pose)),
m_kinematics(kinematics),
@@ -73,7 +73,7 @@ SwerveControllerCommand<NumModules>::SwerveControllerCommand(
frc2::PIDController xController, frc2::PIDController yController,
frc::ProfiledPIDController<units::radians> thetaController,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
wpi::ArrayRef<Subsystem*> requirements)
wpi::span<Subsystem* const> requirements)
: m_trajectory(std::move(trajectory)),
m_pose(std::move(pose)),
m_kinematics(kinematics),

View File

@@ -9,7 +9,7 @@
#include <frc/Timer.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -54,7 +54,7 @@ class TrapezoidProfileCommand
*/
TrapezoidProfileCommand(frc::TrapezoidProfile<Distance> profile,
std::function<void(State)> output,
wpi::ArrayRef<Subsystem*> requirements = {})
wpi::span<Subsystem* const> requirements = {})
: m_profile(profile), m_output(output) {
this->AddRequirements(requirements);
}

View File

@@ -8,7 +8,7 @@
#include <initializer_list>
#include <utility>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "Trigger.h"
@@ -79,7 +79,7 @@ class Button : public Trigger {
* @param requirements the required subsystems.
*/
Button WhenPressed(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started repeatedly while the button is pressed, and
@@ -125,7 +125,7 @@ class Button : public Trigger {
* @param requirements the required subsystems.
*/
Button WhileHeld(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started when the button is pressed, and canceled
@@ -199,7 +199,7 @@ class Button : public Trigger {
* @param requirements the required subsystems.
*/
Button WhenReleased(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to start when the button is pressed, and be canceled when

View File

@@ -9,7 +9,7 @@
#include <memory>
#include <utility>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "frc2/command/Command.h"
#include "frc2/command/CommandScheduler.h"
@@ -101,7 +101,7 @@ class Trigger {
* @paaram requirements the required subsystems.
*/
Trigger WhenActive(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started repeatedly while the trigger is active, and
@@ -161,7 +161,7 @@ class Trigger {
* @param requirements the required subsystems.
*/
Trigger WhileActiveContinous(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started when the trigger becomes active, and
@@ -261,7 +261,7 @@ class Trigger {
* @param requirements the required subsystems.
*/
Trigger WhenInactive(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {});
wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to start when the trigger becomes active, and be canceled