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:
@@ -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