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

@@ -4,6 +4,8 @@
#include <stdint.h>
#include <cstring>
#include <wpi/MemAlloc.h>
#include <wpi/timestamp.h>
@@ -43,7 +45,7 @@ Value::~Value() {
}
}
std::shared_ptr<Value> Value::MakeBooleanArray(wpi::ArrayRef<bool> value,
std::shared_ptr<Value> Value::MakeBooleanArray(wpi::span<const bool> value,
uint64_t time) {
auto val = std::make_shared<Value>(NT_BOOLEAN_ARRAY, time, private_init());
val->m_val.data.arr_boolean.arr = new int[value.size()];
@@ -52,7 +54,7 @@ std::shared_ptr<Value> Value::MakeBooleanArray(wpi::ArrayRef<bool> value,
return val;
}
std::shared_ptr<Value> Value::MakeBooleanArray(wpi::ArrayRef<int> value,
std::shared_ptr<Value> Value::MakeBooleanArray(wpi::span<const int> value,
uint64_t time) {
auto val = std::make_shared<Value>(NT_BOOLEAN_ARRAY, time, private_init());
val->m_val.data.arr_boolean.arr = new int[value.size()];
@@ -61,7 +63,7 @@ std::shared_ptr<Value> Value::MakeBooleanArray(wpi::ArrayRef<int> value,
return val;
}
std::shared_ptr<Value> Value::MakeDoubleArray(wpi::ArrayRef<double> value,
std::shared_ptr<Value> Value::MakeDoubleArray(wpi::span<const double> value,
uint64_t time) {
auto val = std::make_shared<Value>(NT_DOUBLE_ARRAY, time, private_init());
val->m_val.data.arr_double.arr = new double[value.size()];
@@ -70,10 +72,10 @@ std::shared_ptr<Value> Value::MakeDoubleArray(wpi::ArrayRef<double> value,
return val;
}
std::shared_ptr<Value> Value::MakeStringArray(wpi::ArrayRef<std::string> value,
uint64_t time) {
std::shared_ptr<Value> Value::MakeStringArray(
wpi::span<const std::string> value, uint64_t time) {
auto val = std::make_shared<Value>(NT_STRING_ARRAY, time, private_init());
val->m_string_array = value;
val->m_string_array.assign(value.begin(), value.end());
// point NT_Value to the contents in the vector.
val->m_val.data.arr_string.arr = new NT_String[value.size()];
val->m_val.data.arr_string.size = val->m_string_array.size();
@@ -175,11 +177,11 @@ std::shared_ptr<Value> nt::ConvertFromC(const NT_Value& value) {
case NT_RPC:
return Value::MakeRpc(ConvertFromC(value.data.v_raw));
case NT_BOOLEAN_ARRAY:
return Value::MakeBooleanArray(wpi::ArrayRef<int>(
value.data.arr_boolean.arr, value.data.arr_boolean.size));
return Value::MakeBooleanArray(
wpi::span(value.data.arr_boolean.arr, value.data.arr_boolean.size));
case NT_DOUBLE_ARRAY:
return Value::MakeDoubleArray(wpi::ArrayRef<double>(
value.data.arr_double.arr, value.data.arr_double.size));
return Value::MakeDoubleArray(
wpi::span(value.data.arr_double.arr, value.data.arr_double.size));
case NT_STRING_ARRAY: {
std::vector<std::string> v;
v.reserve(value.data.arr_string.size);