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

@@ -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();

View File

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

View File

@@ -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);
}