mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +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:
@@ -51,7 +51,7 @@ void AddressableLED::SetLength(int length) {
|
||||
static_assert(sizeof(AddressableLED::LEDData) == sizeof(HAL_AddressableLEDData),
|
||||
"LED Structs MUST be the same size");
|
||||
|
||||
void AddressableLED::SetData(wpi::ArrayRef<LEDData> ledData) {
|
||||
void AddressableLED::SetData(wpi::span<const LEDData> ledData) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(),
|
||||
&status);
|
||||
|
||||
@@ -260,7 +260,8 @@ void SPI::FreeAuto() {
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::SetAutoTransmitData(wpi::ArrayRef<uint8_t> dataToSend, int zeroSize) {
|
||||
void SPI::SetAutoTransmitData(wpi::span<const uint8_t> dataToSend,
|
||||
int zeroSize) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIAutoTransmitData(m_port, dataToSend.data(), dataToSend.size(),
|
||||
zeroSize, &status);
|
||||
|
||||
@@ -42,7 +42,7 @@ double RobotDriveBase::ApplyDeadband(double value, double deadband) {
|
||||
}
|
||||
}
|
||||
|
||||
void RobotDriveBase::Normalize(wpi::MutableArrayRef<double> wheelSpeeds) {
|
||||
void RobotDriveBase::Normalize(wpi::span<double> wheelSpeeds) {
|
||||
double maxMagnitude = std::abs(wheelSpeeds[0]);
|
||||
for (size_t i = 1; i < wheelSpeeds.size(); i++) {
|
||||
double temp = std::abs(wheelSpeeds[i]);
|
||||
|
||||
@@ -110,17 +110,17 @@ SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
wpi::ArrayRef<bool> defaultValue) {
|
||||
wpi::span<const bool> defaultValue) {
|
||||
return Add(title, nt::Value::MakeBooleanArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
wpi::ArrayRef<double> defaultValue) {
|
||||
wpi::span<const double> defaultValue) {
|
||||
return Add(title, nt::Value::MakeDoubleArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(
|
||||
std::string_view title, wpi::ArrayRef<std::string> defaultValue) {
|
||||
std::string_view title, wpi::span<const std::string> defaultValue) {
|
||||
return Add(title, nt::Value::MakeStringArray(defaultValue));
|
||||
}
|
||||
|
||||
@@ -254,17 +254,17 @@ SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, wpi::ArrayRef<bool> defaultValue) {
|
||||
std::string_view title, wpi::span<const bool> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeBooleanArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, wpi::ArrayRef<double> defaultValue) {
|
||||
std::string_view title, wpi::span<const double> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeDoubleArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, wpi::ArrayRef<std::string> defaultValue) {
|
||||
std::string_view title, wpi::span<const std::string> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeStringArray(defaultValue));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ FieldObject2d& FieldObject2d::operator=(FieldObject2d&& rhs) {
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPose(const Pose2d& pose) {
|
||||
SetPoses(wpi::makeArrayRef(pose));
|
||||
SetPoses({pose});
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPose(units::meter_t x, units::meter_t y,
|
||||
Rotation2d rotation) {
|
||||
SetPoses(wpi::makeArrayRef(Pose2d{x, y, rotation}));
|
||||
SetPoses({{x, y, rotation}});
|
||||
}
|
||||
|
||||
Pose2d FieldObject2d::GetPose() const {
|
||||
@@ -45,14 +45,14 @@ Pose2d FieldObject2d::GetPose() const {
|
||||
return m_poses[0];
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPoses(wpi::ArrayRef<Pose2d> poses) {
|
||||
void FieldObject2d::SetPoses(wpi::span<const Pose2d> poses) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_poses.assign(poses.begin(), poses.end());
|
||||
UpdateEntry();
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPoses(std::initializer_list<Pose2d> poses) {
|
||||
SetPoses(wpi::makeArrayRef(poses.begin(), poses.end()));
|
||||
SetPoses({poses.begin(), poses.end()});
|
||||
}
|
||||
|
||||
void FieldObject2d::SetTrajectory(const Trajectory& trajectory) {
|
||||
@@ -71,7 +71,7 @@ std::vector<Pose2d> FieldObject2d::GetPoses() const {
|
||||
return std::vector<Pose2d>(m_poses.begin(), m_poses.end());
|
||||
}
|
||||
|
||||
wpi::ArrayRef<Pose2d> FieldObject2d::GetPoses(
|
||||
wpi::span<const Pose2d> FieldObject2d::GetPoses(
|
||||
wpi::SmallVectorImpl<Pose2d>& out) const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
UpdateFromEntry();
|
||||
|
||||
@@ -177,7 +177,7 @@ void SendableBuilderImpl::AddStringProperty(
|
||||
|
||||
void SendableBuilderImpl::AddBooleanArrayProperty(
|
||||
std::string_view key, std::function<std::vector<int>()> getter,
|
||||
std::function<void(wpi::ArrayRef<int>)> setter) {
|
||||
std::function<void(wpi::span<const int>)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -203,7 +203,7 @@ void SendableBuilderImpl::AddBooleanArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddDoubleArrayProperty(
|
||||
std::string_view key, std::function<std::vector<double>()> getter,
|
||||
std::function<void(wpi::ArrayRef<double>)> setter) {
|
||||
std::function<void(wpi::span<const double>)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -229,7 +229,7 @@ void SendableBuilderImpl::AddDoubleArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddStringArrayProperty(
|
||||
std::string_view key, std::function<std::vector<std::string>()> getter,
|
||||
std::function<void(wpi::ArrayRef<std::string>)> setter) {
|
||||
std::function<void(wpi::span<const std::string>)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -331,8 +331,8 @@ void SendableBuilderImpl::AddSmallStringProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallBooleanArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::ArrayRef<int>(wpi::SmallVectorImpl<int>& buf)> getter,
|
||||
std::function<void(wpi::ArrayRef<int>)> setter) {
|
||||
std::function<wpi::span<const int>(wpi::SmallVectorImpl<int>& buf)> getter,
|
||||
std::function<void(wpi::span<const int>)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -359,9 +359,9 @@ void SendableBuilderImpl::AddSmallBooleanArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::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) {
|
||||
std::function<void(wpi::span<const double>)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -389,9 +389,9 @@ void SendableBuilderImpl::AddSmallDoubleArrayProperty(
|
||||
void SendableBuilderImpl::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) {
|
||||
std::function<void(wpi::span<const std::string>)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
|
||||
@@ -170,52 +170,52 @@ std::string SmartDashboard::GetString(std::string_view keyName,
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> value) {
|
||||
wpi::span<const int> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetBooleanArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue) {
|
||||
wpi::span<const int> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultBooleanArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::vector<int> SmartDashboard::GetBooleanArray(
|
||||
std::string_view key, wpi::ArrayRef<int> defaultValue) {
|
||||
std::string_view key, wpi::span<const int> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetBooleanArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> value) {
|
||||
wpi::span<const double> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDoubleArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue) {
|
||||
bool SmartDashboard::SetDefaultNumberArray(
|
||||
std::string_view key, wpi::span<const double> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultDoubleArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::vector<double> SmartDashboard::GetNumberArray(
|
||||
std::string_view key, wpi::ArrayRef<double> defaultValue) {
|
||||
std::string_view key, wpi::span<const double> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetDoubleArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutStringArray(std::string_view key,
|
||||
wpi::ArrayRef<std::string> value) {
|
||||
wpi::span<const std::string> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetStringArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultStringArray(
|
||||
std::string_view key, wpi::ArrayRef<std::string> defaultValue) {
|
||||
std::string_view key, wpi::span<const std::string> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultStringArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::vector<std::string> SmartDashboard::GetStringArray(
|
||||
std::string_view key, wpi::ArrayRef<std::string> defaultValue) {
|
||||
std::string_view key, wpi::span<const std::string> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetStringArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user