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:
@@ -41,11 +41,13 @@ void NTCommandSchedulerModel::Update() {
|
||||
}
|
||||
} else if (event.entry == m_commands) {
|
||||
if (event.value && event.value->IsStringArray()) {
|
||||
m_commandsValue = event.value->GetStringArray();
|
||||
auto arr = event.value->GetStringArray();
|
||||
m_commandsValue.assign(arr.begin(), arr.end());
|
||||
}
|
||||
} else if (event.entry == m_ids) {
|
||||
if (event.value && event.value->IsDoubleArray()) {
|
||||
m_idsValue = event.value->GetDoubleArray();
|
||||
auto arr = event.value->GetDoubleArray();
|
||||
m_idsValue.assign(arr.begin(), arr.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
using namespace glass;
|
||||
|
||||
@@ -34,8 +34,8 @@ class NTField2DModel::ObjectModel : public FieldObjectModel {
|
||||
bool Exists() override { return nt::GetEntryType(m_entry) != NT_UNASSIGNED; }
|
||||
bool IsReadOnly() override { return false; }
|
||||
|
||||
wpi::ArrayRef<frc::Pose2d> GetPoses() override { return m_poses; }
|
||||
void SetPoses(wpi::ArrayRef<frc::Pose2d> poses) override;
|
||||
wpi::span<const frc::Pose2d> GetPoses() override { return m_poses; }
|
||||
void SetPoses(wpi::span<const frc::Pose2d> poses) override;
|
||||
void SetPose(size_t i, frc::Pose2d pose) override;
|
||||
void SetPosition(size_t i, frc::Translation2d pos) override;
|
||||
void SetRotation(size_t i, frc::Rotation2d rot) override;
|
||||
@@ -121,8 +121,8 @@ void NTField2DModel::ObjectModel::UpdateNT() {
|
||||
}
|
||||
}
|
||||
|
||||
void NTField2DModel::ObjectModel::SetPoses(wpi::ArrayRef<frc::Pose2d> poses) {
|
||||
m_poses = poses;
|
||||
void NTField2DModel::ObjectModel::SetPoses(wpi::span<const frc::Pose2d> poses) {
|
||||
m_poses.assign(poses.begin(), poses.end());
|
||||
UpdateNT();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ void NTStringChooserModel::SetActive(std::string_view val) {
|
||||
nt::SetEntryValue(m_active, nt::Value::MakeString(val));
|
||||
}
|
||||
|
||||
void NTStringChooserModel::SetOptions(wpi::ArrayRef<std::string> val) {
|
||||
void NTStringChooserModel::SetOptions(wpi::span<const std::string> val) {
|
||||
nt::SetEntryValue(m_options, nt::Value::MakeStringArray(val));
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ void NTStringChooserModel::Update() {
|
||||
if ((event.flags & NT_NOTIFY_DELETE) != 0) {
|
||||
m_optionsValue.clear();
|
||||
} else if (event.value && event.value->IsStringArray()) {
|
||||
m_optionsValue = event.value->GetStringArray();
|
||||
auto arr = event.value->GetStringArray();
|
||||
m_optionsValue.assign(arr.begin(), arr.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,18 @@
|
||||
#include <fmt/format.h>
|
||||
#include <imgui.h>
|
||||
#include <ntcore_cpp.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/SpanExtras.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
|
||||
using namespace glass;
|
||||
|
||||
static std::string BooleanArrayToString(wpi::ArrayRef<int> in) {
|
||||
static std::string BooleanArrayToString(wpi::span<const int> in) {
|
||||
std::string rv;
|
||||
wpi::raw_string_ostream os{rv};
|
||||
os << '[';
|
||||
@@ -47,11 +48,11 @@ static std::string BooleanArrayToString(wpi::ArrayRef<int> in) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
static std::string DoubleArrayToString(wpi::ArrayRef<double> in) {
|
||||
static std::string DoubleArrayToString(wpi::span<const double> in) {
|
||||
return fmt::format("[{:.6f}]", fmt::join(in, ","));
|
||||
}
|
||||
|
||||
static std::string StringArrayToString(wpi::ArrayRef<std::string> in) {
|
||||
static std::string StringArrayToString(wpi::span<const std::string> in) {
|
||||
std::string rv;
|
||||
wpi::raw_string_ostream os{rv};
|
||||
os << '[';
|
||||
@@ -186,7 +187,7 @@ void NetworkTablesModel::Update() {
|
||||
|
||||
// get to leaf
|
||||
auto nodes = &m_root;
|
||||
for (auto part : wpi::ArrayRef(parts.begin(), parts.end()).drop_back()) {
|
||||
for (auto part : wpi::drop_back(wpi::span{parts.begin(), parts.end()})) {
|
||||
auto it =
|
||||
std::find_if(nodes->begin(), nodes->end(),
|
||||
[&](const auto& node) { return node.name == part; });
|
||||
|
||||
Reference in New Issue
Block a user