mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
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:
@@ -9,7 +9,7 @@
|
||||
#include <hal/AddressableLEDTypes.h>
|
||||
#include <hal/Types.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "util/Color.h"
|
||||
#include "util/Color8Bit.h"
|
||||
@@ -107,7 +107,7 @@ class AddressableLED {
|
||||
*
|
||||
* @param ledData the buffer to write
|
||||
*/
|
||||
void SetData(wpi::ArrayRef<LEDData> ledData);
|
||||
void SetData(wpi::span<const LEDData> ledData);
|
||||
|
||||
/**
|
||||
* Sets the led output data.
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
#include <hal/SPITypes.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -173,7 +173,7 @@ class SPI {
|
||||
* @param dataToSend data to send (maximum 16 bytes)
|
||||
* @param zeroSize number of zeros to send after the data
|
||||
*/
|
||||
void SetAutoTransmitData(wpi::ArrayRef<uint8_t> dataToSend, int zeroSize);
|
||||
void SetAutoTransmitData(wpi::span<const uint8_t> dataToSend, int zeroSize);
|
||||
|
||||
/**
|
||||
* Start running the automatic SPI transfer engine at a periodic rate.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc/MotorSafety.h"
|
||||
|
||||
@@ -82,7 +82,7 @@ class RobotDriveBase : public MotorSafety {
|
||||
* Normalize all wheel speeds if the magnitude of any wheel is greater than
|
||||
* 1.0.
|
||||
*/
|
||||
static void Normalize(wpi::MutableArrayRef<double> wheelSpeeds);
|
||||
static void Normalize(wpi::span<double> wheelSpeeds);
|
||||
|
||||
double m_deadband = 0.02;
|
||||
double m_maxOutput = 1.0;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableValue.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallSet.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc/shuffleboard/BuiltInLayouts.h"
|
||||
#include "frc/shuffleboard/LayoutType.h"
|
||||
@@ -228,19 +228,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(std::string_view title, wpi::ArrayRef<bool> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
*
|
||||
* @param title the title of the widget
|
||||
* @param defaultValue the default value of the widget
|
||||
* @return a widget to display the sendable data
|
||||
* @throws IllegalArgumentException if a widget already exists in this
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(std::string_view title, wpi::ArrayRef<double> defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, wpi::span<const bool> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -253,7 +241,20 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(std::string_view title,
|
||||
wpi::ArrayRef<std::string> defaultValue);
|
||||
wpi::span<const double> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
*
|
||||
* @param title the title of the widget
|
||||
* @param defaultValue the default value of the widget
|
||||
* @return a widget to display the sendable data
|
||||
* @throws IllegalArgumentException if a widget already exists in this
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(std::string_view title,
|
||||
wpi::span<const std::string> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container. The widget will display the data provided
|
||||
@@ -432,7 +433,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
wpi::ArrayRef<bool> defaultValue);
|
||||
wpi::span<const bool> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display a simple piece of data.
|
||||
@@ -447,7 +448,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
wpi::span<const double> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display a simple piece of data.
|
||||
@@ -462,7 +463,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
wpi::ArrayRef<std::string> defaultValue);
|
||||
wpi::span<const std::string> defaultValue);
|
||||
|
||||
void EnableIfActuator() override;
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <units/length.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc/geometry/Pose2d.h"
|
||||
#include "frc/geometry/Rotation2d.h"
|
||||
@@ -66,7 +66,7 @@ class FieldObject2d {
|
||||
*
|
||||
* @param poses array of 2D poses
|
||||
*/
|
||||
void SetPoses(wpi::ArrayRef<Pose2d> poses);
|
||||
void SetPoses(wpi::span<const Pose2d> poses);
|
||||
|
||||
/**
|
||||
* Set multiple poses from an array of Pose objects.
|
||||
@@ -97,9 +97,9 @@ class FieldObject2d {
|
||||
*
|
||||
* @param obj Object entry
|
||||
* @param out output SmallVector to hold 2D poses
|
||||
* @return ArrayRef referring to output SmallVector
|
||||
* @return span referring to output SmallVector
|
||||
*/
|
||||
wpi::ArrayRef<Pose2d> GetPoses(wpi::SmallVectorImpl<Pose2d>& out) const;
|
||||
wpi::span<const Pose2d> GetPoses(wpi::SmallVectorImpl<Pose2d>& out) const;
|
||||
|
||||
private:
|
||||
void UpdateEntry(bool setDefault = false);
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableValue.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -107,7 +107,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddBooleanArrayProperty(
|
||||
std::string_view key, std::function<std::vector<int>()> getter,
|
||||
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
|
||||
std::function<void(wpi::span<const int>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a double array property.
|
||||
@@ -118,7 +118,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddDoubleArrayProperty(
|
||||
std::string_view key, std::function<std::vector<double>()> getter,
|
||||
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
|
||||
std::function<void(wpi::span<const double>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string array property.
|
||||
@@ -129,7 +129,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddStringArrayProperty(
|
||||
std::string_view key, std::function<std::vector<std::string>()> getter,
|
||||
std::function<void(wpi::ArrayRef<std::string>)> setter) = 0;
|
||||
std::function<void(wpi::span<const std::string>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a raw property.
|
||||
@@ -174,8 +174,9 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallBooleanArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::ArrayRef<int>(wpi::SmallVectorImpl<int>& buf)> getter,
|
||||
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
|
||||
std::function<wpi::span<const int>(wpi::SmallVectorImpl<int>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const int>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a double array property (SmallVector form).
|
||||
@@ -186,9 +187,9 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallDoubleArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::ArrayRef<double>(wpi::SmallVectorImpl<double>& buf)>
|
||||
std::function<wpi::span<const double>(wpi::SmallVectorImpl<double>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
|
||||
std::function<void(wpi::span<const double>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string array property (SmallVector form).
|
||||
@@ -200,9 +201,9 @@ class SendableBuilder {
|
||||
virtual void AddSmallStringArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<
|
||||
wpi::ArrayRef<std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
||||
wpi::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::ArrayRef<std::string>)> setter) = 0;
|
||||
std::function<void(wpi::span<const std::string>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a raw property (SmallVector form).
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableValue.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
|
||||
@@ -104,15 +104,15 @@ class SendableBuilderImpl : public SendableBuilder {
|
||||
|
||||
void AddBooleanArrayProperty(
|
||||
std::string_view key, std::function<std::vector<int>()> getter,
|
||||
std::function<void(wpi::ArrayRef<int>)> setter) override;
|
||||
std::function<void(wpi::span<const int>)> setter) override;
|
||||
|
||||
void AddDoubleArrayProperty(
|
||||
std::string_view key, std::function<std::vector<double>()> getter,
|
||||
std::function<void(wpi::ArrayRef<double>)> setter) override;
|
||||
std::function<void(wpi::span<const double>)> setter) override;
|
||||
|
||||
void AddStringArrayProperty(
|
||||
std::string_view key, std::function<std::vector<std::string>()> getter,
|
||||
std::function<void(wpi::ArrayRef<std::string>)> setter) override;
|
||||
std::function<void(wpi::span<const std::string>)> setter) override;
|
||||
|
||||
void AddRawProperty(std::string_view key, std::function<std::string()> getter,
|
||||
std::function<void(std::string_view)> setter) override;
|
||||
@@ -128,21 +128,22 @@ class SendableBuilderImpl : public SendableBuilder {
|
||||
|
||||
void AddSmallBooleanArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::ArrayRef<int>(wpi::SmallVectorImpl<int>& buf)> getter,
|
||||
std::function<void(wpi::ArrayRef<int>)> setter) override;
|
||||
std::function<wpi::span<const int>(wpi::SmallVectorImpl<int>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const int>)> setter) override;
|
||||
|
||||
void AddSmallDoubleArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::ArrayRef<double>(wpi::SmallVectorImpl<double>& buf)>
|
||||
std::function<wpi::span<const double>(wpi::SmallVectorImpl<double>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::ArrayRef<double>)> setter) override;
|
||||
std::function<void(wpi::span<const double>)> setter) override;
|
||||
|
||||
void AddSmallStringArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<
|
||||
wpi::ArrayRef<std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
||||
wpi::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::ArrayRef<std::string>)> setter) override;
|
||||
std::function<void(wpi::span<const std::string>)> setter) override;
|
||||
|
||||
void AddSmallRawProperty(
|
||||
std::string_view key,
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableValue.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc/smartdashboard/ListenerExecutor.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
@@ -243,7 +244,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
static bool PutBooleanArray(std::string_view key, wpi::ArrayRef<int> value);
|
||||
static bool PutBooleanArray(std::string_view key, wpi::span<const int> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -253,7 +254,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue);
|
||||
wpi::span<const int> defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the boolean array the key maps to.
|
||||
@@ -274,7 +275,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* non-zero value is true.
|
||||
*/
|
||||
static std::vector<int> GetBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue);
|
||||
wpi::span<const int> defaultValue);
|
||||
|
||||
/**
|
||||
* Put a number array in the table.
|
||||
@@ -283,7 +284,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value The value that will be assigned.
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutNumberArray(std::string_view key, wpi::ArrayRef<double> value);
|
||||
static bool PutNumberArray(std::string_view key,
|
||||
wpi::span<const double> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -293,7 +295,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
wpi::span<const double> defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the number array the key maps to.
|
||||
@@ -309,8 +311,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @note This makes a copy of the array. If the overhead of this is a concern,
|
||||
* use GetValue() instead.
|
||||
*/
|
||||
static std::vector<double> GetNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
static std::vector<double> GetNumberArray(
|
||||
std::string_view key, wpi::span<const double> defaultValue);
|
||||
|
||||
/**
|
||||
* Put a string array in the table.
|
||||
@@ -320,7 +322,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutStringArray(std::string_view key,
|
||||
wpi::ArrayRef<std::string> value);
|
||||
wpi::span<const std::string> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -330,7 +332,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultStringArray(std::string_view key,
|
||||
wpi::ArrayRef<std::string> defaultValue);
|
||||
wpi::span<const std::string> defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the string array the key maps to.
|
||||
@@ -347,7 +349,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* use GetValue() instead.
|
||||
*/
|
||||
static std::vector<std::string> GetStringArray(
|
||||
std::string_view key, wpi::ArrayRef<std::string> defaultValue);
|
||||
std::string_view key, wpi::span<const std::string> defaultValue);
|
||||
|
||||
/**
|
||||
* Put a raw value (byte array) in the table.
|
||||
|
||||
Reference in New Issue
Block a user