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

@@ -7,6 +7,7 @@
#include <algorithm>
#include <iterator>
#include <wpi/SmallVector.h>
#include <wpi/StringExtras.h>
#include <wpi/TCPAcceptor.h>
#include <wpi/TCPConnector.h>
@@ -37,7 +38,7 @@ void Dispatcher::SetServer(const char* server_name, unsigned int port) {
}
void Dispatcher::SetServer(
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers) {
wpi::span<const std::pair<std::string_view, unsigned int>> servers) {
wpi::SmallVector<std::pair<std::string, int>, 16> servers_copy;
for (const auto& server : servers) {
servers_copy.emplace_back(std::string{wpi::trim(server.first)},
@@ -512,7 +513,7 @@ void DispatcherBase::ClientThreadMain() {
bool DispatcherBase::ClientHandshake(
NetworkConnection& conn, std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs) {
std::function<void(wpi::span<std::shared_ptr<Message>>)> send_msgs) {
// get identity
std::string self_id;
{
@@ -522,10 +523,11 @@ bool DispatcherBase::ClientHandshake(
// send client hello
DEBUG0("{}", "client: sending hello");
send_msgs(Message::ClientHello(self_id));
auto msg = Message::ClientHello(self_id);
send_msgs(wpi::span(&msg, 1));
// wait for response
auto msg = get_msg();
msg = get_msg();
if (!msg) {
// disconnected, retry
DEBUG0("{}", "client: server disconnected before first response");
@@ -604,7 +606,7 @@ bool DispatcherBase::ClientHandshake(
bool DispatcherBase::ServerHandshake(
NetworkConnection& conn, std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs) {
std::function<void(wpi::span<std::shared_ptr<Message>>)> send_msgs) {
// Wait for the client to send us a hello.
auto msg = get_msg();
if (!msg) {
@@ -620,7 +622,8 @@ bool DispatcherBase::ServerHandshake(
unsigned int proto_rev = msg->id();
if (proto_rev > 0x0300) {
DEBUG0("{}", "server: client requested proto > 0x0300");
send_msgs(Message::ProtoUnsup());
auto toSend = Message::ProtoUnsup();
send_msgs(wpi::span(&toSend, 1));
return false;
}

View File

@@ -16,6 +16,7 @@
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include <wpi/span.h>
#include "IDispatcher.h"
#include "INetworkConnection.h"
@@ -77,11 +78,11 @@ class DispatcherBase : public IDispatcher {
bool ClientHandshake(
NetworkConnection& conn,
std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
std::function<void(wpi::span<std::shared_ptr<Message>>)> send_msgs);
bool ServerHandshake(
NetworkConnection& conn,
std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
std::function<void(wpi::span<std::shared_ptr<Message>>)> send_msgs);
void ClientReconnect(unsigned int proto_rev = 0x0300);
@@ -136,7 +137,7 @@ class Dispatcher : public DispatcherBase {
void SetServer(const char* server_name, unsigned int port);
void SetServer(
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
wpi::span<const std::pair<std::string_view, unsigned int>> servers);
void SetServerTeam(unsigned int team, unsigned int port);
void SetServerOverride(const char* server_name, unsigned int port);

View File

@@ -10,7 +10,7 @@
#include <string_view>
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "Message.h"
#include "ntcore_cpp.h"
@@ -45,7 +45,7 @@ class IStorage {
INetworkConnection& conn,
std::vector<std::shared_ptr<Message>>* msgs) = 0;
virtual void ApplyInitialAssignments(
INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
INetworkConnection& conn, wpi::span<std::shared_ptr<Message>> msgs,
bool new_server, std::vector<std::shared_ptr<Message>>* out_msgs) = 0;
// Filename-based save/load functions. Used both by periodic saves and

View File

@@ -162,8 +162,9 @@ void NetworkConnection::ReadThreadMain() {
}
return msg;
},
[&](wpi::ArrayRef<std::shared_ptr<Message>> msgs) {
m_outgoing.emplace(msgs);
[&](auto msgs) {
m_outgoing.emplace(std::vector<std::shared_ptr<Message>>(
msgs.begin(), msgs.end()));
})) {
set_state(kDead);
m_active = false;

View File

@@ -19,6 +19,7 @@
#include <wpi/ConcurrentQueue.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include <wpi/span.h>
#include "INetworkConnection.h"
#include "Message.h"
@@ -38,7 +39,7 @@ class NetworkConnection : public INetworkConnection {
typedef std::function<bool(
NetworkConnection& conn,
std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs)>
std::function<void(wpi::span<std::shared_ptr<Message>>)> send_msgs)>
HandshakeFunc;
using ProcessIncomingFunc =
std::function<void(std::shared_ptr<Message>, NetworkConnection*)>;

View File

@@ -410,7 +410,7 @@ void Storage::GetInitialAssignments(
}
void Storage::ApplyInitialAssignments(
INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
INetworkConnection& conn, wpi::span<std::shared_ptr<Message>> msgs,
bool /*new_server*/, std::vector<std::shared_ptr<Message>>* out_msgs) {
std::unique_lock lock(m_mutex);
if (m_server) {

View File

@@ -21,6 +21,7 @@
#include <wpi/StringMap.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include <wpi/span.h>
#include "IStorage.h"
#include "Message.h"
@@ -67,7 +68,7 @@ class Storage : public IStorage {
INetworkConnection& conn,
std::vector<std::shared_ptr<Message>>* msgs) override;
void ApplyInitialAssignments(
INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
INetworkConnection& conn, wpi::span<std::shared_ptr<Message>> msgs,
bool new_server,
std::vector<std::shared_ptr<Message>>* out_msgs) override;

View File

@@ -25,12 +25,12 @@ class SavePersistentImpl {
explicit SavePersistentImpl(wpi::raw_ostream& os) : m_os(os) {}
void Save(wpi::ArrayRef<Entry> entries);
void Save(wpi::span<const Entry> entries);
private:
void WriteString(std::string_view str);
void WriteHeader();
void WriteEntries(wpi::ArrayRef<Entry> entries);
void WriteEntries(wpi::span<const Entry> entries);
void WriteEntry(std::string_view name, const Value& value);
bool WriteType(NT_Type type);
void WriteValue(const Value& value);
@@ -72,7 +72,7 @@ void SavePersistentImpl::WriteString(std::string_view str) {
m_os << '"';
}
void SavePersistentImpl::Save(wpi::ArrayRef<Entry> entries) {
void SavePersistentImpl::Save(wpi::span<const Entry> entries) {
WriteHeader();
WriteEntries(entries);
}
@@ -81,7 +81,7 @@ void SavePersistentImpl::WriteHeader() {
m_os << "[NetworkTables Storage 3.0]\n";
}
void SavePersistentImpl::WriteEntries(wpi::ArrayRef<Entry> entries) {
void SavePersistentImpl::WriteEntries(wpi::span<const Entry> entries) {
for (auto& i : entries) {
if (!i.second) {
continue;

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

View File

@@ -139,7 +139,7 @@ std::shared_ptr<nt::Value> FromJavaBooleanArray(JNIEnv* env, jbooleanArray jarr,
if (!ref) {
return nullptr;
}
wpi::ArrayRef<jboolean> elements{ref};
wpi::span<const jboolean> elements{ref};
size_t len = elements.size();
std::vector<int> arr;
arr.reserve(len);
@@ -306,8 +306,9 @@ static jobject MakeJObject(JNIEnv* env, jobject inst,
static_cast<jint>(answer.call), name.obj(), params.obj(), conn.obj());
}
static jobjectArray MakeJObject(JNIEnv* env, jobject inst,
wpi::ArrayRef<nt::ConnectionNotification> arr) {
static jobjectArray MakeJObject(
JNIEnv* env, jobject inst,
wpi::span<const nt::ConnectionNotification> arr) {
jobjectArray jarr =
env->NewObjectArray(arr.size(), connectionNotificationCls, nullptr);
if (!jarr) {
@@ -321,7 +322,7 @@ static jobjectArray MakeJObject(JNIEnv* env, jobject inst,
}
static jobjectArray MakeJObject(JNIEnv* env, jobject inst,
wpi::ArrayRef<nt::EntryNotification> arr) {
wpi::span<const nt::EntryNotification> arr) {
jobjectArray jarr =
env->NewObjectArray(arr.size(), entryNotificationCls, nullptr);
if (!jarr) {
@@ -335,7 +336,7 @@ static jobjectArray MakeJObject(JNIEnv* env, jobject inst,
}
static jobjectArray MakeJObject(JNIEnv* env, jobject inst,
wpi::ArrayRef<nt::LogMessage> arr) {
wpi::span<const nt::LogMessage> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), logMessageCls, nullptr);
if (!jarr) {
return nullptr;
@@ -348,7 +349,7 @@ static jobjectArray MakeJObject(JNIEnv* env, jobject inst,
}
static jobjectArray MakeJObject(JNIEnv* env, jobject inst,
wpi::ArrayRef<nt::RpcAnswer> arr) {
wpi::span<const nt::RpcAnswer> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), rpcAnswerCls, nullptr);
if (!jarr) {
return nullptr;

View File

@@ -288,47 +288,47 @@ bool NetworkTable::GetBoolean(std::string_view key, bool defaultValue) const {
}
bool NetworkTable::PutBooleanArray(std::string_view key,
wpi::ArrayRef<int> value) {
wpi::span<const int> value) {
return GetEntry(key).SetBooleanArray(value);
}
bool NetworkTable::SetDefaultBooleanArray(std::string_view key,
wpi::ArrayRef<int> defaultValue) {
wpi::span<const int> defaultValue) {
return GetEntry(key).SetDefaultBooleanArray(defaultValue);
}
std::vector<int> NetworkTable::GetBooleanArray(
std::string_view key, wpi::ArrayRef<int> defaultValue) const {
std::string_view key, wpi::span<const int> defaultValue) const {
return GetEntry(key).GetBooleanArray(defaultValue);
}
bool NetworkTable::PutNumberArray(std::string_view key,
wpi::ArrayRef<double> value) {
wpi::span<const double> value) {
return GetEntry(key).SetDoubleArray(value);
}
bool NetworkTable::SetDefaultNumberArray(std::string_view key,
wpi::ArrayRef<double> defaultValue) {
wpi::span<const double> defaultValue) {
return GetEntry(key).SetDefaultDoubleArray(defaultValue);
}
std::vector<double> NetworkTable::GetNumberArray(
std::string_view key, wpi::ArrayRef<double> defaultValue) const {
std::string_view key, wpi::span<const double> defaultValue) const {
return GetEntry(key).GetDoubleArray(defaultValue);
}
bool NetworkTable::PutStringArray(std::string_view key,
wpi::ArrayRef<std::string> value) {
wpi::span<const std::string> value) {
return GetEntry(key).SetStringArray(value);
}
bool NetworkTable::SetDefaultStringArray(
std::string_view key, wpi::ArrayRef<std::string> defaultValue) {
std::string_view key, wpi::span<const std::string> defaultValue) {
return GetEntry(key).SetDefaultStringArray(defaultValue);
}
std::vector<std::string> NetworkTable::GetStringArray(
std::string_view key, wpi::ArrayRef<std::string> defaultValue) const {
std::string_view key, wpi::span<const std::string> defaultValue) const {
return GetEntry(key).GetStringArray(defaultValue);
}

View File

@@ -23,8 +23,8 @@ std::shared_ptr<NetworkTable> NetworkTableInstance::GetTable(
}
}
void NetworkTableInstance::StartClient(wpi::ArrayRef<std::string_view> servers,
unsigned int port) {
void NetworkTableInstance::StartClient(
wpi::span<const std::string_view> servers, unsigned int port) {
wpi::SmallVector<std::pair<std::string_view, unsigned int>, 8> server_ports;
for (const auto& server : servers) {
server_ports.emplace_back(std::make_pair(server, port));
@@ -32,7 +32,7 @@ void NetworkTableInstance::StartClient(wpi::ArrayRef<std::string_view> servers,
StartClient(server_ports);
}
void NetworkTableInstance::SetServer(wpi::ArrayRef<std::string_view> servers,
void NetworkTableInstance::SetServer(wpi::span<const std::string_view> servers,
unsigned int port) {
wpi::SmallVector<std::pair<std::string_view, unsigned int>, 8> server_ports;
for (const auto& server : servers) {

View File

@@ -6,6 +6,7 @@
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <string_view>
#include <wpi/MemAlloc.h>
@@ -550,8 +551,7 @@ char* NT_PackRpcValues(const NT_Value** values, size_t values_len,
NT_Value** NT_UnpackRpcValues(const char* packed, size_t packed_len,
const NT_Type* types, size_t types_len) {
auto values_v = nt::UnpackRpcValues({packed, packed_len},
wpi::ArrayRef<NT_Type>(types, types_len));
auto values_v = nt::UnpackRpcValues({packed, packed_len}, {types, types_len});
if (values_v.size() == 0) {
return nullptr;
}
@@ -972,24 +972,22 @@ NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, uint64_t time,
const NT_Bool* arr, size_t size,
NT_Bool force) {
if (force != 0) {
nt::SetEntryTypeValue(
entry, Value::MakeBooleanArray(wpi::makeArrayRef(arr, size), time));
nt::SetEntryTypeValue(entry,
Value::MakeBooleanArray(wpi::span(arr, size), time));
return 1;
} else {
return nt::SetEntryValue(
entry, Value::MakeBooleanArray(wpi::makeArrayRef(arr, size), time));
entry, Value::MakeBooleanArray(wpi::span(arr, size), time));
}
}
NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, uint64_t time, const double* arr,
size_t size, NT_Bool force) {
if (force != 0) {
nt::SetEntryTypeValue(
entry, Value::MakeDoubleArray(wpi::makeArrayRef(arr, size), time));
nt::SetEntryTypeValue(entry, Value::MakeDoubleArray({arr, size}, time));
return 1;
} else {
return nt::SetEntryValue(
entry, Value::MakeDoubleArray(wpi::makeArrayRef(arr, size), time));
return nt::SetEntryValue(entry, Value::MakeDoubleArray({arr, size}, time));
}
}
@@ -1138,16 +1136,15 @@ NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, uint64_t time,
const NT_Bool* default_value,
size_t default_size) {
return nt::SetDefaultEntryValue(
entry, Value::MakeBooleanArray(
wpi::makeArrayRef(default_value, default_size), time));
entry,
Value::MakeBooleanArray(wpi::span(default_value, default_size), time));
}
NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, uint64_t time,
const double* default_value,
size_t default_size) {
return nt::SetDefaultEntryValue(
entry, Value::MakeDoubleArray(
wpi::makeArrayRef(default_value, default_size), time));
entry, Value::MakeDoubleArray({default_value, default_size}, time));
}
NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, uint64_t time,

View File

@@ -792,7 +792,7 @@ bool UnpackRpcDefinition(std::string_view packed, RpcDefinition* def) {
return true;
}
std::string PackRpcValues(wpi::ArrayRef<std::shared_ptr<Value>> values) {
std::string PackRpcValues(wpi::span<const std::shared_ptr<Value>> values) {
WireEncoder enc(0x0300);
for (auto& value : values) {
enc.WriteValue(*value);
@@ -801,7 +801,7 @@ std::string PackRpcValues(wpi::ArrayRef<std::shared_ptr<Value>> values) {
}
std::vector<std::shared_ptr<Value>> UnpackRpcValues(
std::string_view packed, wpi::ArrayRef<NT_Type> types) {
std::string_view packed, wpi::span<const NT_Type> types) {
wpi::raw_mem_istream is(packed.data(), packed.size());
wpi::Logger logger;
WireDecoder dec(is, 0x0300, logger);
@@ -900,7 +900,7 @@ void StartClient(NT_Inst inst, const char* server_name, unsigned int port) {
void StartClient(
NT_Inst inst,
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers) {
wpi::span<const std::pair<std::string_view, unsigned int>> servers) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
return;
@@ -940,7 +940,7 @@ void SetServer(NT_Inst inst, const char* server_name, unsigned int port) {
void SetServer(
NT_Inst inst,
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers) {
wpi::span<const std::pair<std::string_view, unsigned int>> servers) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
return;

View File

@@ -4,6 +4,8 @@
#include "ntcore_test.h"
#include <cstring>
#include <wpi/MemAlloc.h>
#include "Value_internal.h"

View File

@@ -12,9 +12,9 @@
#include <utility>
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/StringMap.h>
#include <wpi/mutex.h>
#include <wpi/span.h>
#include "networktables/NetworkTableEntry.h"
#include "networktables/TableEntryListener.h"
@@ -360,7 +360,7 @@ class NetworkTable final {
* std::vector<bool> is special-cased in C++. 0 is false, any
* non-zero value is true.
*/
bool PutBooleanArray(std::string_view key, wpi::ArrayRef<int> value);
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.
@@ -370,7 +370,7 @@ class NetworkTable final {
* @return False if the table key exists with a different type
*/
bool SetDefaultBooleanArray(std::string_view key,
wpi::ArrayRef<int> defaultValue);
wpi::span<const int> defaultValue);
/**
* Returns the boolean array the key maps to. If the key does not exist or is
@@ -389,7 +389,7 @@ class NetworkTable final {
* non-zero value is true.
*/
std::vector<int> GetBooleanArray(std::string_view key,
wpi::ArrayRef<int> defaultValue) const;
wpi::span<const int> defaultValue) const;
/**
* Put a number array in the table
@@ -398,7 +398,7 @@ class NetworkTable final {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutNumberArray(std::string_view key, wpi::ArrayRef<double> value);
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.
@@ -408,7 +408,7 @@ class NetworkTable final {
* @returns False if the table key exists with a different type
*/
bool SetDefaultNumberArray(std::string_view key,
wpi::ArrayRef<double> defaultValue);
wpi::span<const double> defaultValue);
/**
* Returns the number array the key maps to. If the key does not exist or is
@@ -422,8 +422,8 @@ class NetworkTable final {
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<double> GetNumberArray(std::string_view key,
wpi::ArrayRef<double> defaultValue) const;
std::vector<double> GetNumberArray(
std::string_view key, wpi::span<const double> defaultValue) const;
/**
* Put a string array in the table
@@ -432,7 +432,7 @@ class NetworkTable final {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutStringArray(std::string_view key, wpi::ArrayRef<std::string> value);
bool PutStringArray(std::string_view key, wpi::span<const std::string> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -442,7 +442,7 @@ class NetworkTable final {
* @returns False if the table key exists with a different type
*/
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. If the key does not exist or is
@@ -457,7 +457,7 @@ class NetworkTable final {
* concern, use GetValue() instead.
*/
std::vector<std::string> GetStringArray(
std::string_view key, wpi::ArrayRef<std::string> defaultValue) const;
std::string_view key, wpi::span<const std::string> defaultValue) const;
/**
* Put a raw value (byte array) in the table

View File

@@ -13,6 +13,8 @@
#include <string_view>
#include <vector>
#include <wpi/span.h>
#include "networktables/NetworkTableType.h"
#include "networktables/NetworkTableValue.h"
#include "networktables/RpcCall.h"
@@ -166,7 +168,7 @@ class NetworkTableEntry final {
* because std::vector<bool> is special-cased in C++. 0 is false, any
* non-zero value is true.
*/
std::vector<int> GetBooleanArray(wpi::ArrayRef<int> defaultValue) const;
std::vector<int> GetBooleanArray(wpi::span<const int> defaultValue) const;
/**
* Gets the entry's value as a boolean array. If the entry does not exist
@@ -195,7 +197,8 @@ class NetworkTableEntry final {
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<double> GetDoubleArray(wpi::ArrayRef<double> defaultValue) const;
std::vector<double> GetDoubleArray(
wpi::span<const double> defaultValue) const;
/**
* Gets the entry's value as a double array. If the entry does not exist
@@ -221,7 +224,7 @@ class NetworkTableEntry final {
* concern, use GetValue() instead.
*/
std::vector<std::string> GetStringArray(
wpi::ArrayRef<std::string> defaultValue) const;
wpi::span<const std::string> defaultValue) const;
/**
* Gets the entry's value as a string array. If the entry does not exist
@@ -282,7 +285,7 @@ class NetworkTableEntry final {
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultBooleanArray(wpi::ArrayRef<int> defaultValue);
bool SetDefaultBooleanArray(wpi::span<const int> defaultValue);
/**
* Sets the entry's value if it does not exist.
@@ -298,7 +301,7 @@ class NetworkTableEntry final {
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultDoubleArray(wpi::ArrayRef<double> defaultValue);
bool SetDefaultDoubleArray(wpi::span<const double> defaultValue);
/**
* Sets the entry's value if it does not exist.
@@ -314,7 +317,7 @@ class NetworkTableEntry final {
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultStringArray(wpi::ArrayRef<std::string> defaultValue);
bool SetDefaultStringArray(wpi::span<const std::string> defaultValue);
/**
* Sets the entry's value if it does not exist.
@@ -370,7 +373,7 @@ class NetworkTableEntry final {
* @param value the value to set
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(wpi::ArrayRef<bool> value);
bool SetBooleanArray(wpi::span<const bool> value);
/**
* Sets the entry's value.
@@ -386,7 +389,7 @@ class NetworkTableEntry final {
* @param value the value to set
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(wpi::ArrayRef<int> value);
bool SetBooleanArray(wpi::span<const int> value);
/**
* Sets the entry's value.
@@ -402,7 +405,7 @@ class NetworkTableEntry final {
* @param value the value to set
* @return False if the entry exists with a different type
*/
bool SetDoubleArray(wpi::ArrayRef<double> value);
bool SetDoubleArray(wpi::span<const double> value);
/**
* Sets the entry's value.
@@ -418,7 +421,7 @@ class NetworkTableEntry final {
* @param value the value to set
* @return False if the entry exists with a different type
*/
bool SetStringArray(wpi::ArrayRef<std::string> value);
bool SetStringArray(wpi::span<const std::string> value);
/**
* Sets the entry's value.
@@ -474,7 +477,7 @@ class NetworkTableEntry final {
*
* @param value the value to set
*/
void ForceSetBooleanArray(wpi::ArrayRef<bool> value);
void ForceSetBooleanArray(wpi::span<const bool> value);
/**
* Sets the entry's value. If the value is of different type, the type is
@@ -490,7 +493,7 @@ class NetworkTableEntry final {
*
* @param value the value to set
*/
void ForceSetBooleanArray(wpi::ArrayRef<int> value);
void ForceSetBooleanArray(wpi::span<const int> value);
/**
* Sets the entry's value. If the value is of different type, the type is
@@ -506,7 +509,7 @@ class NetworkTableEntry final {
*
* @param value the value to set
*/
void ForceSetDoubleArray(wpi::ArrayRef<double> value);
void ForceSetDoubleArray(wpi::span<const double> value);
/**
* Sets the entry's value. If the value is of different type, the type is
@@ -522,7 +525,7 @@ class NetworkTableEntry final {
*
* @param value the value to set
*/
void ForceSetStringArray(wpi::ArrayRef<std::string> value);
void ForceSetStringArray(wpi::span<const std::string> value);
/**
* Sets the entry's value. If the value is of different type, the type is

View File

@@ -86,48 +86,48 @@ inline std::string NetworkTableEntry::GetRaw(
}
inline std::vector<int> NetworkTableEntry::GetBooleanArray(
wpi::ArrayRef<int> defaultValue) const {
wpi::span<const int> defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_BOOLEAN_ARRAY) {
return defaultValue;
return {defaultValue.begin(), defaultValue.end()};
}
return value->GetBooleanArray();
auto arr = value->GetBooleanArray();
return {arr.begin(), arr.end()};
}
inline std::vector<int> NetworkTableEntry::GetBooleanArray(
std::initializer_list<int> defaultValue) const {
return GetBooleanArray(
wpi::makeArrayRef(defaultValue.begin(), defaultValue.end()));
return GetBooleanArray({defaultValue.begin(), defaultValue.end()});
}
inline std::vector<double> NetworkTableEntry::GetDoubleArray(
wpi::ArrayRef<double> defaultValue) const {
wpi::span<const double> defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_DOUBLE_ARRAY) {
return defaultValue;
return {defaultValue.begin(), defaultValue.end()};
}
return value->GetDoubleArray();
auto arr = value->GetDoubleArray();
return {arr.begin(), arr.end()};
}
inline std::vector<double> NetworkTableEntry::GetDoubleArray(
std::initializer_list<double> defaultValue) const {
return GetDoubleArray(
wpi::makeArrayRef(defaultValue.begin(), defaultValue.end()));
return GetDoubleArray({defaultValue.begin(), defaultValue.end()});
}
inline std::vector<std::string> NetworkTableEntry::GetStringArray(
wpi::ArrayRef<std::string> defaultValue) const {
wpi::span<const std::string> defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_STRING_ARRAY) {
return defaultValue;
return {defaultValue.begin(), defaultValue.end()};
}
return value->GetStringArray();
auto arr = value->GetStringArray();
return {arr.begin(), arr.end()};
}
inline std::vector<std::string> NetworkTableEntry::GetStringArray(
std::initializer_list<std::string> defaultValue) const {
return GetStringArray(
wpi::makeArrayRef(defaultValue.begin(), defaultValue.end()));
return GetStringArray({defaultValue.begin(), defaultValue.end()});
}
inline bool NetworkTableEntry::SetDefaultValue(std::shared_ptr<Value> value) {
@@ -151,7 +151,7 @@ inline bool NetworkTableEntry::SetDefaultRaw(std::string_view defaultValue) {
}
inline bool NetworkTableEntry::SetDefaultBooleanArray(
wpi::ArrayRef<int> defaultValue) {
wpi::span<const int> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeBooleanArray(defaultValue));
}
@@ -161,7 +161,7 @@ inline bool NetworkTableEntry::SetDefaultBooleanArray(
}
inline bool NetworkTableEntry::SetDefaultDoubleArray(
wpi::ArrayRef<double> defaultValue) {
wpi::span<const double> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeDoubleArray(defaultValue));
}
@@ -171,7 +171,7 @@ inline bool NetworkTableEntry::SetDefaultDoubleArray(
}
inline bool NetworkTableEntry::SetDefaultStringArray(
wpi::ArrayRef<std::string> defaultValue) {
wpi::span<const std::string> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeStringArray(defaultValue));
}
@@ -200,7 +200,7 @@ inline bool NetworkTableEntry::SetRaw(std::string_view value) {
return SetEntryValue(m_handle, Value::MakeRaw(value));
}
inline bool NetworkTableEntry::SetBooleanArray(wpi::ArrayRef<bool> value) {
inline bool NetworkTableEntry::SetBooleanArray(wpi::span<const bool> value) {
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
}
@@ -209,7 +209,7 @@ inline bool NetworkTableEntry::SetBooleanArray(
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
}
inline bool NetworkTableEntry::SetBooleanArray(wpi::ArrayRef<int> value) {
inline bool NetworkTableEntry::SetBooleanArray(wpi::span<const int> value) {
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
}
@@ -218,7 +218,7 @@ inline bool NetworkTableEntry::SetBooleanArray(
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
}
inline bool NetworkTableEntry::SetDoubleArray(wpi::ArrayRef<double> value) {
inline bool NetworkTableEntry::SetDoubleArray(wpi::span<const double> value) {
return SetEntryValue(m_handle, Value::MakeDoubleArray(value));
}
@@ -228,7 +228,7 @@ inline bool NetworkTableEntry::SetDoubleArray(
}
inline bool NetworkTableEntry::SetStringArray(
wpi::ArrayRef<std::string> value) {
wpi::span<const std::string> value) {
return SetEntryValue(m_handle, Value::MakeStringArray(value));
}
@@ -257,7 +257,8 @@ inline void NetworkTableEntry::ForceSetRaw(std::string_view value) {
SetEntryTypeValue(m_handle, Value::MakeRaw(value));
}
inline void NetworkTableEntry::ForceSetBooleanArray(wpi::ArrayRef<bool> value) {
inline void NetworkTableEntry::ForceSetBooleanArray(
wpi::span<const bool> value) {
SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value));
}
@@ -266,7 +267,8 @@ inline void NetworkTableEntry::ForceSetBooleanArray(
SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value));
}
inline void NetworkTableEntry::ForceSetBooleanArray(wpi::ArrayRef<int> value) {
inline void NetworkTableEntry::ForceSetBooleanArray(
wpi::span<const int> value) {
SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value));
}
@@ -276,7 +278,7 @@ inline void NetworkTableEntry::ForceSetBooleanArray(
}
inline void NetworkTableEntry::ForceSetDoubleArray(
wpi::ArrayRef<double> value) {
wpi::span<const double> value) {
SetEntryTypeValue(m_handle, Value::MakeDoubleArray(value));
}
@@ -286,7 +288,7 @@ inline void NetworkTableEntry::ForceSetDoubleArray(
}
inline void NetworkTableEntry::ForceSetStringArray(
wpi::ArrayRef<std::string> value) {
wpi::span<const std::string> value) {
SetEntryTypeValue(m_handle, Value::MakeStringArray(value));
}

View File

@@ -12,7 +12,7 @@
#include <utility>
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "networktables/NetworkTable.h"
#include "networktables/NetworkTableEntry.h"
@@ -342,7 +342,7 @@ class NetworkTableInstance final {
* @param servers array of server name and port pairs
*/
void StartClient(
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
wpi::span<const std::pair<std::string_view, unsigned int>> servers);
/**
* Starts a client using the specified servers and port. The
@@ -351,7 +351,7 @@ class NetworkTableInstance final {
* @param servers array of server names
* @param port port to communicate over
*/
void StartClient(wpi::ArrayRef<std::string_view> servers,
void StartClient(wpi::span<const std::string_view> servers,
unsigned int port = kDefaultPort);
/**
@@ -383,7 +383,7 @@ class NetworkTableInstance final {
* @param servers array of server name and port pairs
*/
void SetServer(
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
wpi::span<const std::pair<std::string_view, unsigned int>> servers);
/**
* Sets server addresses and port for client (without restarting client).
@@ -392,7 +392,7 @@ class NetworkTableInstance final {
* @param servers array of server names
* @param port port to communicate over
*/
void SetServer(wpi::ArrayRef<std::string_view> servers,
void SetServer(wpi::span<const std::string_view> servers,
unsigned int port = kDefaultPort);
/**

View File

@@ -117,7 +117,7 @@ inline void NetworkTableInstance::StartClient(const char* server_name,
}
inline void NetworkTableInstance::StartClient(
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers) {
wpi::span<const std::pair<std::string_view, unsigned int>> servers) {
::nt::StartClient(m_handle, servers);
}
@@ -136,7 +136,7 @@ inline void NetworkTableInstance::SetServer(const char* server_name,
}
inline void NetworkTableInstance::SetServer(
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers) {
wpi::span<const std::pair<std::string_view, unsigned int>> servers) {
::nt::SetServer(m_handle, servers);
}

View File

@@ -16,7 +16,7 @@
#include <utility>
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "ntcore_c.h"
@@ -192,10 +192,9 @@ class Value final {
*
* @return The boolean array value.
*/
wpi::ArrayRef<int> GetBooleanArray() const {
wpi::span<const int> GetBooleanArray() const {
assert(m_val.type == NT_BOOLEAN_ARRAY);
return wpi::ArrayRef<int>(m_val.data.arr_boolean.arr,
m_val.data.arr_boolean.size);
return {m_val.data.arr_boolean.arr, m_val.data.arr_boolean.size};
}
/**
@@ -203,10 +202,9 @@ class Value final {
*
* @return The double array value.
*/
wpi::ArrayRef<double> GetDoubleArray() const {
wpi::span<const double> GetDoubleArray() const {
assert(m_val.type == NT_DOUBLE_ARRAY);
return wpi::ArrayRef<double>(m_val.data.arr_double.arr,
m_val.data.arr_double.size);
return {m_val.data.arr_double.arr, m_val.data.arr_double.size};
}
/**
@@ -214,7 +212,7 @@ class Value final {
*
* @return The string array value.
*/
wpi::ArrayRef<std::string> GetStringArray() const {
wpi::span<const std::string> GetStringArray() const {
assert(m_val.type == NT_STRING_ARRAY);
return m_string_array;
}
@@ -366,7 +364,7 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeBooleanArray(wpi::ArrayRef<bool> value,
static std::shared_ptr<Value> MakeBooleanArray(wpi::span<const bool> value,
uint64_t time = 0);
/**
@@ -379,8 +377,7 @@ class Value final {
*/
static std::shared_ptr<Value> MakeBooleanArray(
std::initializer_list<bool> value, uint64_t time = 0) {
return MakeBooleanArray(wpi::makeArrayRef(value.begin(), value.end()),
time);
return MakeBooleanArray(wpi::span(value.begin(), value.end()), time);
}
/**
@@ -391,7 +388,7 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeBooleanArray(wpi::ArrayRef<int> value,
static std::shared_ptr<Value> MakeBooleanArray(wpi::span<const int> value,
uint64_t time = 0);
/**
@@ -404,8 +401,7 @@ class Value final {
*/
static std::shared_ptr<Value> MakeBooleanArray(
std::initializer_list<int> value, uint64_t time = 0) {
return MakeBooleanArray(wpi::makeArrayRef(value.begin(), value.end()),
time);
return MakeBooleanArray(wpi::span(value.begin(), value.end()), time);
}
/**
@@ -416,7 +412,7 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeDoubleArray(wpi::ArrayRef<double> value,
static std::shared_ptr<Value> MakeDoubleArray(wpi::span<const double> value,
uint64_t time = 0);
/**
@@ -429,7 +425,7 @@ class Value final {
*/
static std::shared_ptr<Value> MakeDoubleArray(
std::initializer_list<double> value, uint64_t time = 0) {
return MakeDoubleArray(wpi::makeArrayRef(value.begin(), value.end()), time);
return MakeDoubleArray(wpi::span(value.begin(), value.end()), time);
}
/**
@@ -441,7 +437,7 @@ class Value final {
* @return The entry value
*/
static std::shared_ptr<Value> MakeStringArray(
wpi::ArrayRef<std::string> value, uint64_t time = 0);
wpi::span<const std::string> value, uint64_t time = 0);
/**
* Creates a string array entry value.
@@ -453,7 +449,7 @@ class Value final {
*/
static std::shared_ptr<Value> MakeStringArray(
std::initializer_list<std::string> value, uint64_t time = 0) {
return MakeStringArray(wpi::makeArrayRef(value.begin(), value.end()), time);
return MakeStringArray(wpi::span(value.begin(), value.end()), time);
}
/**

View File

@@ -16,7 +16,7 @@
#include <utility>
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/span.h>
#include "networktables/NetworkTableValue.h"
@@ -955,7 +955,7 @@ bool UnpackRpcDefinition(std::string_view packed, RpcDefinition* def);
* @param values array of values to pack
* @return Raw packed bytes.
*/
std::string PackRpcValues(wpi::ArrayRef<std::shared_ptr<Value>> values);
std::string PackRpcValues(wpi::span<const std::shared_ptr<Value>> values);
/**
* Unpack RPC values as required for RPC version 1 definition messages.
@@ -965,7 +965,7 @@ std::string PackRpcValues(wpi::ArrayRef<std::shared_ptr<Value>> values);
* @return Array of values.
*/
std::vector<std::shared_ptr<Value>> UnpackRpcValues(
std::string_view packed, wpi::ArrayRef<NT_Type> types);
std::string_view packed, wpi::span<const NT_Type> types);
/** @} */
@@ -1050,7 +1050,7 @@ void StartClient(NT_Inst inst, const char* server_name, unsigned int port);
*/
void StartClient(
NT_Inst inst,
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
wpi::span<const std::pair<std::string_view, unsigned int>> servers);
/**
* Starts a client using commonly known robot addresses for the specified
@@ -1087,7 +1087,7 @@ void SetServer(NT_Inst inst, const char* server_name, unsigned int port);
*/
void SetServer(
NT_Inst inst,
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
wpi::span<const std::pair<std::string_view, unsigned int>> servers);
/**
* Sets server addresses and port for client (without restarting client).