mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41: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:
@@ -529,7 +529,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(const std::string& host) {
|
||||
return AddAxisCamera("Axis Camera", host);
|
||||
}
|
||||
|
||||
cs::AxisCamera CameraServer::AddAxisCamera(wpi::ArrayRef<std::string> hosts) {
|
||||
cs::AxisCamera CameraServer::AddAxisCamera(wpi::span<const std::string> hosts) {
|
||||
return AddAxisCamera("Axis Camera", hosts);
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
|
||||
}
|
||||
|
||||
cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
|
||||
wpi::ArrayRef<std::string> hosts) {
|
||||
wpi::span<const std::string> hosts) {
|
||||
cs::AxisCamera camera{name, hosts};
|
||||
StartAutomaticCapture(camera);
|
||||
auto csShared = GetCameraServerShared();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "cscore.h"
|
||||
#include "cscore_cv.h"
|
||||
@@ -116,7 +116,7 @@ class CameraServer {
|
||||
*
|
||||
* @param hosts Array of Camera host IPs/DNS names
|
||||
*/
|
||||
cs::AxisCamera AddAxisCamera(wpi::ArrayRef<std::string> hosts);
|
||||
cs::AxisCamera AddAxisCamera(wpi::span<const std::string> hosts);
|
||||
|
||||
/**
|
||||
* Adds an Axis IP camera.
|
||||
@@ -159,7 +159,7 @@ class CameraServer {
|
||||
* @param hosts Array of Camera host IPs/DNS names
|
||||
*/
|
||||
cs::AxisCamera AddAxisCamera(std::string_view name,
|
||||
wpi::ArrayRef<std::string> hosts);
|
||||
wpi::span<const std::string> hosts);
|
||||
|
||||
/**
|
||||
* Adds an Axis IP camera.
|
||||
|
||||
@@ -88,7 +88,7 @@ int ConfigurableSourceImpl::CreateProperty(
|
||||
}
|
||||
|
||||
void ConfigurableSourceImpl::SetEnumPropertyChoices(
|
||||
int property, wpi::ArrayRef<std::string> choices, CS_Status* status) {
|
||||
int property, wpi::span<const std::string> choices, CS_Status* status) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
@@ -99,7 +99,7 @@ void ConfigurableSourceImpl::SetEnumPropertyChoices(
|
||||
*status = CS_WRONG_PROPERTY_TYPE;
|
||||
return;
|
||||
}
|
||||
prop->enumChoices = choices;
|
||||
prop->enumChoices.assign(choices.begin(), choices.end());
|
||||
m_notifier.NotifySourceProperty(*this, CS_SOURCE_PROPERTY_CHOICES_UPDATED,
|
||||
prop->name, property, CS_PROP_ENUM,
|
||||
prop->value, {});
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "SourceImpl.h"
|
||||
|
||||
@@ -41,7 +41,8 @@ class ConfigurableSourceImpl : public SourceImpl {
|
||||
int CreateProperty(std::string_view name, CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue, int value,
|
||||
std::function<void(CS_Property property)> onChange);
|
||||
void SetEnumPropertyChoices(int property, wpi::ArrayRef<std::string> choices,
|
||||
void SetEnumPropertyChoices(int property,
|
||||
wpi::span<const std::string> choices,
|
||||
CS_Status* status);
|
||||
|
||||
private:
|
||||
|
||||
@@ -140,7 +140,7 @@ CS_Property CreateSourcePropertyCallback(
|
||||
}
|
||||
|
||||
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
wpi::ArrayRef<std::string> choices,
|
||||
wpi::span<const std::string> choices,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "ConfigurableSourceImpl.h"
|
||||
#include "SourceImpl.h"
|
||||
|
||||
@@ -378,7 +378,7 @@ CS_HttpCameraKind HttpCameraImpl::GetKind() const {
|
||||
return m_kind;
|
||||
}
|
||||
|
||||
bool HttpCameraImpl::SetUrls(wpi::ArrayRef<std::string> urls,
|
||||
bool HttpCameraImpl::SetUrls(wpi::span<const std::string> urls,
|
||||
CS_Status* status) {
|
||||
std::vector<wpi::HttpLocation> locations;
|
||||
for (const auto& url : urls) {
|
||||
@@ -571,14 +571,15 @@ CS_Source CreateHttpCamera(std::string_view name, std::string_view url,
|
||||
inst.notifier, inst.telemetry);
|
||||
break;
|
||||
}
|
||||
if (!source->SetUrls(std::string{url}, status)) {
|
||||
std::string urlStr{url};
|
||||
if (!source->SetUrls(wpi::span{&urlStr, 1}, status)) {
|
||||
return 0;
|
||||
}
|
||||
return inst.CreateSource(CS_SOURCE_HTTP, source);
|
||||
}
|
||||
|
||||
CS_Source CreateHttpCamera(std::string_view name,
|
||||
wpi::ArrayRef<std::string> urls,
|
||||
wpi::span<const std::string> urls,
|
||||
CS_HttpCameraKind kind, CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
if (urls.empty()) {
|
||||
@@ -602,7 +603,7 @@ CS_HttpCameraKind GetHttpCameraKind(CS_Source source, CS_Status* status) {
|
||||
return static_cast<HttpCameraImpl&>(*data->source).GetKind();
|
||||
}
|
||||
|
||||
void SetHttpCameraUrls(CS_Source source, wpi::ArrayRef<std::string> urls,
|
||||
void SetHttpCameraUrls(CS_Source source, wpi::span<const std::string> urls,
|
||||
CS_Status* status) {
|
||||
if (urls.empty()) {
|
||||
*status = CS_EMPTY_VALUE;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/raw_istream.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "SourceImpl.h"
|
||||
#include "cscore_cpp.h"
|
||||
@@ -54,7 +55,7 @@ class HttpCameraImpl : public SourceImpl {
|
||||
void NumSinksEnabledChanged() override;
|
||||
|
||||
CS_HttpCameraKind GetKind() const;
|
||||
bool SetUrls(wpi::ArrayRef<std::string> urls, CS_Status* status);
|
||||
bool SetUrls(wpi::span<const std::string> urls, CS_Status* status);
|
||||
std::vector<std::string> GetUrls() const;
|
||||
|
||||
// Property data
|
||||
|
||||
@@ -86,18 +86,17 @@ class Instance {
|
||||
void DestroySource(CS_Source handle);
|
||||
void DestroySink(CS_Sink handle);
|
||||
|
||||
wpi::ArrayRef<CS_Source> EnumerateSourceHandles(
|
||||
wpi::span<CS_Source> EnumerateSourceHandles(
|
||||
wpi::SmallVectorImpl<CS_Source>& vec) {
|
||||
return m_sources.GetAll(vec);
|
||||
}
|
||||
|
||||
wpi::ArrayRef<CS_Sink> EnumerateSinkHandles(
|
||||
wpi::SmallVectorImpl<CS_Sink>& vec) {
|
||||
wpi::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec) {
|
||||
return m_sinks.GetAll(vec);
|
||||
}
|
||||
|
||||
wpi::ArrayRef<CS_Sink> EnumerateSourceSinks(
|
||||
CS_Source source, wpi::SmallVectorImpl<CS_Sink>& vec) {
|
||||
wpi::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
|
||||
wpi::SmallVectorImpl<CS_Sink>& vec) {
|
||||
vec.clear();
|
||||
m_sinks.ForEach([&](CS_Sink sinkHandle, const SinkData& data) {
|
||||
if (source == data.sourceHandle.load()) {
|
||||
|
||||
@@ -27,7 +27,7 @@ int PropertyContainer::GetPropertyIndex(std::string_view name) const {
|
||||
return ndx;
|
||||
}
|
||||
|
||||
wpi::ArrayRef<int> PropertyContainer::EnumerateProperties(
|
||||
wpi::span<int> PropertyContainer::EnumerateProperties(
|
||||
wpi::SmallVectorImpl<int>& vec, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status)) {
|
||||
return {};
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "PropertyImpl.h"
|
||||
#include "cscore_cpp.h"
|
||||
@@ -33,8 +33,8 @@ class PropertyContainer {
|
||||
virtual ~PropertyContainer() = default;
|
||||
|
||||
int GetPropertyIndex(std::string_view name) const;
|
||||
wpi::ArrayRef<int> EnumerateProperties(wpi::SmallVectorImpl<int>& vec,
|
||||
CS_Status* status) const;
|
||||
wpi::span<int> EnumerateProperties(wpi::SmallVectorImpl<int>& vec,
|
||||
CS_Status* status) const;
|
||||
CS_PropertyKind GetPropertyKind(int property) const;
|
||||
std::string_view GetPropertyName(int property,
|
||||
wpi::SmallVectorImpl<char>& buf,
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "ConfigurableSourceImpl.h"
|
||||
#include "SourceImpl.h"
|
||||
#include "cscore_raw.h"
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/Logger.h>
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
namespace cs {
|
||||
|
||||
@@ -50,7 +50,7 @@ class UnlimitedHandleResource {
|
||||
std::shared_ptr<TStruct> Free(THandle handle);
|
||||
|
||||
template <typename T>
|
||||
wpi::ArrayRef<T> GetAll(wpi::SmallVectorImpl<T>& vec);
|
||||
wpi::span<T> GetAll(wpi::SmallVectorImpl<T>& vec);
|
||||
|
||||
std::vector<std::shared_ptr<TStruct>> FreeAll();
|
||||
|
||||
@@ -151,7 +151,7 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Free(
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
|
||||
template <typename T>
|
||||
inline wpi::ArrayRef<T>
|
||||
inline wpi::span<T>
|
||||
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::GetAll(
|
||||
wpi::SmallVectorImpl<T>& vec) {
|
||||
ForEach([&](THandle handle, const TStruct& data) { vec.push_back(handle); });
|
||||
|
||||
@@ -286,13 +286,13 @@ CS_Property GetSourceProperty(CS_Source source, std::string_view name,
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
}
|
||||
|
||||
wpi::ArrayRef<CS_Property> EnumerateSourceProperties(
|
||||
wpi::span<CS_Property> EnumerateSourceProperties(
|
||||
CS_Source source, wpi::SmallVectorImpl<CS_Property>& vec,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
wpi::SmallVector<int, 32> properties_buf;
|
||||
for (auto property :
|
||||
@@ -398,14 +398,14 @@ std::vector<VideoMode> EnumerateSourceVideoModes(CS_Source source,
|
||||
return data->source->EnumerateVideoModes(status);
|
||||
}
|
||||
|
||||
wpi::ArrayRef<CS_Sink> EnumerateSourceSinks(CS_Source source,
|
||||
wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status) {
|
||||
wpi::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
|
||||
wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
auto data = inst.GetSource(source);
|
||||
if (!data) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return wpi::ArrayRef<CS_Sink>{};
|
||||
return {};
|
||||
}
|
||||
return inst.EnumerateSourceSinks(source, vec);
|
||||
}
|
||||
@@ -583,12 +583,12 @@ CS_Property GetSinkProperty(CS_Sink sink, std::string_view name,
|
||||
return Handle{sink, property, Handle::kSinkProperty};
|
||||
}
|
||||
|
||||
wpi::ArrayRef<CS_Property> EnumerateSinkProperties(
|
||||
wpi::span<CS_Property> EnumerateSinkProperties(
|
||||
CS_Sink sink, wpi::SmallVectorImpl<CS_Property>& vec, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
wpi::SmallVector<int, 32> properties_buf;
|
||||
for (auto property :
|
||||
@@ -861,13 +861,13 @@ void Shutdown() {
|
||||
// Utility Functions
|
||||
//
|
||||
|
||||
wpi::ArrayRef<CS_Source> EnumerateSourceHandles(
|
||||
wpi::span<CS_Source> EnumerateSourceHandles(
|
||||
wpi::SmallVectorImpl<CS_Source>& vec, CS_Status* status) {
|
||||
return Instance::GetInstance().EnumerateSourceHandles(vec);
|
||||
}
|
||||
|
||||
wpi::ArrayRef<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status) {
|
||||
wpi::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status) {
|
||||
return Instance::GetInstance().EnumerateSinkHandles(vec);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/jni_util.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "cscore_cpp.h"
|
||||
#include "cscore_cv.h"
|
||||
@@ -294,7 +295,8 @@ static jobject MakeJObject(JNIEnv* env, const cs::RawEvent& event) {
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
static jobjectArray MakeJObject(JNIEnv* env, wpi::ArrayRef<cs::RawEvent> arr) {
|
||||
static jobjectArray MakeJObject(JNIEnv* env,
|
||||
wpi::span<const cs::RawEvent> arr) {
|
||||
jobjectArray jarr = env->NewObjectArray(arr.size(), videoEventCls, nullptr);
|
||||
if (!jarr) {
|
||||
return nullptr;
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "cscore_c.h"
|
||||
|
||||
@@ -203,7 +203,7 @@ CS_Source CreateUsbCameraPath(std::string_view name, std::string_view path,
|
||||
CS_Source CreateHttpCamera(std::string_view name, std::string_view url,
|
||||
CS_HttpCameraKind kind, CS_Status* status);
|
||||
CS_Source CreateHttpCamera(std::string_view name,
|
||||
wpi::ArrayRef<std::string> urls,
|
||||
wpi::span<const std::string> urls,
|
||||
CS_HttpCameraKind kind, CS_Status* status);
|
||||
CS_Source CreateCvSource(std::string_view name, const VideoMode& mode,
|
||||
CS_Status* status);
|
||||
@@ -230,7 +230,7 @@ bool IsSourceConnected(CS_Source source, CS_Status* status);
|
||||
bool IsSourceEnabled(CS_Source source, CS_Status* status);
|
||||
CS_Property GetSourceProperty(CS_Source source, std::string_view name,
|
||||
CS_Status* status);
|
||||
wpi::ArrayRef<CS_Property> EnumerateSourceProperties(
|
||||
wpi::span<CS_Property> EnumerateSourceProperties(
|
||||
CS_Source source, wpi::SmallVectorImpl<CS_Property>& vec,
|
||||
CS_Status* status);
|
||||
VideoMode GetSourceVideoMode(CS_Source source, CS_Status* status);
|
||||
@@ -249,9 +249,9 @@ std::string GetSourceConfigJson(CS_Source source, CS_Status* status);
|
||||
wpi::json GetSourceConfigJsonObject(CS_Source source, CS_Status* status);
|
||||
std::vector<VideoMode> EnumerateSourceVideoModes(CS_Source source,
|
||||
CS_Status* status);
|
||||
wpi::ArrayRef<CS_Sink> EnumerateSourceSinks(CS_Source source,
|
||||
wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status);
|
||||
wpi::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
|
||||
wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status);
|
||||
CS_Source CopySource(CS_Source source, CS_Status* status);
|
||||
void ReleaseSource(CS_Source source, CS_Status* status);
|
||||
/** @} */
|
||||
@@ -285,7 +285,7 @@ UsbCameraInfo GetUsbCameraInfo(CS_Source source, CS_Status* status);
|
||||
* @{
|
||||
*/
|
||||
CS_HttpCameraKind GetHttpCameraKind(CS_Source source, CS_Status* status);
|
||||
void SetHttpCameraUrls(CS_Source source, wpi::ArrayRef<std::string> urls,
|
||||
void SetHttpCameraUrls(CS_Source source, wpi::span<const std::string> urls,
|
||||
CS_Status* status);
|
||||
std::vector<std::string> GetHttpCameraUrls(CS_Source source, CS_Status* status);
|
||||
/** @} */
|
||||
@@ -304,7 +304,7 @@ CS_Property CreateSourceProperty(CS_Source source, std::string_view name,
|
||||
int step, int defaultValue, int value,
|
||||
CS_Status* status);
|
||||
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
wpi::ArrayRef<std::string> choices,
|
||||
wpi::span<const std::string> choices,
|
||||
CS_Status* status);
|
||||
/** @} */
|
||||
|
||||
@@ -335,7 +335,7 @@ std::string_view GetSinkDescription(CS_Sink sink,
|
||||
CS_Status* status);
|
||||
CS_Property GetSinkProperty(CS_Sink sink, std::string_view name,
|
||||
CS_Status* status);
|
||||
wpi::ArrayRef<CS_Property> EnumerateSinkProperties(
|
||||
wpi::span<CS_Property> EnumerateSinkProperties(
|
||||
CS_Sink sink, wpi::SmallVectorImpl<CS_Property>& vec, CS_Status* status);
|
||||
void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status);
|
||||
CS_Property GetSinkSourceProperty(CS_Sink sink, std::string_view name,
|
||||
@@ -430,10 +430,10 @@ void Shutdown();
|
||||
*/
|
||||
std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status);
|
||||
|
||||
wpi::ArrayRef<CS_Source> EnumerateSourceHandles(
|
||||
wpi::span<CS_Source> EnumerateSourceHandles(
|
||||
wpi::SmallVectorImpl<CS_Source>& vec, CS_Status* status);
|
||||
wpi::ArrayRef<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status);
|
||||
wpi::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
|
||||
CS_Status* status);
|
||||
|
||||
std::string GetHostname();
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "cscore_cpp.h"
|
||||
|
||||
namespace cs {
|
||||
@@ -514,7 +516,7 @@ class HttpCamera : public VideoCamera {
|
||||
* @param urls Array of Camera URLs
|
||||
* @param kind Camera kind (e.g. kAxis)
|
||||
*/
|
||||
HttpCamera(std::string_view name, wpi::ArrayRef<std::string> urls,
|
||||
HttpCamera(std::string_view name, wpi::span<const std::string> urls,
|
||||
HttpCameraKind kind = kUnknown);
|
||||
|
||||
/**
|
||||
@@ -539,7 +541,7 @@ class HttpCamera : public VideoCamera {
|
||||
/**
|
||||
* Change the URLs used to connect to the camera.
|
||||
*/
|
||||
void SetUrls(wpi::ArrayRef<std::string> urls);
|
||||
void SetUrls(wpi::span<const std::string> urls);
|
||||
|
||||
/**
|
||||
* Change the URLs used to connect to the camera.
|
||||
@@ -558,7 +560,7 @@ class HttpCamera : public VideoCamera {
|
||||
*/
|
||||
class AxisCamera : public HttpCamera {
|
||||
static std::string HostToUrl(std::string_view host);
|
||||
static std::vector<std::string> HostToUrl(wpi::ArrayRef<std::string> hosts);
|
||||
static std::vector<std::string> HostToUrl(wpi::span<const std::string> hosts);
|
||||
template <typename T>
|
||||
static std::vector<std::string> HostToUrl(std::initializer_list<T> hosts);
|
||||
|
||||
@@ -597,7 +599,7 @@ class AxisCamera : public HttpCamera {
|
||||
* @param hosts Array of Camera host IPs/DNS names
|
||||
* @param kind Camera kind (e.g. kAxis)
|
||||
*/
|
||||
AxisCamera(std::string_view name, wpi::ArrayRef<std::string> hosts);
|
||||
AxisCamera(std::string_view name, wpi::span<const std::string> hosts);
|
||||
|
||||
/**
|
||||
* Create a source for an Axis IP camera.
|
||||
@@ -698,7 +700,7 @@ class ImageSource : public VideoSource {
|
||||
* @param choices Choices
|
||||
*/
|
||||
void SetEnumPropertyChoices(const VideoProperty& property,
|
||||
wpi::ArrayRef<std::string> choices);
|
||||
wpi::span<const std::string> choices);
|
||||
|
||||
/**
|
||||
* Configure enum property choices.
|
||||
|
||||
@@ -302,7 +302,7 @@ inline HttpCamera::HttpCamera(std::string_view name, const std::string& url,
|
||||
: HttpCamera(name, std::string_view{url}, kind) {}
|
||||
|
||||
inline HttpCamera::HttpCamera(std::string_view name,
|
||||
wpi::ArrayRef<std::string> urls,
|
||||
wpi::span<const std::string> urls,
|
||||
HttpCameraKind kind) {
|
||||
m_handle = CreateHttpCamera(
|
||||
name, urls, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
|
||||
@@ -329,7 +329,7 @@ inline HttpCamera::HttpCameraKind HttpCamera::GetHttpCameraKind() const {
|
||||
static_cast<int>(::cs::GetHttpCameraKind(m_handle, &m_status)));
|
||||
}
|
||||
|
||||
inline void HttpCamera::SetUrls(wpi::ArrayRef<std::string> urls) {
|
||||
inline void HttpCamera::SetUrls(wpi::span<const std::string> urls) {
|
||||
m_status = 0;
|
||||
::cs::SetHttpCameraUrls(m_handle, urls, &m_status);
|
||||
}
|
||||
@@ -351,7 +351,7 @@ inline std::vector<std::string> HttpCamera::GetUrls() const {
|
||||
}
|
||||
|
||||
inline std::vector<std::string> AxisCamera::HostToUrl(
|
||||
wpi::ArrayRef<std::string> hosts) {
|
||||
wpi::span<const std::string> hosts) {
|
||||
std::vector<std::string> rv;
|
||||
rv.reserve(hosts.size());
|
||||
for (const auto& host : hosts) {
|
||||
@@ -381,7 +381,7 @@ inline AxisCamera::AxisCamera(std::string_view name, const std::string& host)
|
||||
: HttpCamera(name, HostToUrl(std::string_view{host}), kAxis) {}
|
||||
|
||||
inline AxisCamera::AxisCamera(std::string_view name,
|
||||
wpi::ArrayRef<std::string> hosts)
|
||||
wpi::span<const std::string> hosts)
|
||||
: HttpCamera(name, HostToUrl(hosts), kAxis) {}
|
||||
|
||||
template <typename T>
|
||||
@@ -452,7 +452,7 @@ inline VideoProperty ImageSource::CreateStringProperty(std::string_view name,
|
||||
}
|
||||
|
||||
inline void ImageSource::SetEnumPropertyChoices(
|
||||
const VideoProperty& property, wpi::ArrayRef<std::string> choices) {
|
||||
const VideoProperty& property, wpi::span<const std::string> choices) {
|
||||
m_status = 0;
|
||||
SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices, &m_status);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class PopupState {
|
||||
|
||||
SelectedTargetInfo* GetTarget() { return &m_target; }
|
||||
FieldObjectModel* GetInsertModel() { return m_insertModel; }
|
||||
wpi::ArrayRef<frc::Pose2d> GetInsertPoses() const { return m_insertPoses; }
|
||||
wpi::span<const frc::Pose2d> GetInsertPoses() const { return m_insertPoses; }
|
||||
|
||||
void Display(Field2DModel* model, const FieldFrameData& ffd);
|
||||
|
||||
@@ -184,7 +184,7 @@ class ObjectInfo {
|
||||
|
||||
DisplayOptions GetDisplayOptions() const;
|
||||
void DisplaySettings();
|
||||
void DrawLine(ImDrawList* drawList, wpi::ArrayRef<ImVec2> points) const;
|
||||
void DrawLine(ImDrawList* drawList, wpi::span<const ImVec2> points) const;
|
||||
|
||||
void LoadImage();
|
||||
const gui::Texture& GetTexture() const { return m_texture; }
|
||||
@@ -623,7 +623,7 @@ void ObjectInfo::DisplaySettings() {
|
||||
}
|
||||
|
||||
void ObjectInfo::DrawLine(ImDrawList* drawList,
|
||||
wpi::ArrayRef<ImVec2> points) const {
|
||||
wpi::span<const ImVec2> points) const {
|
||||
if (points.empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -1038,9 +1038,9 @@ void FieldDisplay::DisplayObject(FieldObjectModel& model,
|
||||
|
||||
m_drawSplit.Split(m_drawList, 2);
|
||||
m_drawSplit.SetCurrentChannel(m_drawList, 1);
|
||||
wpi::ArrayRef<frc::Pose2d> poses = gPopupState.GetInsertModel() == &model
|
||||
? gPopupState.GetInsertPoses()
|
||||
: model.GetPoses();
|
||||
auto poses = gPopupState.GetInsertModel() == &model
|
||||
? gPopupState.GetInsertPoses()
|
||||
: model.GetPoses();
|
||||
size_t i = 0;
|
||||
for (auto&& pose : poses) {
|
||||
PoseFrameData pfd{pose, model, i, m_ffd, displayOptions};
|
||||
@@ -1113,7 +1113,8 @@ void PopupState::DisplayTarget(Field2DModel* model, const FieldFrameData& ffd) {
|
||||
m_target.objModel->SetPose(m_target.index, pose);
|
||||
}
|
||||
if (ImGui::Button("Delete Pose")) {
|
||||
std::vector<frc::Pose2d> poses = m_target.objModel->GetPoses();
|
||||
auto posesRef = m_target.objModel->GetPoses();
|
||||
std::vector<frc::Pose2d> poses{posesRef.begin(), posesRef.end()};
|
||||
if (m_target.index < poses.size()) {
|
||||
poses.erase(poses.begin() + m_target.index);
|
||||
m_target.objModel->SetPoses(poses);
|
||||
@@ -1150,7 +1151,8 @@ void PopupState::DisplayInsert(Field2DModel* model) {
|
||||
if (ImGui::Selectable(name.data(), selected)) {
|
||||
m_insertModel = &objModel;
|
||||
auto pose = m_insertPoses[m_insertIndex];
|
||||
m_insertPoses = objModel.GetPoses();
|
||||
auto posesRef = objModel.GetPoses();
|
||||
m_insertPoses.assign(posesRef.begin(), posesRef.end());
|
||||
m_insertPoses.emplace_back(std::move(pose));
|
||||
m_insertName = name;
|
||||
m_insertIndex = m_insertPoses.size() - 1;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/STLExtras.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "glass/Model.h"
|
||||
|
||||
@@ -27,7 +27,7 @@ class LEDDisplayModel : public glass::Model {
|
||||
|
||||
virtual bool IsRunning() = 0;
|
||||
|
||||
virtual wpi::ArrayRef<Data> GetData(wpi::SmallVectorImpl<Data>& buf) = 0;
|
||||
virtual wpi::span<const Data> GetData(wpi::SmallVectorImpl<Data>& buf) = 0;
|
||||
};
|
||||
|
||||
class LEDDisplaysModel : public glass::Model {
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <frc/geometry/Rotation2d.h>
|
||||
#include <frc/geometry/Translation2d.h>
|
||||
#include <imgui.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/STLExtras.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "glass/Model.h"
|
||||
#include "glass/View.h"
|
||||
@@ -22,8 +22,8 @@ class FieldObjectModel : public Model {
|
||||
public:
|
||||
virtual const char* GetName() const = 0;
|
||||
|
||||
virtual wpi::ArrayRef<frc::Pose2d> GetPoses() = 0;
|
||||
virtual void SetPoses(wpi::ArrayRef<frc::Pose2d> poses) = 0;
|
||||
virtual wpi::span<const frc::Pose2d> GetPoses() = 0;
|
||||
virtual void SetPoses(wpi::span<const frc::Pose2d> poses) = 0;
|
||||
virtual void SetPose(size_t i, frc::Pose2d pose) = 0;
|
||||
virtual void SetPosition(size_t i, frc::Translation2d pos) = 0;
|
||||
virtual void SetRotation(size_t i, frc::Rotation2d rot) = 0;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "glass/Model.h"
|
||||
|
||||
@@ -24,7 +24,7 @@ class StringChooserModel : public Model {
|
||||
virtual void SetDefault(std::string_view val) = 0;
|
||||
virtual void SetSelected(std::string_view val) = 0;
|
||||
virtual void SetActive(std::string_view val) = 0;
|
||||
virtual void SetOptions(wpi::ArrayRef<std::string> val) = 0;
|
||||
virtual void SetOptions(wpi::span<const std::string> val) = 0;
|
||||
};
|
||||
|
||||
void DisplayStringChooser(StringChooserModel* model);
|
||||
|
||||
@@ -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; });
|
||||
|
||||
@@ -32,7 +32,7 @@ class NTStringChooserModel : public StringChooserModel {
|
||||
void SetDefault(std::string_view val) override;
|
||||
void SetSelected(std::string_view val) override;
|
||||
void SetActive(std::string_view val) override;
|
||||
void SetOptions(wpi::ArrayRef<std::string> val) override;
|
||||
void SetOptions(wpi::span<const std::string> val) override;
|
||||
|
||||
void Update() override;
|
||||
bool Exists() override;
|
||||
|
||||
@@ -257,7 +257,7 @@ Java_edu_wpi_first_hal_simulation_AddressableLEDDataJNI_getData
|
||||
std::make_unique<HAL_AddressableLEDData[]>(HAL_kAddressableLEDMaxLength);
|
||||
int32_t length = HALSIM_GetAddressableLEDData(index, data.get());
|
||||
return MakeJByteArray(
|
||||
env, wpi::ArrayRef(reinterpret_cast<jbyte*>(data.get()), length * 4));
|
||||
env, wpi::span(reinterpret_cast<jbyte*>(data.get()), length * 4));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -668,7 +668,7 @@ Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_getSimValueEnumDoubleValues
|
||||
{
|
||||
int32_t numElems = 0;
|
||||
const double* elems = HALSIM_GetSimValueEnumDoubleValues(handle, &numElems);
|
||||
return MakeJDoubleArray(env, wpi::makeArrayRef(elems, numElems));
|
||||
return MakeJDoubleArray(env, wpi::span(elems, numElems));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -59,7 +59,7 @@ int32_t SpiReadAutoReceiveBufferCallbackStore::performCallback(
|
||||
}
|
||||
|
||||
auto toCallbackArr = MakeJIntArray(
|
||||
env, wpi::ArrayRef<uint32_t>{buffer, static_cast<size_t>(numToRead)});
|
||||
env, wpi::span<const uint32_t>{buffer, static_cast<size_t>(numToRead)});
|
||||
|
||||
jint ret = env->CallIntMethod(m_call, sim::GetBufferCallback(),
|
||||
MakeJString(env, name), toCallbackArr,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifdef __cplusplus
|
||||
#include <initializer_list>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
#endif
|
||||
|
||||
#include "hal/Types.h"
|
||||
@@ -832,7 +832,8 @@ class SimDevice {
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnum(const char* name, int32_t direction,
|
||||
wpi::ArrayRef<const char*> options, int32_t initialValue) {
|
||||
wpi::span<const char* const> options,
|
||||
int32_t initialValue) {
|
||||
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
|
||||
const_cast<const char**>(options.data()),
|
||||
initialValue);
|
||||
@@ -884,8 +885,8 @@ class SimDevice {
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnumDouble(const char* name, int32_t direction,
|
||||
wpi::ArrayRef<const char*> options,
|
||||
wpi::ArrayRef<double> optionValues,
|
||||
wpi::span<const char* const> options,
|
||||
wpi::span<const double> optionValues,
|
||||
int32_t initialValue) {
|
||||
if (options.size() != optionValues.size()) {
|
||||
return {};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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*)>;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "ntcore_test.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <wpi/MemAlloc.h>
|
||||
|
||||
#include "Value_internal.h"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
#include "TestPrinters.h"
|
||||
@@ -11,6 +12,16 @@
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
inline bool operator==(span<T> lhs, span<T> rhs) {
|
||||
if (lhs.size() != rhs.size()) {
|
||||
return false;
|
||||
}
|
||||
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||
}
|
||||
} // namespace wpi
|
||||
|
||||
namespace nt {
|
||||
|
||||
class ValueTest : public ::testing::Test {};
|
||||
@@ -110,7 +121,7 @@ TEST_F(ValueTest, BooleanArray) {
|
||||
std::vector<int> vec{1, 0, 1};
|
||||
auto v = Value::MakeBooleanArray(vec);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, v->type());
|
||||
ASSERT_EQ(wpi::ArrayRef<int>(vec), v->GetBooleanArray());
|
||||
ASSERT_EQ(wpi::span<const int>(vec), v->GetBooleanArray());
|
||||
NT_Value cv;
|
||||
NT_InitValue(&cv);
|
||||
ConvertToC(*v, &cv);
|
||||
@@ -124,7 +135,7 @@ TEST_F(ValueTest, BooleanArray) {
|
||||
vec = {0, 1, 0};
|
||||
v = Value::MakeBooleanArray(vec);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, v->type());
|
||||
ASSERT_EQ(wpi::ArrayRef<int>(vec), v->GetBooleanArray());
|
||||
ASSERT_EQ(wpi::span<const int>(vec), v->GetBooleanArray());
|
||||
ConvertToC(*v, &cv);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, cv.type);
|
||||
ASSERT_EQ(3u, cv.data.arr_boolean.size);
|
||||
@@ -136,7 +147,7 @@ TEST_F(ValueTest, BooleanArray) {
|
||||
vec = {1, 0};
|
||||
v = Value::MakeBooleanArray(vec);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, v->type());
|
||||
ASSERT_EQ(wpi::ArrayRef<int>(vec), v->GetBooleanArray());
|
||||
ASSERT_EQ(wpi::span<const int>(vec), v->GetBooleanArray());
|
||||
ConvertToC(*v, &cv);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, cv.type);
|
||||
ASSERT_EQ(2u, cv.data.arr_boolean.size);
|
||||
@@ -150,7 +161,7 @@ TEST_F(ValueTest, DoubleArray) {
|
||||
std::vector<double> vec{0.5, 0.25, 0.5};
|
||||
auto v = Value::MakeDoubleArray(vec);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, v->type());
|
||||
ASSERT_EQ(wpi::ArrayRef<double>(vec), v->GetDoubleArray());
|
||||
ASSERT_EQ(wpi::span<const double>(vec), v->GetDoubleArray());
|
||||
NT_Value cv;
|
||||
NT_InitValue(&cv);
|
||||
ConvertToC(*v, &cv);
|
||||
@@ -164,7 +175,7 @@ TEST_F(ValueTest, DoubleArray) {
|
||||
vec = {0.25, 0.5, 0.25};
|
||||
v = Value::MakeDoubleArray(vec);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, v->type());
|
||||
ASSERT_EQ(wpi::ArrayRef<double>(vec), v->GetDoubleArray());
|
||||
ASSERT_EQ(wpi::span<const double>(vec), v->GetDoubleArray());
|
||||
ConvertToC(*v, &cv);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, cv.type);
|
||||
ASSERT_EQ(3u, cv.data.arr_double.size);
|
||||
@@ -176,7 +187,7 @@ TEST_F(ValueTest, DoubleArray) {
|
||||
vec = {0.5, 0.25};
|
||||
v = Value::MakeDoubleArray(vec);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, v->type());
|
||||
ASSERT_EQ(wpi::ArrayRef<double>(vec), v->GetDoubleArray());
|
||||
ASSERT_EQ(wpi::span<const double>(vec), v->GetDoubleArray());
|
||||
ConvertToC(*v, &cv);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, cv.type);
|
||||
ASSERT_EQ(2u, cv.data.arr_double.size);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include <hal/simulation/DriverStationData.h>
|
||||
#include <hal/simulation/MockHooks.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
using namespace halsim;
|
||||
|
||||
@@ -45,7 +45,7 @@ void DSCommPacket::SetAlliance(uint8_t station_code) {
|
||||
m_alliance_station = static_cast<HAL_AllianceStationID>(station_code);
|
||||
}
|
||||
|
||||
void DSCommPacket::ReadMatchtimeTag(wpi::ArrayRef<uint8_t> tagData) {
|
||||
void DSCommPacket::ReadMatchtimeTag(wpi::span<const uint8_t> tagData) {
|
||||
if (tagData.size() < 6) {
|
||||
return;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ void DSCommPacket::ReadMatchtimeTag(wpi::ArrayRef<uint8_t> tagData) {
|
||||
m_match_time = matchTime;
|
||||
}
|
||||
|
||||
void DSCommPacket::ReadJoystickTag(wpi::ArrayRef<uint8_t> dataInput,
|
||||
void DSCommPacket::ReadJoystickTag(wpi::span<const uint8_t> dataInput,
|
||||
int index) {
|
||||
DSCommJoystickPacket& stick = m_joystick_packets[index];
|
||||
stick.ResetUdp();
|
||||
@@ -72,7 +72,7 @@ void DSCommPacket::ReadJoystickTag(wpi::ArrayRef<uint8_t> dataInput,
|
||||
return;
|
||||
}
|
||||
|
||||
dataInput = dataInput.slice(2);
|
||||
dataInput = dataInput.subspan(2);
|
||||
|
||||
// Read axes
|
||||
int axesLength = dataInput[0];
|
||||
@@ -86,7 +86,7 @@ void DSCommPacket::ReadJoystickTag(wpi::ArrayRef<uint8_t> dataInput,
|
||||
}
|
||||
stick.axes.count = axesLength;
|
||||
|
||||
dataInput = dataInput.slice(1 + axesLength);
|
||||
dataInput = dataInput.subspan(1 + axesLength);
|
||||
|
||||
// Read Buttons
|
||||
int buttonCount = dataInput[0];
|
||||
@@ -97,7 +97,7 @@ void DSCommPacket::ReadJoystickTag(wpi::ArrayRef<uint8_t> dataInput,
|
||||
}
|
||||
stick.buttons.count = buttonCount;
|
||||
|
||||
dataInput = dataInput.slice(1 + numBytes);
|
||||
dataInput = dataInput.subspan(1 + numBytes);
|
||||
|
||||
int povsLength = dataInput[0];
|
||||
for (int i = 0; i < povsLength * 2; i += 2) {
|
||||
@@ -112,11 +112,11 @@ void DSCommPacket::ReadJoystickTag(wpi::ArrayRef<uint8_t> dataInput,
|
||||
/*----------------------------------------------------------------------------
|
||||
** Communication methods
|
||||
**--------------------------------------------------------------------------*/
|
||||
void DSCommPacket::DecodeTCP(wpi::ArrayRef<uint8_t> packet) {
|
||||
void DSCommPacket::DecodeTCP(wpi::span<const uint8_t> packet) {
|
||||
// No header
|
||||
while (!packet.empty()) {
|
||||
int tagLength = packet[0] << 8 | packet[1];
|
||||
auto tagPacket = packet.slice(0, tagLength + 2);
|
||||
auto tagPacket = packet.subspan(0, tagLength + 2);
|
||||
|
||||
if (tagLength == 0) {
|
||||
return;
|
||||
@@ -133,11 +133,11 @@ void DSCommPacket::DecodeTCP(wpi::ArrayRef<uint8_t> packet) {
|
||||
ReadNewMatchInfoTag(tagPacket);
|
||||
break;
|
||||
}
|
||||
packet = packet.slice(tagLength + 2);
|
||||
packet = packet.subspan(tagLength + 2);
|
||||
}
|
||||
}
|
||||
|
||||
void DSCommPacket::DecodeUDP(wpi::ArrayRef<uint8_t> packet) {
|
||||
void DSCommPacket::DecodeUDP(wpi::span<const uint8_t> packet) {
|
||||
if (packet.size() < 6) {
|
||||
return;
|
||||
}
|
||||
@@ -154,14 +154,14 @@ void DSCommPacket::DecodeUDP(wpi::ArrayRef<uint8_t> packet) {
|
||||
}
|
||||
|
||||
// Else, handle tagged data
|
||||
packet = packet.slice(6);
|
||||
packet = packet.subspan(6);
|
||||
|
||||
int joystickNum = 0;
|
||||
|
||||
// Loop to handle multiple tags
|
||||
while (!packet.empty()) {
|
||||
auto tagLength = packet[0];
|
||||
auto tagPacket = packet.slice(0, tagLength + 1);
|
||||
auto tagPacket = packet.subspan(0, tagLength + 1);
|
||||
|
||||
switch (packet[1]) {
|
||||
case kJoystickDataTag:
|
||||
@@ -172,11 +172,11 @@ void DSCommPacket::DecodeUDP(wpi::ArrayRef<uint8_t> packet) {
|
||||
ReadMatchtimeTag(tagPacket);
|
||||
break;
|
||||
}
|
||||
packet = packet.slice(tagLength + 1);
|
||||
packet = packet.subspan(tagLength + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data) {
|
||||
void DSCommPacket::ReadNewMatchInfoTag(wpi::span<const uint8_t> data) {
|
||||
// Size 2 bytes, tag 1 byte
|
||||
if (data.size() <= 3) {
|
||||
return;
|
||||
@@ -190,7 +190,7 @@ void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data) {
|
||||
|
||||
matchInfo.eventName[nameLength] = '\0';
|
||||
|
||||
data = data.slice(4 + nameLength);
|
||||
data = data.subspan(4 + nameLength);
|
||||
|
||||
if (data.size() < 4) {
|
||||
return;
|
||||
@@ -204,7 +204,7 @@ void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data) {
|
||||
HALSIM_SetMatchInfo(&matchInfo);
|
||||
}
|
||||
|
||||
void DSCommPacket::ReadGameSpecificMessageTag(wpi::ArrayRef<uint8_t> data) {
|
||||
void DSCommPacket::ReadGameSpecificMessageTag(wpi::span<const uint8_t> data) {
|
||||
// Size 2 bytes, tag 1 byte
|
||||
if (data.size() <= 3) {
|
||||
return;
|
||||
@@ -220,11 +220,11 @@ void DSCommPacket::ReadGameSpecificMessageTag(wpi::ArrayRef<uint8_t> data) {
|
||||
|
||||
HALSIM_SetMatchInfo(&matchInfo);
|
||||
}
|
||||
void DSCommPacket::ReadJoystickDescriptionTag(wpi::ArrayRef<uint8_t> data) {
|
||||
void DSCommPacket::ReadJoystickDescriptionTag(wpi::span<const uint8_t> data) {
|
||||
if (data.size() < 3) {
|
||||
return;
|
||||
}
|
||||
data = data.slice(3);
|
||||
data = data.subspan(3);
|
||||
int joystickNum = data[0];
|
||||
DSCommJoystickPacket& packet = m_joystick_packets[joystickNum];
|
||||
packet.ResetTcp();
|
||||
@@ -235,14 +235,14 @@ void DSCommPacket::ReadJoystickDescriptionTag(wpi::ArrayRef<uint8_t> data) {
|
||||
for (int i = 0; i < nameLength; i++) {
|
||||
packet.descriptor.name[i] = data[4 + i];
|
||||
}
|
||||
data = data.slice(4 + nameLength);
|
||||
data = data.subspan(4 + nameLength);
|
||||
packet.descriptor.name[nameLength] = '\0';
|
||||
int axesCount = data[0];
|
||||
packet.descriptor.axisCount = axesCount;
|
||||
for (int i = 0; i < axesCount; i++) {
|
||||
packet.descriptor.axisTypes[i] = data[1 + i];
|
||||
}
|
||||
data = data.slice(1 + axesCount);
|
||||
data = data.subspan(1 + axesCount);
|
||||
|
||||
packet.descriptor.buttonCount = data[0];
|
||||
packet.descriptor.povCount = data[1];
|
||||
|
||||
@@ -116,13 +116,12 @@ static void SetupUdp(wpi::uv::Loop& loop) {
|
||||
struct sockaddr_in simAddr;
|
||||
NameToAddr("127.0.0.1", 1135, &simAddr);
|
||||
simLoopTimer->timeout.connect([udpLocal = udp.get(), simAddr] {
|
||||
udpLocal->Send(simAddr, wpi::ArrayRef<Buffer>{singleByte.get(), 1},
|
||||
[](auto buf, Error err) {
|
||||
if (err) {
|
||||
fmt::print(stderr, "{}\n", err.str());
|
||||
std::fflush(stderr);
|
||||
}
|
||||
});
|
||||
udpLocal->Send(simAddr, {singleByte.get(), 1}, [](auto buf, Error err) {
|
||||
if (err) {
|
||||
fmt::print(stderr, "{}\n", err.str());
|
||||
std::fflush(stderr);
|
||||
}
|
||||
});
|
||||
});
|
||||
simLoopTimer->Start(Timer::Time{100}, Timer::Time{100});
|
||||
|
||||
@@ -131,8 +130,7 @@ static void SetupUdp(wpi::uv::Loop& loop) {
|
||||
const sockaddr& recSock,
|
||||
unsigned int port) {
|
||||
auto ds = udpLocal->GetLoop()->GetData<halsim::DSCommPacket>();
|
||||
ds->DecodeUDP(
|
||||
wpi::ArrayRef<uint8_t>{reinterpret_cast<uint8_t*>(buf.base), len});
|
||||
ds->DecodeUDP({reinterpret_cast<uint8_t*>(buf.base), len});
|
||||
|
||||
struct sockaddr_in outAddr;
|
||||
std::memcpy(&outAddr, &recSock, sizeof(sockaddr_in));
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
#include <DSCommJoystickPacket.h>
|
||||
#include <hal/simulation/DriverStationData.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/raw_uv_ostream.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
class DSCommPacketTest;
|
||||
|
||||
@@ -20,8 +20,8 @@ class DSCommPacket {
|
||||
|
||||
public:
|
||||
DSCommPacket(void);
|
||||
void DecodeTCP(wpi::ArrayRef<uint8_t> packet);
|
||||
void DecodeUDP(wpi::ArrayRef<uint8_t> packet);
|
||||
void DecodeTCP(wpi::span<const uint8_t> packet);
|
||||
void DecodeUDP(wpi::span<const uint8_t> packet);
|
||||
void SendUDPToHALSim(void);
|
||||
void SetupSendBuffer(wpi::raw_uv_ostream& buf);
|
||||
|
||||
@@ -53,11 +53,11 @@ class DSCommPacket {
|
||||
void SetAlliance(uint8_t station_code);
|
||||
void SetupSendHeader(wpi::raw_uv_ostream& buf);
|
||||
void SetupJoystickTag(wpi::raw_uv_ostream& buf);
|
||||
void ReadMatchtimeTag(wpi::ArrayRef<uint8_t> tagData);
|
||||
void ReadJoystickTag(wpi::ArrayRef<uint8_t> data, int index);
|
||||
void ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data);
|
||||
void ReadGameSpecificMessageTag(wpi::ArrayRef<uint8_t> data);
|
||||
void ReadJoystickDescriptionTag(wpi::ArrayRef<uint8_t> data);
|
||||
void ReadMatchtimeTag(wpi::span<const uint8_t> tagData);
|
||||
void ReadJoystickTag(wpi::span<const uint8_t> data, int index);
|
||||
void ReadNewMatchInfoTag(wpi::span<const uint8_t> data);
|
||||
void ReadGameSpecificMessageTag(wpi::span<const uint8_t> data);
|
||||
void ReadJoystickDescriptionTag(wpi::span<const uint8_t> data);
|
||||
|
||||
uint8_t m_hi;
|
||||
uint8_t m_lo;
|
||||
|
||||
@@ -11,23 +11,24 @@ class DSCommPacketTest : public ::testing::Test {
|
||||
|
||||
void SendJoysticks() { commPacket.SendJoysticks(); }
|
||||
|
||||
halsim::DSCommJoystickPacket& ReadJoystickTag(wpi::ArrayRef<uint8_t> data,
|
||||
halsim::DSCommJoystickPacket& ReadJoystickTag(wpi::span<const uint8_t> data,
|
||||
int index) {
|
||||
commPacket.ReadJoystickTag(data, index);
|
||||
return commPacket.m_joystick_packets[index];
|
||||
}
|
||||
|
||||
halsim::DSCommJoystickPacket& ReadDescriptorTag(wpi::ArrayRef<uint8_t> data) {
|
||||
halsim::DSCommJoystickPacket& ReadDescriptorTag(
|
||||
wpi::span<const uint8_t> data) {
|
||||
commPacket.ReadJoystickDescriptionTag(data);
|
||||
return commPacket.m_joystick_packets[data[3]];
|
||||
}
|
||||
|
||||
HAL_MatchInfo& ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data) {
|
||||
HAL_MatchInfo& ReadNewMatchInfoTag(wpi::span<const uint8_t> data) {
|
||||
commPacket.ReadNewMatchInfoTag(data);
|
||||
return commPacket.matchInfo;
|
||||
}
|
||||
|
||||
HAL_MatchInfo& ReadGameSpecificTag(wpi::ArrayRef<uint8_t> data) {
|
||||
HAL_MatchInfo& ReadGameSpecificTag(wpi::span<const uint8_t> data) {
|
||||
commPacket.ReadGameSpecificMessageTag(data);
|
||||
return commPacket.matchInfo;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class AddressableLEDModel : public glass::LEDDisplayModel {
|
||||
|
||||
bool IsRunning() override { return HALSIM_GetAddressableLEDRunning(m_index); }
|
||||
|
||||
wpi::ArrayRef<Data> GetData(wpi::SmallVectorImpl<Data>&) override {
|
||||
wpi::span<const Data> GetData(wpi::SmallVectorImpl<Data>&) override {
|
||||
size_t length = HALSIM_GetAddressableLEDData(m_index, m_data);
|
||||
return {reinterpret_cast<Data*>(m_data), length};
|
||||
}
|
||||
|
||||
@@ -48,12 +48,11 @@ SequentialCommandGroup Command::BeforeStarting(
|
||||
std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) && {
|
||||
return std::move(*this).BeforeStarting(
|
||||
std::move(toRun),
|
||||
wpi::makeArrayRef(requirements.begin(), requirements.end()));
|
||||
std::move(toRun), {requirements.begin(), requirements.end()});
|
||||
}
|
||||
|
||||
SequentialCommandGroup Command::BeforeStarting(
|
||||
std::function<void()> toRun, wpi::ArrayRef<Subsystem*> requirements) && {
|
||||
std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
|
||||
std::vector<std::unique_ptr<Command>> temp;
|
||||
temp.emplace_back(
|
||||
std::make_unique<InstantCommand>(std::move(toRun), requirements));
|
||||
@@ -64,13 +63,12 @@ SequentialCommandGroup Command::BeforeStarting(
|
||||
SequentialCommandGroup Command::AndThen(
|
||||
std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) && {
|
||||
return std::move(*this).AndThen(
|
||||
std::move(toRun),
|
||||
wpi::makeArrayRef(requirements.begin(), requirements.end()));
|
||||
return std::move(*this).AndThen(std::move(toRun),
|
||||
{requirements.begin(), requirements.end()});
|
||||
}
|
||||
|
||||
SequentialCommandGroup Command::AndThen(
|
||||
std::function<void()> toRun, wpi::ArrayRef<Subsystem*> requirements) && {
|
||||
std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
|
||||
std::vector<std::unique_ptr<Command>> temp;
|
||||
temp.emplace_back(std::move(*this).TransferOwnership());
|
||||
temp.emplace_back(
|
||||
|
||||
@@ -18,7 +18,7 @@ void CommandBase::AddRequirements(
|
||||
m_requirements.insert(requirements.begin(), requirements.end());
|
||||
}
|
||||
|
||||
void CommandBase::AddRequirements(wpi::ArrayRef<Subsystem*> requirements) {
|
||||
void CommandBase::AddRequirements(wpi::span<Subsystem* const> requirements) {
|
||||
m_requirements.insert(requirements.begin(), requirements.end());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
bool CommandGroupBase::RequireUngrouped(Command& command) {
|
||||
bool CommandGroupBase::RequireUngrouped(const Command& command) {
|
||||
if (command.IsGrouped()) {
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse, "{}",
|
||||
@@ -15,8 +15,12 @@ bool CommandGroupBase::RequireUngrouped(Command& command) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandGroupBase::RequireUngrouped(const Command* command) {
|
||||
return RequireUngrouped(*command);
|
||||
}
|
||||
|
||||
bool CommandGroupBase::RequireUngrouped(
|
||||
wpi::ArrayRef<std::unique_ptr<Command>> commands) {
|
||||
wpi::span<const std::unique_ptr<Command>> commands) {
|
||||
bool allUngrouped = true;
|
||||
for (auto&& command : commands) {
|
||||
allUngrouped &= !command.get()->IsGrouped();
|
||||
@@ -30,7 +34,7 @@ bool CommandGroupBase::RequireUngrouped(
|
||||
}
|
||||
|
||||
bool CommandGroupBase::RequireUngrouped(
|
||||
std::initializer_list<Command*> commands) {
|
||||
std::initializer_list<const Command*> commands) {
|
||||
bool allUngrouped = true;
|
||||
for (auto&& command : commands) {
|
||||
allUngrouped &= !command->IsGrouped();
|
||||
|
||||
@@ -161,7 +161,7 @@ void CommandScheduler::Schedule(Command* command) {
|
||||
}
|
||||
|
||||
void CommandScheduler::Schedule(bool interruptible,
|
||||
wpi::ArrayRef<Command*> commands) {
|
||||
wpi::span<Command* const> commands) {
|
||||
for (auto command : commands) {
|
||||
Schedule(interruptible, command);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ void CommandScheduler::Schedule(bool interruptible,
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::Schedule(wpi::ArrayRef<Command*> commands) {
|
||||
void CommandScheduler::Schedule(wpi::span<Command* const> commands) {
|
||||
for (auto command : commands) {
|
||||
Schedule(true, command);
|
||||
}
|
||||
@@ -284,7 +284,8 @@ void CommandScheduler::RegisterSubsystem(
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::RegisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems) {
|
||||
void CommandScheduler::RegisterSubsystem(
|
||||
wpi::span<Subsystem* const> subsystems) {
|
||||
for (auto* subsystem : subsystems) {
|
||||
RegisterSubsystem(subsystem);
|
||||
}
|
||||
@@ -298,7 +299,7 @@ void CommandScheduler::UnregisterSubsystem(
|
||||
}
|
||||
|
||||
void CommandScheduler::UnregisterSubsystem(
|
||||
wpi::ArrayRef<Subsystem*> subsystems) {
|
||||
wpi::span<Subsystem* const> subsystems) {
|
||||
for (auto* subsystem : subsystems) {
|
||||
UnregisterSubsystem(subsystem);
|
||||
}
|
||||
@@ -340,7 +341,7 @@ void CommandScheduler::Cancel(Command* command) {
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::Cancel(wpi::ArrayRef<Command*> commands) {
|
||||
void CommandScheduler::Cancel(wpi::span<Command* const> commands) {
|
||||
for (auto command : commands) {
|
||||
Cancel(command);
|
||||
}
|
||||
@@ -370,7 +371,7 @@ units::second_t CommandScheduler::TimeSinceScheduled(
|
||||
}
|
||||
}
|
||||
bool CommandScheduler::IsScheduled(
|
||||
wpi::ArrayRef<const Command*> commands) const {
|
||||
wpi::span<const Command* const> commands) const {
|
||||
for (auto command : commands) {
|
||||
if (!IsScheduled(command)) {
|
||||
return false;
|
||||
@@ -444,8 +445,7 @@ void CommandScheduler::InitSendable(frc::SendableBuilder& builder) {
|
||||
m_impl->scheduledCommands.end()) {
|
||||
Cancel(command);
|
||||
}
|
||||
nt::NetworkTableEntry(cancelEntry)
|
||||
.SetDoubleArray(wpi::ArrayRef<double>{});
|
||||
nt::NetworkTableEntry(cancelEntry).SetDoubleArray({});
|
||||
}
|
||||
|
||||
wpi::SmallVector<std::string, 8> names;
|
||||
|
||||
@@ -21,7 +21,7 @@ FunctionalCommand::FunctionalCommand(std::function<void()> onInit,
|
||||
std::function<void()> onExecute,
|
||||
std::function<void(bool)> onEnd,
|
||||
std::function<bool()> isFinished,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_onInit{std::move(onInit)},
|
||||
m_onExecute{std::move(onExecute)},
|
||||
m_onEnd{std::move(onEnd)},
|
||||
|
||||
@@ -13,7 +13,7 @@ InstantCommand::InstantCommand(std::function<void()> toRun,
|
||||
}
|
||||
|
||||
InstantCommand::InstantCommand(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_toRun{std::move(toRun)} {
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ MecanumControllerCommand::MecanumControllerCommand(
|
||||
std::function<void(units::volt_t, units::volt_t, units::volt_t,
|
||||
units::volt_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_feedforward(feedforward),
|
||||
@@ -139,7 +139,7 @@ MecanumControllerCommand::MecanumControllerCommand(
|
||||
std::function<void(units::volt_t, units::volt_t, units::volt_t,
|
||||
units::volt_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_feedforward(feedforward),
|
||||
@@ -218,7 +218,7 @@ MecanumControllerCommand::MecanumControllerCommand(
|
||||
std::function<void(units::meters_per_second_t, units::meters_per_second_t,
|
||||
units::meters_per_second_t, units::meters_per_second_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_kinematics(kinematics),
|
||||
@@ -239,7 +239,7 @@ MecanumControllerCommand::MecanumControllerCommand(
|
||||
std::function<void(units::meters_per_second_t, units::meters_per_second_t,
|
||||
units::meters_per_second_t, units::meters_per_second_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_kinematics(kinematics),
|
||||
|
||||
@@ -15,7 +15,7 @@ NotifierCommand::NotifierCommand(std::function<void()> toRun,
|
||||
|
||||
NotifierCommand::NotifierCommand(std::function<void()> toRun,
|
||||
units::second_t period,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_toRun(toRun), m_notifier{std::move(toRun)}, m_period{period} {
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ PIDCommand::PIDCommand(PIDController controller,
|
||||
std::function<double()> measurementSource,
|
||||
std::function<double()> setpointSource,
|
||||
std::function<void(double)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_controller{std::move(controller)},
|
||||
m_measurement{std::move(measurementSource)},
|
||||
m_setpoint{std::move(setpointSource)},
|
||||
@@ -43,7 +43,7 @@ PIDCommand::PIDCommand(PIDController controller,
|
||||
PIDCommand::PIDCommand(PIDController controller,
|
||||
std::function<double()> measurementSource,
|
||||
double setpoint, std::function<void(double)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: PIDCommand(
|
||||
controller, measurementSource, [setpoint] { return setpoint; },
|
||||
useOutput, requirements) {}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
using namespace frc2;
|
||||
|
||||
PerpetualCommand::PerpetualCommand(std::unique_ptr<Command>&& command) {
|
||||
if (!CommandGroupBase::RequireUngrouped(command)) {
|
||||
if (!CommandGroupBase::RequireUngrouped(*command)) {
|
||||
return;
|
||||
}
|
||||
m_command = std::move(command);
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
ProxyScheduleCommand::ProxyScheduleCommand(wpi::ArrayRef<Command*> toSchedule) {
|
||||
ProxyScheduleCommand::ProxyScheduleCommand(
|
||||
wpi::span<Command* const> toSchedule) {
|
||||
SetInsert(m_toSchedule, toSchedule);
|
||||
}
|
||||
|
||||
ProxyScheduleCommand::ProxyScheduleCommand(Command* toSchedule) {
|
||||
SetInsert(m_toSchedule, {&toSchedule, 1});
|
||||
}
|
||||
|
||||
void ProxyScheduleCommand::Initialize() {
|
||||
for (auto* command : m_toSchedule) {
|
||||
command->Schedule();
|
||||
|
||||
@@ -39,7 +39,7 @@ RamseteCommand::RamseteCommand(
|
||||
std::function<frc::DifferentialDriveWheelSpeeds()> wheelSpeeds,
|
||||
frc2::PIDController leftController, frc2::PIDController rightController,
|
||||
std::function<void(volt_t, volt_t)> output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_controller(controller),
|
||||
@@ -75,7 +75,7 @@ RamseteCommand::RamseteCommand(
|
||||
frc::DifferentialDriveKinematics kinematics,
|
||||
std::function<void(units::meters_per_second_t, units::meters_per_second_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_controller(controller),
|
||||
|
||||
@@ -13,7 +13,7 @@ RunCommand::RunCommand(std::function<void()> toRun,
|
||||
}
|
||||
|
||||
RunCommand::RunCommand(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_toRun{std::move(toRun)} {
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,14 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
ScheduleCommand::ScheduleCommand(wpi::ArrayRef<Command*> toSchedule) {
|
||||
ScheduleCommand::ScheduleCommand(wpi::span<Command* const> toSchedule) {
|
||||
SetInsert(m_toSchedule, toSchedule);
|
||||
}
|
||||
|
||||
ScheduleCommand::ScheduleCommand(Command* toSchedule) {
|
||||
SetInsert(m_toSchedule, {&toSchedule, 1});
|
||||
}
|
||||
|
||||
void ScheduleCommand::Initialize() {
|
||||
for (auto command : m_toSchedule) {
|
||||
command->Schedule();
|
||||
|
||||
@@ -15,7 +15,7 @@ StartEndCommand::StartEndCommand(std::function<void()> onInit,
|
||||
|
||||
StartEndCommand::StartEndCommand(std::function<void()> onInit,
|
||||
std::function<void()> onEnd,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_onInit{std::move(onInit)}, m_onEnd{std::move(onEnd)} {
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ Button Button::WhenPressed(std::function<void()> toRun,
|
||||
}
|
||||
|
||||
Button Button::WhenPressed(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements) {
|
||||
wpi::span<Subsystem* const> requirements) {
|
||||
WhenActive(std::move(toRun), requirements);
|
||||
return *this;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ Button Button::WhileHeld(std::function<void()> toRun,
|
||||
}
|
||||
|
||||
Button Button::WhileHeld(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements) {
|
||||
wpi::span<Subsystem* const> requirements) {
|
||||
WhileActiveContinous(std::move(toRun), requirements);
|
||||
return *this;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ Button Button::WhenReleased(std::function<void()> toRun,
|
||||
}
|
||||
|
||||
Button Button::WhenReleased(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements) {
|
||||
wpi::span<Subsystem* const> requirements) {
|
||||
WhenInactive(std::move(toRun), requirements);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ Trigger Trigger::WhenActive(Command* command, bool interruptible) {
|
||||
|
||||
Trigger Trigger::WhenActive(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
return WhenActive(std::move(toRun), wpi::makeArrayRef(requirements.begin(),
|
||||
requirements.end()));
|
||||
return WhenActive(std::move(toRun),
|
||||
{requirements.begin(), requirements.end()});
|
||||
}
|
||||
|
||||
Trigger Trigger::WhenActive(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements) {
|
||||
wpi::span<Subsystem* const> requirements) {
|
||||
return WhenActive(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
@@ -55,13 +55,12 @@ Trigger Trigger::WhileActiveContinous(Command* command, bool interruptible) {
|
||||
Trigger Trigger::WhileActiveContinous(
|
||||
std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
return WhileActiveContinous(
|
||||
std::move(toRun),
|
||||
wpi::makeArrayRef(requirements.begin(), requirements.end()));
|
||||
return WhileActiveContinous(std::move(toRun),
|
||||
{requirements.begin(), requirements.end()});
|
||||
}
|
||||
|
||||
Trigger Trigger::WhileActiveContinous(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements) {
|
||||
Trigger Trigger::WhileActiveContinous(
|
||||
std::function<void()> toRun, wpi::span<Subsystem* const> requirements) {
|
||||
return WhileActiveContinous(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
@@ -97,12 +96,12 @@ Trigger Trigger::WhenInactive(Command* command, bool interruptible) {
|
||||
|
||||
Trigger Trigger::WhenInactive(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
return WhenInactive(std::move(toRun), wpi::makeArrayRef(requirements.begin(),
|
||||
requirements.end()));
|
||||
return WhenInactive(std::move(toRun),
|
||||
{requirements.begin(), requirements.end()});
|
||||
}
|
||||
|
||||
Trigger Trigger::WhenInactive(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements) {
|
||||
wpi::span<Subsystem* const> requirements) {
|
||||
return WhenInactive(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <string>
|
||||
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/Demangle.h>
|
||||
#include <wpi/SmallSet.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/Subsystem.h"
|
||||
|
||||
@@ -140,7 +140,7 @@ class Command {
|
||||
*/
|
||||
SequentialCommandGroup BeforeStarting(
|
||||
std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {}) &&;
|
||||
wpi::span<Subsystem* const> requirements = {}) &&;
|
||||
|
||||
/**
|
||||
* Decorates this command with a runnable to run after the command finishes.
|
||||
@@ -162,7 +162,7 @@ class Command {
|
||||
*/
|
||||
SequentialCommandGroup AndThen(
|
||||
std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {}) &&;
|
||||
wpi::span<Subsystem* const> requirements = {}) &&;
|
||||
|
||||
/**
|
||||
* Decorates this command to run perpetually, ignoring its ordinary end
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
#include <frc/smartdashboard/Sendable.h>
|
||||
#include <frc/smartdashboard/SendableHelper.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallSet.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
|
||||
@@ -35,7 +35,7 @@ class CommandBase : public Command,
|
||||
*
|
||||
* @param requirements the requirements to add
|
||||
*/
|
||||
void AddRequirements(wpi::ArrayRef<Subsystem*> requirements);
|
||||
void AddRequirements(wpi::span<Subsystem* const> requirements);
|
||||
|
||||
void AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
|
||||
@@ -25,10 +25,19 @@ class CommandGroupBase : public CommandBase {
|
||||
* Requires that the specified command not have been already allocated to a
|
||||
* CommandGroup. Reports an error if the command is already grouped.
|
||||
*
|
||||
* @param commands The command to check
|
||||
* @param command The command to check
|
||||
* @return True if all the command is ungrouped.
|
||||
*/
|
||||
static bool RequireUngrouped(Command& command);
|
||||
static bool RequireUngrouped(const Command& command);
|
||||
|
||||
/**
|
||||
* Requires that the specified command not have been already allocated to a
|
||||
* CommandGroup. Reports an error if the command is already grouped.
|
||||
*
|
||||
* @param command The command to check
|
||||
* @return True if all the command is ungrouped.
|
||||
*/
|
||||
static bool RequireUngrouped(const Command* command);
|
||||
|
||||
/**
|
||||
* Requires that the specified commands not have been already allocated to a
|
||||
@@ -37,7 +46,7 @@ class CommandGroupBase : public CommandBase {
|
||||
* @param commands The commands to check
|
||||
* @return True if all the commands are ungrouped.
|
||||
*/
|
||||
static bool RequireUngrouped(wpi::ArrayRef<std::unique_ptr<Command>>);
|
||||
static bool RequireUngrouped(wpi::span<const std::unique_ptr<Command>>);
|
||||
|
||||
/**
|
||||
* Requires that the specified commands not have been already allocated to a
|
||||
@@ -46,7 +55,7 @@ class CommandGroupBase : public CommandBase {
|
||||
* @param commands The commands to check
|
||||
* @return True if all the commands are ungrouped.
|
||||
*/
|
||||
static bool RequireUngrouped(std::initializer_list<Command*>);
|
||||
static bool RequireUngrouped(std::initializer_list<const Command*>);
|
||||
|
||||
/**
|
||||
* Adds the given commands to the command group.
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include <frc/smartdashboard/Sendable.h>
|
||||
#include <frc/smartdashboard/SendableHelper.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/FunctionExtras.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
namespace frc2 {
|
||||
class Command;
|
||||
@@ -92,7 +92,7 @@ class CommandScheduler final : public frc::Sendable,
|
||||
* @param interruptible whether the commands should be interruptible
|
||||
* @param commands the commands to schedule
|
||||
*/
|
||||
void Schedule(bool interruptible, wpi::ArrayRef<Command*> commands);
|
||||
void Schedule(bool interruptible, wpi::span<Command* const> commands);
|
||||
|
||||
/**
|
||||
* Schedules multiple commands for execution. Does nothing if the command is
|
||||
@@ -112,7 +112,7 @@ class CommandScheduler final : public frc::Sendable,
|
||||
*
|
||||
* @param commands the commands to schedule
|
||||
*/
|
||||
void Schedule(wpi::ArrayRef<Command*> commands);
|
||||
void Schedule(wpi::span<Command* const> commands);
|
||||
|
||||
/**
|
||||
* Schedules multiple commands for execution, with interruptible defaulted to
|
||||
@@ -160,10 +160,10 @@ class CommandScheduler final : public frc::Sendable,
|
||||
void UnregisterSubsystem(Subsystem* subsystem);
|
||||
|
||||
void RegisterSubsystem(std::initializer_list<Subsystem*> subsystems);
|
||||
void RegisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems);
|
||||
void RegisterSubsystem(wpi::span<Subsystem* const> subsystems);
|
||||
|
||||
void UnregisterSubsystem(std::initializer_list<Subsystem*> subsystems);
|
||||
void UnregisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems);
|
||||
void UnregisterSubsystem(wpi::span<Subsystem* const> subsystems);
|
||||
|
||||
/**
|
||||
* Sets the default command for a subsystem. Registers that subsystem if it
|
||||
@@ -223,7 +223,7 @@ class CommandScheduler final : public frc::Sendable,
|
||||
*
|
||||
* @param commands the commands to cancel
|
||||
*/
|
||||
void Cancel(wpi::ArrayRef<Command*> commands);
|
||||
void Cancel(wpi::span<Command* const> commands);
|
||||
|
||||
/**
|
||||
* Cancels commands. The scheduler will only call Command::End()
|
||||
@@ -261,7 +261,7 @@ class CommandScheduler final : public frc::Sendable,
|
||||
* @param commands the command to query
|
||||
* @return whether the command is currently scheduled
|
||||
*/
|
||||
bool IsScheduled(wpi::ArrayRef<const Command*> commands) const;
|
||||
bool IsScheduled(wpi::span<const Command* const> commands) const;
|
||||
|
||||
/**
|
||||
* Whether the given commands are running. Note that this only works on
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -52,7 +52,7 @@ class FunctionalCommand : public CommandHelper<CommandBase, FunctionalCommand> {
|
||||
std::function<void()> onExecute,
|
||||
std::function<void(bool)> onEnd,
|
||||
std::function<bool()> isFinished,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
FunctionalCommand(FunctionalCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -38,7 +38,7 @@ class InstantCommand : public CommandHelper<CommandBase, InstantCommand> {
|
||||
* @param requirements the subsystems required by this command
|
||||
*/
|
||||
explicit InstantCommand(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
InstantCommand(InstantCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <units/length.h>
|
||||
#include <units/velocity.h>
|
||||
#include <units/voltage.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
@@ -204,7 +204,7 @@ class MecanumControllerCommand
|
||||
std::function<void(units::volt_t, units::volt_t, units::volt_t,
|
||||
units::volt_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Constructs a new MecanumControllerCommand that when executed will follow
|
||||
@@ -257,7 +257,7 @@ class MecanumControllerCommand
|
||||
std::function<void(units::volt_t, units::volt_t, units::volt_t,
|
||||
units::volt_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Constructs a new MecanumControllerCommand that when executed will follow
|
||||
@@ -373,7 +373,7 @@ class MecanumControllerCommand
|
||||
units::meters_per_second_t,
|
||||
units::meters_per_second_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Constructs a new MecanumControllerCommand that when executed will follow
|
||||
@@ -413,7 +413,7 @@ class MecanumControllerCommand
|
||||
units::meters_per_second_t,
|
||||
units::meters_per_second_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <frc/Notifier.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -45,7 +45,7 @@ class NotifierCommand : public CommandHelper<CommandBase, NotifierCommand> {
|
||||
* @param requirements the subsystems required by this command
|
||||
*/
|
||||
NotifierCommand(std::function<void()> toRun, units::second_t period,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
NotifierCommand(NotifierCommand&& other);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <initializer_list>
|
||||
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -53,7 +54,7 @@ class PIDCommand : public CommandHelper<CommandBase, PIDCommand> {
|
||||
std::function<double()> measurementSource,
|
||||
std::function<double()> setpointSource,
|
||||
std::function<void(double)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Creates a new PIDCommand, which controls the given output with a
|
||||
@@ -83,7 +84,7 @@ class PIDCommand : public CommandHelper<CommandBase, PIDCommand> {
|
||||
PIDCommand(PIDController controller,
|
||||
std::function<double()> measurementSource, double setpoint,
|
||||
std::function<void(double)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
PIDCommand(PIDCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <frc/controller/ProfiledPIDController.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -70,7 +70,7 @@ class ProfiledPIDCommand
|
||||
std::function<Distance_t()> measurementSource,
|
||||
std::function<State()> goalSource,
|
||||
std::function<void(double, State)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {})
|
||||
wpi::span<Subsystem* const> requirements = {})
|
||||
: m_controller{controller},
|
||||
m_measurement{std::move(measurementSource)},
|
||||
m_goal{std::move(goalSource)},
|
||||
@@ -114,7 +114,7 @@ class ProfiledPIDCommand
|
||||
std::function<Distance_t()> measurementSource,
|
||||
std::function<Distance_t()> goalSource,
|
||||
std::function<void(double, State)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {})
|
||||
wpi::span<Subsystem* const> requirements = {})
|
||||
: ProfiledPIDCommand(
|
||||
controller, measurementSource,
|
||||
[&goalSource]() {
|
||||
@@ -153,7 +153,7 @@ class ProfiledPIDCommand
|
||||
ProfiledPIDCommand(frc::ProfiledPIDController<Distance> controller,
|
||||
std::function<Distance_t()> measurementSource, State goal,
|
||||
std::function<void(double, State)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {})
|
||||
wpi::span<Subsystem* const> requirements = {})
|
||||
: ProfiledPIDCommand(
|
||||
controller, measurementSource, [goal] { return goal; }, useOutput,
|
||||
requirements) {}
|
||||
@@ -191,7 +191,7 @@ class ProfiledPIDCommand
|
||||
std::function<Distance_t()> measurementSource,
|
||||
Distance_t goal,
|
||||
std::function<void(double, State)> useOutput,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {})
|
||||
wpi::span<Subsystem* const> requirements = {})
|
||||
: ProfiledPIDCommand(
|
||||
controller, measurementSource, [goal] { return goal; }, useOutput,
|
||||
requirements) {}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -27,7 +27,9 @@ class ProxyScheduleCommand
|
||||
*
|
||||
* @param toSchedule the commands to schedule
|
||||
*/
|
||||
explicit ProxyScheduleCommand(wpi::ArrayRef<Command*> toSchedule);
|
||||
explicit ProxyScheduleCommand(wpi::span<Command* const> toSchedule);
|
||||
|
||||
explicit ProxyScheduleCommand(Command* toSchedule);
|
||||
|
||||
ProxyScheduleCommand(ProxyScheduleCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <frc/trajectory/Trajectory.h>
|
||||
#include <units/length.h>
|
||||
#include <units/voltage.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -114,7 +114,7 @@ class RamseteCommand : public CommandHelper<CommandBase, RamseteCommand> {
|
||||
frc2::PIDController leftController,
|
||||
frc2::PIDController rightController,
|
||||
std::function<void(units::volt_t, units::volt_t)> output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Constructs a new RamseteCommand that, when executed, will follow the
|
||||
@@ -162,7 +162,7 @@ class RamseteCommand : public CommandHelper<CommandBase, RamseteCommand> {
|
||||
std::function<void(units::meters_per_second_t,
|
||||
units::meters_per_second_t)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -39,7 +39,7 @@ class RunCommand : public CommandHelper<CommandBase, RunCommand> {
|
||||
* @param requirements the subsystems to require
|
||||
*/
|
||||
explicit RunCommand(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
RunCommand(RunCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -26,7 +26,9 @@ class ScheduleCommand : public CommandHelper<CommandBase, ScheduleCommand> {
|
||||
*
|
||||
* @param toSchedule the commands to schedule
|
||||
*/
|
||||
explicit ScheduleCommand(wpi::ArrayRef<Command*> toSchedule);
|
||||
explicit ScheduleCommand(wpi::span<Command* const> toSchedule);
|
||||
|
||||
explicit ScheduleCommand(Command* toSchedule);
|
||||
|
||||
ScheduleCommand(ScheduleCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
...);
|
||||
|
||||
for (auto&& command : foo) {
|
||||
if (!CommandGroupBase::RequireUngrouped(command.second)) {
|
||||
if (!CommandGroupBase::RequireUngrouped(*command.second)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
std::vector<std::pair<Key, std::unique_ptr<Command>>>&& commands)
|
||||
: m_selector{std::move(selector)} {
|
||||
for (auto&& command : commands) {
|
||||
if (!CommandGroupBase::RequireUngrouped(command.second)) {
|
||||
if (!CommandGroupBase::RequireUngrouped(*command.second)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
namespace frc2 {
|
||||
template <typename T>
|
||||
void SetInsert(wpi::SmallVectorImpl<T*>& vector, wpi::ArrayRef<T*> toAdd) {
|
||||
void SetInsert(wpi::SmallVectorImpl<T*>& vector, wpi::span<T* const> toAdd) {
|
||||
for (auto addCommand : toAdd) {
|
||||
bool exists = false;
|
||||
for (auto existingCommand : vector) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -42,7 +42,7 @@ class StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
|
||||
* @param requirements the subsystems required by this command
|
||||
*/
|
||||
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
StartEndCommand(StartEndCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <units/length.h>
|
||||
#include <units/time.h>
|
||||
#include <units/voltage.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
@@ -167,7 +167,7 @@ class SwerveControllerCommand
|
||||
std::function<frc::Rotation2d()> desiredRotation,
|
||||
std::function<void(std::array<frc::SwerveModuleState, NumModules>)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Constructs a new SwerveControllerCommand that when executed will follow the
|
||||
@@ -205,7 +205,7 @@ class SwerveControllerCommand
|
||||
frc::ProfiledPIDController<units::radians> thetaController,
|
||||
std::function<void(std::array<frc::SwerveModuleState, NumModules>)>
|
||||
output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ SwerveControllerCommand<NumModules>::SwerveControllerCommand(
|
||||
frc::ProfiledPIDController<units::radians> thetaController,
|
||||
std::function<frc::Rotation2d()> desiredRotation,
|
||||
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_kinematics(kinematics),
|
||||
@@ -73,7 +73,7 @@ SwerveControllerCommand<NumModules>::SwerveControllerCommand(
|
||||
frc2::PIDController xController, frc2::PIDController yController,
|
||||
frc::ProfiledPIDController<units::radians> thetaController,
|
||||
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
|
||||
wpi::ArrayRef<Subsystem*> requirements)
|
||||
wpi::span<Subsystem* const> requirements)
|
||||
: m_trajectory(std::move(trajectory)),
|
||||
m_pose(std::move(pose)),
|
||||
m_kinematics(kinematics),
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <frc/Timer.h>
|
||||
#include <frc/trajectory/TrapezoidProfile.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
@@ -54,7 +54,7 @@ class TrapezoidProfileCommand
|
||||
*/
|
||||
TrapezoidProfileCommand(frc::TrapezoidProfile<Distance> profile,
|
||||
std::function<void(State)> output,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {})
|
||||
wpi::span<Subsystem* const> requirements = {})
|
||||
: m_profile(profile), m_output(output) {
|
||||
this->AddRequirements(requirements);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
|
||||
@@ -79,7 +79,7 @@ class Button : public Trigger {
|
||||
* @param requirements the required subsystems.
|
||||
*/
|
||||
Button WhenPressed(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to be started repeatedly while the button is pressed, and
|
||||
@@ -125,7 +125,7 @@ class Button : public Trigger {
|
||||
* @param requirements the required subsystems.
|
||||
*/
|
||||
Button WhileHeld(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to be started when the button is pressed, and canceled
|
||||
@@ -199,7 +199,7 @@ class Button : public Trigger {
|
||||
* @param requirements the required subsystems.
|
||||
*/
|
||||
Button WhenReleased(std::function<void()> toRun,
|
||||
wpi::ArrayRef<Subsystem*> requirements = {});
|
||||
wpi::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to start when the button is pressed, and be canceled when
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user