diff --git a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp index 19de47b9d0..5f068a15e1 100644 --- a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp +++ b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp @@ -529,7 +529,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(const std::string& host) { return AddAxisCamera("Axis Camera", host); } -cs::AxisCamera CameraServer::AddAxisCamera(wpi::ArrayRef hosts) { +cs::AxisCamera CameraServer::AddAxisCamera(wpi::span 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 hosts) { + wpi::span hosts) { cs::AxisCamera camera{name, hosts}; StartAutomaticCapture(camera); auto csShared = GetCameraServerShared(); diff --git a/cameraserver/src/main/native/include/cameraserver/CameraServer.h b/cameraserver/src/main/native/include/cameraserver/CameraServer.h index e5ce45766f..ac304fbadc 100644 --- a/cameraserver/src/main/native/include/cameraserver/CameraServer.h +++ b/cameraserver/src/main/native/include/cameraserver/CameraServer.h @@ -10,7 +10,7 @@ #include #include -#include +#include #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 hosts); + cs::AxisCamera AddAxisCamera(wpi::span 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 hosts); + wpi::span hosts); /** * Adds an Axis IP camera. diff --git a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp index 78cd988640..16452f1c74 100644 --- a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp +++ b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp @@ -88,7 +88,7 @@ int ConfigurableSourceImpl::CreateProperty( } void ConfigurableSourceImpl::SetEnumPropertyChoices( - int property, wpi::ArrayRef choices, CS_Status* status) { + int property, wpi::span 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, {}); diff --git a/cscore/src/main/native/cpp/ConfigurableSourceImpl.h b/cscore/src/main/native/cpp/ConfigurableSourceImpl.h index bfc07f903e..bb9f3ed70f 100644 --- a/cscore/src/main/native/cpp/ConfigurableSourceImpl.h +++ b/cscore/src/main/native/cpp/ConfigurableSourceImpl.h @@ -12,7 +12,7 @@ #include #include -#include +#include #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 onChange); - void SetEnumPropertyChoices(int property, wpi::ArrayRef choices, + void SetEnumPropertyChoices(int property, + wpi::span choices, CS_Status* status); private: diff --git a/cscore/src/main/native/cpp/CvSourceImpl.cpp b/cscore/src/main/native/cpp/CvSourceImpl.cpp index d05d89af70..8d5a38d8d1 100644 --- a/cscore/src/main/native/cpp/CvSourceImpl.cpp +++ b/cscore/src/main/native/cpp/CvSourceImpl.cpp @@ -140,7 +140,7 @@ CS_Property CreateSourcePropertyCallback( } void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, - wpi::ArrayRef choices, + wpi::span choices, CS_Status* status) { auto data = Instance::GetInstance().GetSource(source); if (!data || (data->kind & SourceMask) == 0) { diff --git a/cscore/src/main/native/cpp/CvSourceImpl.h b/cscore/src/main/native/cpp/CvSourceImpl.h index 1956fbe56d..fba7131b43 100644 --- a/cscore/src/main/native/cpp/CvSourceImpl.h +++ b/cscore/src/main/native/cpp/CvSourceImpl.h @@ -13,7 +13,6 @@ #include #include -#include #include "ConfigurableSourceImpl.h" #include "SourceImpl.h" diff --git a/cscore/src/main/native/cpp/HttpCameraImpl.cpp b/cscore/src/main/native/cpp/HttpCameraImpl.cpp index 5cbe9436d6..068393b88f 100644 --- a/cscore/src/main/native/cpp/HttpCameraImpl.cpp +++ b/cscore/src/main/native/cpp/HttpCameraImpl.cpp @@ -378,7 +378,7 @@ CS_HttpCameraKind HttpCameraImpl::GetKind() const { return m_kind; } -bool HttpCameraImpl::SetUrls(wpi::ArrayRef urls, +bool HttpCameraImpl::SetUrls(wpi::span urls, CS_Status* status) { std::vector 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 urls, + wpi::span 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(*data->source).GetKind(); } -void SetHttpCameraUrls(CS_Source source, wpi::ArrayRef urls, +void SetHttpCameraUrls(CS_Source source, wpi::span urls, CS_Status* status) { if (urls.empty()) { *status = CS_EMPTY_VALUE; diff --git a/cscore/src/main/native/cpp/HttpCameraImpl.h b/cscore/src/main/native/cpp/HttpCameraImpl.h index 1d375a82df..2c589362e2 100644 --- a/cscore/src/main/native/cpp/HttpCameraImpl.h +++ b/cscore/src/main/native/cpp/HttpCameraImpl.h @@ -19,6 +19,7 @@ #include #include #include +#include #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 urls, CS_Status* status); + bool SetUrls(wpi::span urls, CS_Status* status); std::vector GetUrls() const; // Property data diff --git a/cscore/src/main/native/cpp/Instance.h b/cscore/src/main/native/cpp/Instance.h index fba616353e..f84eacf4d0 100644 --- a/cscore/src/main/native/cpp/Instance.h +++ b/cscore/src/main/native/cpp/Instance.h @@ -86,18 +86,17 @@ class Instance { void DestroySource(CS_Source handle); void DestroySink(CS_Sink handle); - wpi::ArrayRef EnumerateSourceHandles( + wpi::span EnumerateSourceHandles( wpi::SmallVectorImpl& vec) { return m_sources.GetAll(vec); } - wpi::ArrayRef EnumerateSinkHandles( - wpi::SmallVectorImpl& vec) { + wpi::span EnumerateSinkHandles(wpi::SmallVectorImpl& vec) { return m_sinks.GetAll(vec); } - wpi::ArrayRef EnumerateSourceSinks( - CS_Source source, wpi::SmallVectorImpl& vec) { + wpi::span EnumerateSourceSinks(CS_Source source, + wpi::SmallVectorImpl& vec) { vec.clear(); m_sinks.ForEach([&](CS_Sink sinkHandle, const SinkData& data) { if (source == data.sourceHandle.load()) { diff --git a/cscore/src/main/native/cpp/PropertyContainer.cpp b/cscore/src/main/native/cpp/PropertyContainer.cpp index d95c06edfa..b1d3a6f793 100644 --- a/cscore/src/main/native/cpp/PropertyContainer.cpp +++ b/cscore/src/main/native/cpp/PropertyContainer.cpp @@ -27,7 +27,7 @@ int PropertyContainer::GetPropertyIndex(std::string_view name) const { return ndx; } -wpi::ArrayRef PropertyContainer::EnumerateProperties( +wpi::span PropertyContainer::EnumerateProperties( wpi::SmallVectorImpl& vec, CS_Status* status) const { if (!m_properties_cached && !CacheProperties(status)) { return {}; diff --git a/cscore/src/main/native/cpp/PropertyContainer.h b/cscore/src/main/native/cpp/PropertyContainer.h index f09ea23c7b..a00c675248 100644 --- a/cscore/src/main/native/cpp/PropertyContainer.h +++ b/cscore/src/main/native/cpp/PropertyContainer.h @@ -12,9 +12,9 @@ #include #include -#include #include #include +#include #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 EnumerateProperties(wpi::SmallVectorImpl& vec, - CS_Status* status) const; + wpi::span EnumerateProperties(wpi::SmallVectorImpl& vec, + CS_Status* status) const; CS_PropertyKind GetPropertyKind(int property) const; std::string_view GetPropertyName(int property, wpi::SmallVectorImpl& buf, diff --git a/cscore/src/main/native/cpp/RawSourceImpl.h b/cscore/src/main/native/cpp/RawSourceImpl.h index bb9a49fc67..5887ed4203 100644 --- a/cscore/src/main/native/cpp/RawSourceImpl.h +++ b/cscore/src/main/native/cpp/RawSourceImpl.h @@ -12,8 +12,6 @@ #include #include -#include - #include "ConfigurableSourceImpl.h" #include "SourceImpl.h" #include "cscore_raw.h" diff --git a/cscore/src/main/native/cpp/SourceImpl.h b/cscore/src/main/native/cpp/SourceImpl.h index 0a7839e23a..dd2e574f19 100644 --- a/cscore/src/main/native/cpp/SourceImpl.h +++ b/cscore/src/main/native/cpp/SourceImpl.h @@ -12,7 +12,6 @@ #include #include -#include #include #include #include diff --git a/cscore/src/main/native/cpp/UnlimitedHandleResource.h b/cscore/src/main/native/cpp/UnlimitedHandleResource.h index cba6399b53..f7671ae4f5 100644 --- a/cscore/src/main/native/cpp/UnlimitedHandleResource.h +++ b/cscore/src/main/native/cpp/UnlimitedHandleResource.h @@ -9,9 +9,9 @@ #include #include -#include #include #include +#include namespace cs { @@ -50,7 +50,7 @@ class UnlimitedHandleResource { std::shared_ptr Free(THandle handle); template - wpi::ArrayRef GetAll(wpi::SmallVectorImpl& vec); + wpi::span GetAll(wpi::SmallVectorImpl& vec); std::vector> FreeAll(); @@ -151,7 +151,7 @@ UnlimitedHandleResource::Free( template template -inline wpi::ArrayRef +inline wpi::span UnlimitedHandleResource::GetAll( wpi::SmallVectorImpl& vec) { ForEach([&](THandle handle, const TStruct& data) { vec.push_back(handle); }); diff --git a/cscore/src/main/native/cpp/cscore_cpp.cpp b/cscore/src/main/native/cpp/cscore_cpp.cpp index 7d3828e318..4faae795ed 100644 --- a/cscore/src/main/native/cpp/cscore_cpp.cpp +++ b/cscore/src/main/native/cpp/cscore_cpp.cpp @@ -286,13 +286,13 @@ CS_Property GetSourceProperty(CS_Source source, std::string_view name, return Handle{source, property, Handle::kProperty}; } -wpi::ArrayRef EnumerateSourceProperties( +wpi::span EnumerateSourceProperties( CS_Source source, wpi::SmallVectorImpl& vec, CS_Status* status) { auto data = Instance::GetInstance().GetSource(source); if (!data) { *status = CS_INVALID_HANDLE; - return 0; + return {}; } wpi::SmallVector properties_buf; for (auto property : @@ -398,14 +398,14 @@ std::vector EnumerateSourceVideoModes(CS_Source source, return data->source->EnumerateVideoModes(status); } -wpi::ArrayRef EnumerateSourceSinks(CS_Source source, - wpi::SmallVectorImpl& vec, - CS_Status* status) { +wpi::span EnumerateSourceSinks(CS_Source source, + wpi::SmallVectorImpl& vec, + CS_Status* status) { auto& inst = Instance::GetInstance(); auto data = inst.GetSource(source); if (!data) { *status = CS_INVALID_HANDLE; - return wpi::ArrayRef{}; + 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 EnumerateSinkProperties( +wpi::span EnumerateSinkProperties( CS_Sink sink, wpi::SmallVectorImpl& vec, CS_Status* status) { auto data = Instance::GetInstance().GetSink(sink); if (!data) { *status = CS_INVALID_HANDLE; - return 0; + return {}; } wpi::SmallVector properties_buf; for (auto property : @@ -861,13 +861,13 @@ void Shutdown() { // Utility Functions // -wpi::ArrayRef EnumerateSourceHandles( +wpi::span EnumerateSourceHandles( wpi::SmallVectorImpl& vec, CS_Status* status) { return Instance::GetInstance().EnumerateSourceHandles(vec); } -wpi::ArrayRef EnumerateSinkHandles(wpi::SmallVectorImpl& vec, - CS_Status* status) { +wpi::span EnumerateSinkHandles(wpi::SmallVectorImpl& vec, + CS_Status* status) { return Instance::GetInstance().EnumerateSinkHandles(vec); } diff --git a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp index afdf566787..8b648f8b14 100644 --- a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp +++ b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #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 arr) { +static jobjectArray MakeJObject(JNIEnv* env, + wpi::span arr) { jobjectArray jarr = env->NewObjectArray(arr.size(), videoEventCls, nullptr); if (!jarr) { return nullptr; diff --git a/cscore/src/main/native/include/cscore_cpp.h b/cscore/src/main/native/include/cscore_cpp.h index 593ad08936..8b1eab1788 100644 --- a/cscore/src/main/native/include/cscore_cpp.h +++ b/cscore/src/main/native/include/cscore_cpp.h @@ -12,8 +12,8 @@ #include #include -#include #include +#include #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 urls, + wpi::span 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 EnumerateSourceProperties( +wpi::span EnumerateSourceProperties( CS_Source source, wpi::SmallVectorImpl& 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 EnumerateSourceVideoModes(CS_Source source, CS_Status* status); -wpi::ArrayRef EnumerateSourceSinks(CS_Source source, - wpi::SmallVectorImpl& vec, - CS_Status* status); +wpi::span EnumerateSourceSinks(CS_Source source, + wpi::SmallVectorImpl& 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 urls, +void SetHttpCameraUrls(CS_Source source, wpi::span urls, CS_Status* status); std::vector 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 choices, + wpi::span 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 EnumerateSinkProperties( +wpi::span EnumerateSinkProperties( CS_Sink sink, wpi::SmallVectorImpl& 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 EnumerateUsbCameras(CS_Status* status); -wpi::ArrayRef EnumerateSourceHandles( +wpi::span EnumerateSourceHandles( wpi::SmallVectorImpl& vec, CS_Status* status); -wpi::ArrayRef EnumerateSinkHandles(wpi::SmallVectorImpl& vec, - CS_Status* status); +wpi::span EnumerateSinkHandles(wpi::SmallVectorImpl& vec, + CS_Status* status); std::string GetHostname(); diff --git a/cscore/src/main/native/include/cscore_oo.h b/cscore/src/main/native/include/cscore_oo.h index 384d5230b2..f780fcd003 100644 --- a/cscore/src/main/native/include/cscore_oo.h +++ b/cscore/src/main/native/include/cscore_oo.h @@ -11,6 +11,8 @@ #include #include +#include + #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 urls, + HttpCamera(std::string_view name, wpi::span 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 urls); + void SetUrls(wpi::span 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 HostToUrl(wpi::ArrayRef hosts); + static std::vector HostToUrl(wpi::span hosts); template static std::vector HostToUrl(std::initializer_list 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 hosts); + AxisCamera(std::string_view name, wpi::span 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 choices); + wpi::span choices); /** * Configure enum property choices. diff --git a/cscore/src/main/native/include/cscore_oo.inc b/cscore/src/main/native/include/cscore_oo.inc index 878462afdb..5037d97982 100644 --- a/cscore/src/main/native/include/cscore_oo.inc +++ b/cscore/src/main/native/include/cscore_oo.inc @@ -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 urls, + wpi::span urls, HttpCameraKind kind) { m_handle = CreateHttpCamera( name, urls, static_cast(static_cast(kind)), @@ -329,7 +329,7 @@ inline HttpCamera::HttpCameraKind HttpCamera::GetHttpCameraKind() const { static_cast(::cs::GetHttpCameraKind(m_handle, &m_status))); } -inline void HttpCamera::SetUrls(wpi::ArrayRef urls) { +inline void HttpCamera::SetUrls(wpi::span urls) { m_status = 0; ::cs::SetHttpCameraUrls(m_handle, urls, &m_status); } @@ -351,7 +351,7 @@ inline std::vector HttpCamera::GetUrls() const { } inline std::vector AxisCamera::HostToUrl( - wpi::ArrayRef hosts) { + wpi::span hosts) { std::vector 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 hosts) + wpi::span hosts) : HttpCamera(name, HostToUrl(hosts), kAxis) {} template @@ -452,7 +452,7 @@ inline VideoProperty ImageSource::CreateStringProperty(std::string_view name, } inline void ImageSource::SetEnumPropertyChoices( - const VideoProperty& property, wpi::ArrayRef choices) { + const VideoProperty& property, wpi::span choices) { m_status = 0; SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices, &m_status); } diff --git a/glass/src/lib/native/cpp/other/Field2D.cpp b/glass/src/lib/native/cpp/other/Field2D.cpp index e926019674..786d3de45b 100644 --- a/glass/src/lib/native/cpp/other/Field2D.cpp +++ b/glass/src/lib/native/cpp/other/Field2D.cpp @@ -90,7 +90,7 @@ class PopupState { SelectedTargetInfo* GetTarget() { return &m_target; } FieldObjectModel* GetInsertModel() { return m_insertModel; } - wpi::ArrayRef GetInsertPoses() const { return m_insertPoses; } + wpi::span 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 points) const; + void DrawLine(ImDrawList* drawList, wpi::span 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 points) const { + wpi::span 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 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 poses = m_target.objModel->GetPoses(); + auto posesRef = m_target.objModel->GetPoses(); + std::vector 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; diff --git a/glass/src/lib/native/include/glass/hardware/LEDDisplay.h b/glass/src/lib/native/include/glass/hardware/LEDDisplay.h index f6122080a1..c7af045897 100644 --- a/glass/src/lib/native/include/glass/hardware/LEDDisplay.h +++ b/glass/src/lib/native/include/glass/hardware/LEDDisplay.h @@ -4,8 +4,8 @@ #pragma once -#include #include +#include #include "glass/Model.h" @@ -27,7 +27,7 @@ class LEDDisplayModel : public glass::Model { virtual bool IsRunning() = 0; - virtual wpi::ArrayRef GetData(wpi::SmallVectorImpl& buf) = 0; + virtual wpi::span GetData(wpi::SmallVectorImpl& buf) = 0; }; class LEDDisplaysModel : public glass::Model { diff --git a/glass/src/lib/native/include/glass/other/Field2D.h b/glass/src/lib/native/include/glass/other/Field2D.h index c9944deff3..8c86acd702 100644 --- a/glass/src/lib/native/include/glass/other/Field2D.h +++ b/glass/src/lib/native/include/glass/other/Field2D.h @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #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 GetPoses() = 0; - virtual void SetPoses(wpi::ArrayRef poses) = 0; + virtual wpi::span GetPoses() = 0; + virtual void SetPoses(wpi::span 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; diff --git a/glass/src/lib/native/include/glass/other/StringChooser.h b/glass/src/lib/native/include/glass/other/StringChooser.h index 692eb7ca43..77f9ac2b2d 100644 --- a/glass/src/lib/native/include/glass/other/StringChooser.h +++ b/glass/src/lib/native/include/glass/other/StringChooser.h @@ -8,7 +8,7 @@ #include #include -#include +#include #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 val) = 0; + virtual void SetOptions(wpi::span val) = 0; }; void DisplayStringChooser(StringChooserModel* model); diff --git a/glass/src/libnt/native/cpp/NTCommandScheduler.cpp b/glass/src/libnt/native/cpp/NTCommandScheduler.cpp index 4d4e39394e..ccc64127be 100644 --- a/glass/src/libnt/native/cpp/NTCommandScheduler.cpp +++ b/glass/src/libnt/native/cpp/NTCommandScheduler.cpp @@ -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()); } } } diff --git a/glass/src/libnt/native/cpp/NTFMS.cpp b/glass/src/libnt/native/cpp/NTFMS.cpp index 1f54803fc7..84c1ce78cc 100644 --- a/glass/src/libnt/native/cpp/NTFMS.cpp +++ b/glass/src/libnt/native/cpp/NTFMS.cpp @@ -7,6 +7,7 @@ #include #include +#include #include using namespace glass; diff --git a/glass/src/libnt/native/cpp/NTField2D.cpp b/glass/src/libnt/native/cpp/NTField2D.cpp index 5c0c9542f5..3ce4580184 100644 --- a/glass/src/libnt/native/cpp/NTField2D.cpp +++ b/glass/src/libnt/native/cpp/NTField2D.cpp @@ -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 GetPoses() override { return m_poses; } - void SetPoses(wpi::ArrayRef poses) override; + wpi::span GetPoses() override { return m_poses; } + void SetPoses(wpi::span 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 poses) { - m_poses = poses; +void NTField2DModel::ObjectModel::SetPoses(wpi::span poses) { + m_poses.assign(poses.begin(), poses.end()); UpdateNT(); } diff --git a/glass/src/libnt/native/cpp/NTStringChooser.cpp b/glass/src/libnt/native/cpp/NTStringChooser.cpp index 47eb787ea5..e6a97fae93 100644 --- a/glass/src/libnt/native/cpp/NTStringChooser.cpp +++ b/glass/src/libnt/native/cpp/NTStringChooser.cpp @@ -35,7 +35,7 @@ void NTStringChooserModel::SetActive(std::string_view val) { nt::SetEntryValue(m_active, nt::Value::MakeString(val)); } -void NTStringChooserModel::SetOptions(wpi::ArrayRef val) { +void NTStringChooserModel::SetOptions(wpi::span 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()); } } } diff --git a/glass/src/libnt/native/cpp/NetworkTables.cpp b/glass/src/libnt/native/cpp/NetworkTables.cpp index 0e0955d3ce..596ef0a0ca 100644 --- a/glass/src/libnt/native/cpp/NetworkTables.cpp +++ b/glass/src/libnt/native/cpp/NetworkTables.cpp @@ -17,17 +17,18 @@ #include #include #include -#include #include +#include #include #include +#include #include "glass/Context.h" #include "glass/DataSource.h" using namespace glass; -static std::string BooleanArrayToString(wpi::ArrayRef in) { +static std::string BooleanArrayToString(wpi::span in) { std::string rv; wpi::raw_string_ostream os{rv}; os << '['; @@ -47,11 +48,11 @@ static std::string BooleanArrayToString(wpi::ArrayRef in) { return rv; } -static std::string DoubleArrayToString(wpi::ArrayRef in) { +static std::string DoubleArrayToString(wpi::span in) { return fmt::format("[{:.6f}]", fmt::join(in, ",")); } -static std::string StringArrayToString(wpi::ArrayRef in) { +static std::string StringArrayToString(wpi::span 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; }); diff --git a/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h b/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h index fac9f7c53a..2d806c9778 100644 --- a/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h +++ b/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h @@ -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 val) override; + void SetOptions(wpi::span val) override; void Update() override; bool Exists() override; diff --git a/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp index 52a4fb53b5..e888bd3ca9 100644 --- a/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp @@ -257,7 +257,7 @@ Java_edu_wpi_first_hal_simulation_AddressableLEDDataJNI_getData std::make_unique(HAL_kAddressableLEDMaxLength); int32_t length = HALSIM_GetAddressableLEDData(index, data.get()); return MakeJByteArray( - env, wpi::ArrayRef(reinterpret_cast(data.get()), length * 4)); + env, wpi::span(reinterpret_cast(data.get()), length * 4)); } /* diff --git a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp index 51a3f0746c..60ce0f7a77 100644 --- a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp @@ -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)); } /* diff --git a/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp index 8d43e6fa2f..c20f60729f 100644 --- a/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp +++ b/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp @@ -59,7 +59,7 @@ int32_t SpiReadAutoReceiveBufferCallbackStore::performCallback( } auto toCallbackArr = MakeJIntArray( - env, wpi::ArrayRef{buffer, static_cast(numToRead)}); + env, wpi::span{buffer, static_cast(numToRead)}); jint ret = env->CallIntMethod(m_call, sim::GetBufferCallback(), MakeJString(env, name), toCallbackArr, diff --git a/hal/src/main/native/include/hal/SimDevice.h b/hal/src/main/native/include/hal/SimDevice.h index ae319da455..7c0cf2d336 100644 --- a/hal/src/main/native/include/hal/SimDevice.h +++ b/hal/src/main/native/include/hal/SimDevice.h @@ -9,7 +9,7 @@ #ifdef __cplusplus #include -#include +#include #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 options, int32_t initialValue) { + wpi::span options, + int32_t initialValue) { return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(), const_cast(options.data()), initialValue); @@ -884,8 +885,8 @@ class SimDevice { * @return simulated enum value object */ SimEnum CreateEnumDouble(const char* name, int32_t direction, - wpi::ArrayRef options, - wpi::ArrayRef optionValues, + wpi::span options, + wpi::span optionValues, int32_t initialValue) { if (options.size() != optionValues.size()) { return {}; diff --git a/ntcore/src/main/native/cpp/Dispatcher.cpp b/ntcore/src/main/native/cpp/Dispatcher.cpp index f0416f54ed..84d9698cf9 100644 --- a/ntcore/src/main/native/cpp/Dispatcher.cpp +++ b/ntcore/src/main/native/cpp/Dispatcher.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,7 @@ void Dispatcher::SetServer(const char* server_name, unsigned int port) { } void Dispatcher::SetServer( - wpi::ArrayRef> servers) { + wpi::span> servers) { wpi::SmallVector, 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()> get_msg, - std::function>)> send_msgs) { + std::function>)> 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()> get_msg, - std::function>)> send_msgs) { + std::function>)> 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; } diff --git a/ntcore/src/main/native/cpp/Dispatcher.h b/ntcore/src/main/native/cpp/Dispatcher.h index c18b0b4caf..a2a742531e 100644 --- a/ntcore/src/main/native/cpp/Dispatcher.h +++ b/ntcore/src/main/native/cpp/Dispatcher.h @@ -16,6 +16,7 @@ #include #include +#include #include "IDispatcher.h" #include "INetworkConnection.h" @@ -77,11 +78,11 @@ class DispatcherBase : public IDispatcher { bool ClientHandshake( NetworkConnection& conn, std::function()> get_msg, - std::function>)> send_msgs); + std::function>)> send_msgs); bool ServerHandshake( NetworkConnection& conn, std::function()> get_msg, - std::function>)> send_msgs); + std::function>)> 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> servers); + wpi::span> servers); void SetServerTeam(unsigned int team, unsigned int port); void SetServerOverride(const char* server_name, unsigned int port); diff --git a/ntcore/src/main/native/cpp/IStorage.h b/ntcore/src/main/native/cpp/IStorage.h index d547d51dff..795d032970 100644 --- a/ntcore/src/main/native/cpp/IStorage.h +++ b/ntcore/src/main/native/cpp/IStorage.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include "Message.h" #include "ntcore_cpp.h" @@ -45,7 +45,7 @@ class IStorage { INetworkConnection& conn, std::vector>* msgs) = 0; virtual void ApplyInitialAssignments( - INetworkConnection& conn, wpi::ArrayRef> msgs, + INetworkConnection& conn, wpi::span> msgs, bool new_server, std::vector>* out_msgs) = 0; // Filename-based save/load functions. Used both by periodic saves and diff --git a/ntcore/src/main/native/cpp/NetworkConnection.cpp b/ntcore/src/main/native/cpp/NetworkConnection.cpp index ffc45c5b65..838eecbc45 100644 --- a/ntcore/src/main/native/cpp/NetworkConnection.cpp +++ b/ntcore/src/main/native/cpp/NetworkConnection.cpp @@ -162,8 +162,9 @@ void NetworkConnection::ReadThreadMain() { } return msg; }, - [&](wpi::ArrayRef> msgs) { - m_outgoing.emplace(msgs); + [&](auto msgs) { + m_outgoing.emplace(std::vector>( + msgs.begin(), msgs.end())); })) { set_state(kDead); m_active = false; diff --git a/ntcore/src/main/native/cpp/NetworkConnection.h b/ntcore/src/main/native/cpp/NetworkConnection.h index 412b91702f..e023320caf 100644 --- a/ntcore/src/main/native/cpp/NetworkConnection.h +++ b/ntcore/src/main/native/cpp/NetworkConnection.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "INetworkConnection.h" #include "Message.h" @@ -38,7 +39,7 @@ class NetworkConnection : public INetworkConnection { typedef std::function()> get_msg, - std::function>)> send_msgs)> + std::function>)> send_msgs)> HandshakeFunc; using ProcessIncomingFunc = std::function, NetworkConnection*)>; diff --git a/ntcore/src/main/native/cpp/Storage.cpp b/ntcore/src/main/native/cpp/Storage.cpp index 9e8bd83c06..dadc3f6637 100644 --- a/ntcore/src/main/native/cpp/Storage.cpp +++ b/ntcore/src/main/native/cpp/Storage.cpp @@ -410,7 +410,7 @@ void Storage::GetInitialAssignments( } void Storage::ApplyInitialAssignments( - INetworkConnection& conn, wpi::ArrayRef> msgs, + INetworkConnection& conn, wpi::span> msgs, bool /*new_server*/, std::vector>* out_msgs) { std::unique_lock lock(m_mutex); if (m_server) { diff --git a/ntcore/src/main/native/cpp/Storage.h b/ntcore/src/main/native/cpp/Storage.h index 3ca834cdb2..add675ebfd 100644 --- a/ntcore/src/main/native/cpp/Storage.h +++ b/ntcore/src/main/native/cpp/Storage.h @@ -21,6 +21,7 @@ #include #include #include +#include #include "IStorage.h" #include "Message.h" @@ -67,7 +68,7 @@ class Storage : public IStorage { INetworkConnection& conn, std::vector>* msgs) override; void ApplyInitialAssignments( - INetworkConnection& conn, wpi::ArrayRef> msgs, + INetworkConnection& conn, wpi::span> msgs, bool new_server, std::vector>* out_msgs) override; diff --git a/ntcore/src/main/native/cpp/Storage_save.cpp b/ntcore/src/main/native/cpp/Storage_save.cpp index 26e0cad983..6d5db9f83a 100644 --- a/ntcore/src/main/native/cpp/Storage_save.cpp +++ b/ntcore/src/main/native/cpp/Storage_save.cpp @@ -25,12 +25,12 @@ class SavePersistentImpl { explicit SavePersistentImpl(wpi::raw_ostream& os) : m_os(os) {} - void Save(wpi::ArrayRef entries); + void Save(wpi::span entries); private: void WriteString(std::string_view str); void WriteHeader(); - void WriteEntries(wpi::ArrayRef entries); + void WriteEntries(wpi::span 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 entries) { +void SavePersistentImpl::Save(wpi::span entries) { WriteHeader(); WriteEntries(entries); } @@ -81,7 +81,7 @@ void SavePersistentImpl::WriteHeader() { m_os << "[NetworkTables Storage 3.0]\n"; } -void SavePersistentImpl::WriteEntries(wpi::ArrayRef entries) { +void SavePersistentImpl::WriteEntries(wpi::span entries) { for (auto& i : entries) { if (!i.second) { continue; diff --git a/ntcore/src/main/native/cpp/Value.cpp b/ntcore/src/main/native/cpp/Value.cpp index 96af67a551..e0d65c998b 100644 --- a/ntcore/src/main/native/cpp/Value.cpp +++ b/ntcore/src/main/native/cpp/Value.cpp @@ -4,6 +4,8 @@ #include +#include + #include #include @@ -43,7 +45,7 @@ Value::~Value() { } } -std::shared_ptr Value::MakeBooleanArray(wpi::ArrayRef value, +std::shared_ptr Value::MakeBooleanArray(wpi::span value, uint64_t time) { auto val = std::make_shared(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::MakeBooleanArray(wpi::ArrayRef value, return val; } -std::shared_ptr Value::MakeBooleanArray(wpi::ArrayRef value, +std::shared_ptr Value::MakeBooleanArray(wpi::span value, uint64_t time) { auto val = std::make_shared(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::MakeBooleanArray(wpi::ArrayRef value, return val; } -std::shared_ptr Value::MakeDoubleArray(wpi::ArrayRef value, +std::shared_ptr Value::MakeDoubleArray(wpi::span value, uint64_t time) { auto val = std::make_shared(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::MakeDoubleArray(wpi::ArrayRef value, return val; } -std::shared_ptr Value::MakeStringArray(wpi::ArrayRef value, - uint64_t time) { +std::shared_ptr Value::MakeStringArray( + wpi::span value, uint64_t time) { auto val = std::make_shared(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 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( - 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( - 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 v; v.reserve(value.data.arr_string.size); diff --git a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp index b3f943c0fa..6c7ed82683 100644 --- a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp +++ b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp @@ -139,7 +139,7 @@ std::shared_ptr FromJavaBooleanArray(JNIEnv* env, jbooleanArray jarr, if (!ref) { return nullptr; } - wpi::ArrayRef elements{ref}; + wpi::span elements{ref}; size_t len = elements.size(); std::vector arr; arr.reserve(len); @@ -306,8 +306,9 @@ static jobject MakeJObject(JNIEnv* env, jobject inst, static_cast(answer.call), name.obj(), params.obj(), conn.obj()); } -static jobjectArray MakeJObject(JNIEnv* env, jobject inst, - wpi::ArrayRef arr) { +static jobjectArray MakeJObject( + JNIEnv* env, jobject inst, + wpi::span 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 arr) { + wpi::span 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 arr) { + wpi::span 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 arr) { + wpi::span arr) { jobjectArray jarr = env->NewObjectArray(arr.size(), rpcAnswerCls, nullptr); if (!jarr) { return nullptr; diff --git a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp index 25bd809f02..017d0af2ed 100644 --- a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp +++ b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp @@ -288,47 +288,47 @@ bool NetworkTable::GetBoolean(std::string_view key, bool defaultValue) const { } bool NetworkTable::PutBooleanArray(std::string_view key, - wpi::ArrayRef value) { + wpi::span value) { return GetEntry(key).SetBooleanArray(value); } bool NetworkTable::SetDefaultBooleanArray(std::string_view key, - wpi::ArrayRef defaultValue) { + wpi::span defaultValue) { return GetEntry(key).SetDefaultBooleanArray(defaultValue); } std::vector NetworkTable::GetBooleanArray( - std::string_view key, wpi::ArrayRef defaultValue) const { + std::string_view key, wpi::span defaultValue) const { return GetEntry(key).GetBooleanArray(defaultValue); } bool NetworkTable::PutNumberArray(std::string_view key, - wpi::ArrayRef value) { + wpi::span value) { return GetEntry(key).SetDoubleArray(value); } bool NetworkTable::SetDefaultNumberArray(std::string_view key, - wpi::ArrayRef defaultValue) { + wpi::span defaultValue) { return GetEntry(key).SetDefaultDoubleArray(defaultValue); } std::vector NetworkTable::GetNumberArray( - std::string_view key, wpi::ArrayRef defaultValue) const { + std::string_view key, wpi::span defaultValue) const { return GetEntry(key).GetDoubleArray(defaultValue); } bool NetworkTable::PutStringArray(std::string_view key, - wpi::ArrayRef value) { + wpi::span value) { return GetEntry(key).SetStringArray(value); } bool NetworkTable::SetDefaultStringArray( - std::string_view key, wpi::ArrayRef defaultValue) { + std::string_view key, wpi::span defaultValue) { return GetEntry(key).SetDefaultStringArray(defaultValue); } std::vector NetworkTable::GetStringArray( - std::string_view key, wpi::ArrayRef defaultValue) const { + std::string_view key, wpi::span defaultValue) const { return GetEntry(key).GetStringArray(defaultValue); } diff --git a/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp b/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp index 4ff8f7551b..4566b30529 100644 --- a/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp +++ b/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp @@ -23,8 +23,8 @@ std::shared_ptr NetworkTableInstance::GetTable( } } -void NetworkTableInstance::StartClient(wpi::ArrayRef servers, - unsigned int port) { +void NetworkTableInstance::StartClient( + wpi::span servers, unsigned int port) { wpi::SmallVector, 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 servers, StartClient(server_ports); } -void NetworkTableInstance::SetServer(wpi::ArrayRef servers, +void NetworkTableInstance::SetServer(wpi::span servers, unsigned int port) { wpi::SmallVector, 8> server_ports; for (const auto& server : servers) { diff --git a/ntcore/src/main/native/cpp/ntcore_c.cpp b/ntcore/src/main/native/cpp/ntcore_c.cpp index ae48b1cce6..c5a8e497c5 100644 --- a/ntcore/src/main/native/cpp/ntcore_c.cpp +++ b/ntcore/src/main/native/cpp/ntcore_c.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -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(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, diff --git a/ntcore/src/main/native/cpp/ntcore_cpp.cpp b/ntcore/src/main/native/cpp/ntcore_cpp.cpp index 619e996941..ae85e46b26 100644 --- a/ntcore/src/main/native/cpp/ntcore_cpp.cpp +++ b/ntcore/src/main/native/cpp/ntcore_cpp.cpp @@ -792,7 +792,7 @@ bool UnpackRpcDefinition(std::string_view packed, RpcDefinition* def) { return true; } -std::string PackRpcValues(wpi::ArrayRef> values) { +std::string PackRpcValues(wpi::span> values) { WireEncoder enc(0x0300); for (auto& value : values) { enc.WriteValue(*value); @@ -801,7 +801,7 @@ std::string PackRpcValues(wpi::ArrayRef> values) { } std::vector> UnpackRpcValues( - std::string_view packed, wpi::ArrayRef types) { + std::string_view packed, wpi::span 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> servers) { + wpi::span> 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> servers) { + wpi::span> servers) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { return; diff --git a/ntcore/src/main/native/cpp/ntcore_test.cpp b/ntcore/src/main/native/cpp/ntcore_test.cpp index 00d07f7b27..64bde688db 100644 --- a/ntcore/src/main/native/cpp/ntcore_test.cpp +++ b/ntcore/src/main/native/cpp/ntcore_test.cpp @@ -4,6 +4,8 @@ #include "ntcore_test.h" +#include + #include #include "Value_internal.h" diff --git a/ntcore/src/main/native/include/networktables/NetworkTable.h b/ntcore/src/main/native/include/networktables/NetworkTable.h index 7ac4e7eb14..3a04e45222 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTable.h +++ b/ntcore/src/main/native/include/networktables/NetworkTable.h @@ -12,9 +12,9 @@ #include #include -#include #include #include +#include #include "networktables/NetworkTableEntry.h" #include "networktables/TableEntryListener.h" @@ -360,7 +360,7 @@ class NetworkTable final { * std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - bool PutBooleanArray(std::string_view key, wpi::ArrayRef value); + bool PutBooleanArray(std::string_view key, wpi::span 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 defaultValue); + wpi::span 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 GetBooleanArray(std::string_view key, - wpi::ArrayRef defaultValue) const; + wpi::span 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 value); + bool PutNumberArray(std::string_view key, wpi::span 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 defaultValue); + wpi::span 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 GetNumberArray(std::string_view key, - wpi::ArrayRef defaultValue) const; + std::vector GetNumberArray( + std::string_view key, wpi::span 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 value); + bool PutStringArray(std::string_view key, wpi::span 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 defaultValue); + wpi::span 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 GetStringArray( - std::string_view key, wpi::ArrayRef defaultValue) const; + std::string_view key, wpi::span defaultValue) const; /** * Put a raw value (byte array) in the table diff --git a/ntcore/src/main/native/include/networktables/NetworkTableEntry.h b/ntcore/src/main/native/include/networktables/NetworkTableEntry.h index 7774fa2157..ff717ae583 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableEntry.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableEntry.h @@ -13,6 +13,8 @@ #include #include +#include + #include "networktables/NetworkTableType.h" #include "networktables/NetworkTableValue.h" #include "networktables/RpcCall.h" @@ -166,7 +168,7 @@ class NetworkTableEntry final { * because std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - std::vector GetBooleanArray(wpi::ArrayRef defaultValue) const; + std::vector GetBooleanArray(wpi::span 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 GetDoubleArray(wpi::ArrayRef defaultValue) const; + std::vector GetDoubleArray( + wpi::span 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 GetStringArray( - wpi::ArrayRef defaultValue) const; + wpi::span 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 defaultValue); + bool SetDefaultBooleanArray(wpi::span 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 defaultValue); + bool SetDefaultDoubleArray(wpi::span 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 defaultValue); + bool SetDefaultStringArray(wpi::span 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 value); + bool SetBooleanArray(wpi::span 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 value); + bool SetBooleanArray(wpi::span 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 value); + bool SetDoubleArray(wpi::span 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 value); + bool SetStringArray(wpi::span value); /** * Sets the entry's value. @@ -474,7 +477,7 @@ class NetworkTableEntry final { * * @param value the value to set */ - void ForceSetBooleanArray(wpi::ArrayRef value); + void ForceSetBooleanArray(wpi::span 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 value); + void ForceSetBooleanArray(wpi::span 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 value); + void ForceSetDoubleArray(wpi::span 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 value); + void ForceSetStringArray(wpi::span value); /** * Sets the entry's value. If the value is of different type, the type is diff --git a/ntcore/src/main/native/include/networktables/NetworkTableEntry.inc b/ntcore/src/main/native/include/networktables/NetworkTableEntry.inc index 00082b3961..e7deb51733 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableEntry.inc +++ b/ntcore/src/main/native/include/networktables/NetworkTableEntry.inc @@ -86,48 +86,48 @@ inline std::string NetworkTableEntry::GetRaw( } inline std::vector NetworkTableEntry::GetBooleanArray( - wpi::ArrayRef defaultValue) const { + wpi::span 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 NetworkTableEntry::GetBooleanArray( std::initializer_list defaultValue) const { - return GetBooleanArray( - wpi::makeArrayRef(defaultValue.begin(), defaultValue.end())); + return GetBooleanArray({defaultValue.begin(), defaultValue.end()}); } inline std::vector NetworkTableEntry::GetDoubleArray( - wpi::ArrayRef defaultValue) const { + wpi::span 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 NetworkTableEntry::GetDoubleArray( std::initializer_list defaultValue) const { - return GetDoubleArray( - wpi::makeArrayRef(defaultValue.begin(), defaultValue.end())); + return GetDoubleArray({defaultValue.begin(), defaultValue.end()}); } inline std::vector NetworkTableEntry::GetStringArray( - wpi::ArrayRef defaultValue) const { + wpi::span 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 NetworkTableEntry::GetStringArray( std::initializer_list defaultValue) const { - return GetStringArray( - wpi::makeArrayRef(defaultValue.begin(), defaultValue.end())); + return GetStringArray({defaultValue.begin(), defaultValue.end()}); } inline bool NetworkTableEntry::SetDefaultValue(std::shared_ptr value) { @@ -151,7 +151,7 @@ inline bool NetworkTableEntry::SetDefaultRaw(std::string_view defaultValue) { } inline bool NetworkTableEntry::SetDefaultBooleanArray( - wpi::ArrayRef defaultValue) { + wpi::span defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeBooleanArray(defaultValue)); } @@ -161,7 +161,7 @@ inline bool NetworkTableEntry::SetDefaultBooleanArray( } inline bool NetworkTableEntry::SetDefaultDoubleArray( - wpi::ArrayRef defaultValue) { + wpi::span defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeDoubleArray(defaultValue)); } @@ -171,7 +171,7 @@ inline bool NetworkTableEntry::SetDefaultDoubleArray( } inline bool NetworkTableEntry::SetDefaultStringArray( - wpi::ArrayRef defaultValue) { + wpi::span 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 value) { +inline bool NetworkTableEntry::SetBooleanArray(wpi::span 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 value) { +inline bool NetworkTableEntry::SetBooleanArray(wpi::span 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 value) { +inline bool NetworkTableEntry::SetDoubleArray(wpi::span value) { return SetEntryValue(m_handle, Value::MakeDoubleArray(value)); } @@ -228,7 +228,7 @@ inline bool NetworkTableEntry::SetDoubleArray( } inline bool NetworkTableEntry::SetStringArray( - wpi::ArrayRef value) { + wpi::span 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 value) { +inline void NetworkTableEntry::ForceSetBooleanArray( + wpi::span 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 value) { +inline void NetworkTableEntry::ForceSetBooleanArray( + wpi::span value) { SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value)); } @@ -276,7 +278,7 @@ inline void NetworkTableEntry::ForceSetBooleanArray( } inline void NetworkTableEntry::ForceSetDoubleArray( - wpi::ArrayRef value) { + wpi::span value) { SetEntryTypeValue(m_handle, Value::MakeDoubleArray(value)); } @@ -286,7 +288,7 @@ inline void NetworkTableEntry::ForceSetDoubleArray( } inline void NetworkTableEntry::ForceSetStringArray( - wpi::ArrayRef value) { + wpi::span value) { SetEntryTypeValue(m_handle, Value::MakeStringArray(value)); } diff --git a/ntcore/src/main/native/include/networktables/NetworkTableInstance.h b/ntcore/src/main/native/include/networktables/NetworkTableInstance.h index 3f7f247ac7..f91efa0857 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableInstance.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableInstance.h @@ -12,7 +12,7 @@ #include #include -#include +#include #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> servers); + wpi::span> 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 servers, + void StartClient(wpi::span 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> servers); + wpi::span> 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 servers, + void SetServer(wpi::span servers, unsigned int port = kDefaultPort); /** diff --git a/ntcore/src/main/native/include/networktables/NetworkTableInstance.inc b/ntcore/src/main/native/include/networktables/NetworkTableInstance.inc index 9bb5399d8a..5cb7be0aac 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableInstance.inc +++ b/ntcore/src/main/native/include/networktables/NetworkTableInstance.inc @@ -117,7 +117,7 @@ inline void NetworkTableInstance::StartClient(const char* server_name, } inline void NetworkTableInstance::StartClient( - wpi::ArrayRef> servers) { + wpi::span> servers) { ::nt::StartClient(m_handle, servers); } @@ -136,7 +136,7 @@ inline void NetworkTableInstance::SetServer(const char* server_name, } inline void NetworkTableInstance::SetServer( - wpi::ArrayRef> servers) { + wpi::span> servers) { ::nt::SetServer(m_handle, servers); } diff --git a/ntcore/src/main/native/include/networktables/NetworkTableValue.h b/ntcore/src/main/native/include/networktables/NetworkTableValue.h index acc51ad2b9..c8f73a19f3 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableValue.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableValue.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include "ntcore_c.h" @@ -192,10 +192,9 @@ class Value final { * * @return The boolean array value. */ - wpi::ArrayRef GetBooleanArray() const { + wpi::span GetBooleanArray() const { assert(m_val.type == NT_BOOLEAN_ARRAY); - return wpi::ArrayRef(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 GetDoubleArray() const { + wpi::span GetDoubleArray() const { assert(m_val.type == NT_DOUBLE_ARRAY); - return wpi::ArrayRef(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 GetStringArray() const { + wpi::span 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 MakeBooleanArray(wpi::ArrayRef value, + static std::shared_ptr MakeBooleanArray(wpi::span value, uint64_t time = 0); /** @@ -379,8 +377,7 @@ class Value final { */ static std::shared_ptr MakeBooleanArray( std::initializer_list 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 MakeBooleanArray(wpi::ArrayRef value, + static std::shared_ptr MakeBooleanArray(wpi::span value, uint64_t time = 0); /** @@ -404,8 +401,7 @@ class Value final { */ static std::shared_ptr MakeBooleanArray( std::initializer_list 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 MakeDoubleArray(wpi::ArrayRef value, + static std::shared_ptr MakeDoubleArray(wpi::span value, uint64_t time = 0); /** @@ -429,7 +425,7 @@ class Value final { */ static std::shared_ptr MakeDoubleArray( std::initializer_list 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 MakeStringArray( - wpi::ArrayRef value, uint64_t time = 0); + wpi::span value, uint64_t time = 0); /** * Creates a string array entry value. @@ -453,7 +449,7 @@ class Value final { */ static std::shared_ptr MakeStringArray( std::initializer_list value, uint64_t time = 0) { - return MakeStringArray(wpi::makeArrayRef(value.begin(), value.end()), time); + return MakeStringArray(wpi::span(value.begin(), value.end()), time); } /** diff --git a/ntcore/src/main/native/include/ntcore_cpp.h b/ntcore/src/main/native/include/ntcore_cpp.h index 2bc517a6d7..8126b80942 100644 --- a/ntcore/src/main/native/include/ntcore_cpp.h +++ b/ntcore/src/main/native/include/ntcore_cpp.h @@ -16,7 +16,7 @@ #include #include -#include +#include #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> values); +std::string PackRpcValues(wpi::span> values); /** * Unpack RPC values as required for RPC version 1 definition messages. @@ -965,7 +965,7 @@ std::string PackRpcValues(wpi::ArrayRef> values); * @return Array of values. */ std::vector> UnpackRpcValues( - std::string_view packed, wpi::ArrayRef types); + std::string_view packed, wpi::span types); /** @} */ @@ -1050,7 +1050,7 @@ void StartClient(NT_Inst inst, const char* server_name, unsigned int port); */ void StartClient( NT_Inst inst, - wpi::ArrayRef> servers); + wpi::span> 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> servers); + wpi::span> servers); /** * Sets server addresses and port for client (without restarting client). diff --git a/ntcore/src/test/native/cpp/ValueTest.cpp b/ntcore/src/test/native/cpp/ValueTest.cpp index 271f7b67ae..d28611cd56 100644 --- a/ntcore/src/test/native/cpp/ValueTest.cpp +++ b/ntcore/src/test/native/cpp/ValueTest.cpp @@ -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 #include #include "TestPrinters.h" @@ -11,6 +12,16 @@ using namespace std::string_view_literals; +namespace wpi { +template +inline bool operator==(span lhs, span 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 vec{1, 0, 1}; auto v = Value::MakeBooleanArray(vec); ASSERT_EQ(NT_BOOLEAN_ARRAY, v->type()); - ASSERT_EQ(wpi::ArrayRef(vec), v->GetBooleanArray()); + ASSERT_EQ(wpi::span(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(vec), v->GetBooleanArray()); + ASSERT_EQ(wpi::span(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(vec), v->GetBooleanArray()); + ASSERT_EQ(wpi::span(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 vec{0.5, 0.25, 0.5}; auto v = Value::MakeDoubleArray(vec); ASSERT_EQ(NT_DOUBLE_ARRAY, v->type()); - ASSERT_EQ(wpi::ArrayRef(vec), v->GetDoubleArray()); + ASSERT_EQ(wpi::span(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(vec), v->GetDoubleArray()); + ASSERT_EQ(wpi::span(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(vec), v->GetDoubleArray()); + ASSERT_EQ(wpi::span(vec), v->GetDoubleArray()); ConvertToC(*v, &cv); ASSERT_EQ(NT_DOUBLE_ARRAY, cv.type); ASSERT_EQ(2u, cv.data.arr_double.size); diff --git a/simulation/halsim_ds_socket/src/main/native/cpp/DSCommPacket.cpp b/simulation/halsim_ds_socket/src/main/native/cpp/DSCommPacket.cpp index aeaf5e1101..9088bd7ee8 100644 --- a/simulation/halsim_ds_socket/src/main/native/cpp/DSCommPacket.cpp +++ b/simulation/halsim_ds_socket/src/main/native/cpp/DSCommPacket.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include using namespace halsim; @@ -45,7 +45,7 @@ void DSCommPacket::SetAlliance(uint8_t station_code) { m_alliance_station = static_cast(station_code); } -void DSCommPacket::ReadMatchtimeTag(wpi::ArrayRef tagData) { +void DSCommPacket::ReadMatchtimeTag(wpi::span tagData) { if (tagData.size() < 6) { return; } @@ -63,7 +63,7 @@ void DSCommPacket::ReadMatchtimeTag(wpi::ArrayRef tagData) { m_match_time = matchTime; } -void DSCommPacket::ReadJoystickTag(wpi::ArrayRef dataInput, +void DSCommPacket::ReadJoystickTag(wpi::span dataInput, int index) { DSCommJoystickPacket& stick = m_joystick_packets[index]; stick.ResetUdp(); @@ -72,7 +72,7 @@ void DSCommPacket::ReadJoystickTag(wpi::ArrayRef 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 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 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 dataInput, /*---------------------------------------------------------------------------- ** Communication methods **--------------------------------------------------------------------------*/ -void DSCommPacket::DecodeTCP(wpi::ArrayRef packet) { +void DSCommPacket::DecodeTCP(wpi::span 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 packet) { ReadNewMatchInfoTag(tagPacket); break; } - packet = packet.slice(tagLength + 2); + packet = packet.subspan(tagLength + 2); } } -void DSCommPacket::DecodeUDP(wpi::ArrayRef packet) { +void DSCommPacket::DecodeUDP(wpi::span packet) { if (packet.size() < 6) { return; } @@ -154,14 +154,14 @@ void DSCommPacket::DecodeUDP(wpi::ArrayRef 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 packet) { ReadMatchtimeTag(tagPacket); break; } - packet = packet.slice(tagLength + 1); + packet = packet.subspan(tagLength + 1); } } -void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef data) { +void DSCommPacket::ReadNewMatchInfoTag(wpi::span data) { // Size 2 bytes, tag 1 byte if (data.size() <= 3) { return; @@ -190,7 +190,7 @@ void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef 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 data) { HALSIM_SetMatchInfo(&matchInfo); } -void DSCommPacket::ReadGameSpecificMessageTag(wpi::ArrayRef data) { +void DSCommPacket::ReadGameSpecificMessageTag(wpi::span data) { // Size 2 bytes, tag 1 byte if (data.size() <= 3) { return; @@ -220,11 +220,11 @@ void DSCommPacket::ReadGameSpecificMessageTag(wpi::ArrayRef data) { HALSIM_SetMatchInfo(&matchInfo); } -void DSCommPacket::ReadJoystickDescriptionTag(wpi::ArrayRef data) { +void DSCommPacket::ReadJoystickDescriptionTag(wpi::span 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 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]; diff --git a/simulation/halsim_ds_socket/src/main/native/cpp/main.cpp b/simulation/halsim_ds_socket/src/main/native/cpp/main.cpp index c9fa585334..799cdd9f95 100644 --- a/simulation/halsim_ds_socket/src/main/native/cpp/main.cpp +++ b/simulation/halsim_ds_socket/src/main/native/cpp/main.cpp @@ -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{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(); - ds->DecodeUDP( - wpi::ArrayRef{reinterpret_cast(buf.base), len}); + ds->DecodeUDP({reinterpret_cast(buf.base), len}); struct sockaddr_in outAddr; std::memcpy(&outAddr, &recSock, sizeof(sockaddr_in)); diff --git a/simulation/halsim_ds_socket/src/main/native/include/DSCommPacket.h b/simulation/halsim_ds_socket/src/main/native/include/DSCommPacket.h index 66b341961d..1285711bfe 100644 --- a/simulation/halsim_ds_socket/src/main/native/include/DSCommPacket.h +++ b/simulation/halsim_ds_socket/src/main/native/include/DSCommPacket.h @@ -8,8 +8,8 @@ #include #include -#include #include +#include class DSCommPacketTest; @@ -20,8 +20,8 @@ class DSCommPacket { public: DSCommPacket(void); - void DecodeTCP(wpi::ArrayRef packet); - void DecodeUDP(wpi::ArrayRef packet); + void DecodeTCP(wpi::span packet); + void DecodeUDP(wpi::span 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 tagData); - void ReadJoystickTag(wpi::ArrayRef data, int index); - void ReadNewMatchInfoTag(wpi::ArrayRef data); - void ReadGameSpecificMessageTag(wpi::ArrayRef data); - void ReadJoystickDescriptionTag(wpi::ArrayRef data); + void ReadMatchtimeTag(wpi::span tagData); + void ReadJoystickTag(wpi::span data, int index); + void ReadNewMatchInfoTag(wpi::span data); + void ReadGameSpecificMessageTag(wpi::span data); + void ReadJoystickDescriptionTag(wpi::span data); uint8_t m_hi; uint8_t m_lo; diff --git a/simulation/halsim_ds_socket/src/test/native/cpp/DSCommPacketTest.cpp b/simulation/halsim_ds_socket/src/test/native/cpp/DSCommPacketTest.cpp index 1425ac082d..84df27cc17 100644 --- a/simulation/halsim_ds_socket/src/test/native/cpp/DSCommPacketTest.cpp +++ b/simulation/halsim_ds_socket/src/test/native/cpp/DSCommPacketTest.cpp @@ -11,23 +11,24 @@ class DSCommPacketTest : public ::testing::Test { void SendJoysticks() { commPacket.SendJoysticks(); } - halsim::DSCommJoystickPacket& ReadJoystickTag(wpi::ArrayRef data, + halsim::DSCommJoystickPacket& ReadJoystickTag(wpi::span data, int index) { commPacket.ReadJoystickTag(data, index); return commPacket.m_joystick_packets[index]; } - halsim::DSCommJoystickPacket& ReadDescriptorTag(wpi::ArrayRef data) { + halsim::DSCommJoystickPacket& ReadDescriptorTag( + wpi::span data) { commPacket.ReadJoystickDescriptionTag(data); return commPacket.m_joystick_packets[data[3]]; } - HAL_MatchInfo& ReadNewMatchInfoTag(wpi::ArrayRef data) { + HAL_MatchInfo& ReadNewMatchInfoTag(wpi::span data) { commPacket.ReadNewMatchInfoTag(data); return commPacket.matchInfo; } - HAL_MatchInfo& ReadGameSpecificTag(wpi::ArrayRef data) { + HAL_MatchInfo& ReadGameSpecificTag(wpi::span data) { commPacket.ReadGameSpecificMessageTag(data); return commPacket.matchInfo; } diff --git a/simulation/halsim_gui/src/main/native/cpp/AddressableLEDGui.cpp b/simulation/halsim_gui/src/main/native/cpp/AddressableLEDGui.cpp index 586bbd8841..23a52381f2 100644 --- a/simulation/halsim_gui/src/main/native/cpp/AddressableLEDGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/AddressableLEDGui.cpp @@ -26,7 +26,7 @@ class AddressableLEDModel : public glass::LEDDisplayModel { bool IsRunning() override { return HALSIM_GetAddressableLEDRunning(m_index); } - wpi::ArrayRef GetData(wpi::SmallVectorImpl&) override { + wpi::span GetData(wpi::SmallVectorImpl&) override { size_t length = HALSIM_GetAddressableLEDData(m_index, m_data); return {reinterpret_cast(m_data), length}; } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp index 2abd7c0dd8..b434c1be05 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp @@ -48,12 +48,11 @@ SequentialCommandGroup Command::BeforeStarting( std::function toRun, std::initializer_list 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 toRun, wpi::ArrayRef requirements) && { + std::function toRun, wpi::span requirements) && { std::vector> temp; temp.emplace_back( std::make_unique(std::move(toRun), requirements)); @@ -64,13 +63,12 @@ SequentialCommandGroup Command::BeforeStarting( SequentialCommandGroup Command::AndThen( std::function toRun, std::initializer_list 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 toRun, wpi::ArrayRef requirements) && { + std::function toRun, wpi::span requirements) && { std::vector> temp; temp.emplace_back(std::move(*this).TransferOwnership()); temp.emplace_back( diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp index 654ba58037..c1415a4282 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp @@ -18,7 +18,7 @@ void CommandBase::AddRequirements( m_requirements.insert(requirements.begin(), requirements.end()); } -void CommandBase::AddRequirements(wpi::ArrayRef requirements) { +void CommandBase::AddRequirements(wpi::span requirements) { m_requirements.insert(requirements.begin(), requirements.end()); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp index d6c89aec1f..a3d275df42 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp @@ -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> commands) { + wpi::span> 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 commands) { + std::initializer_list commands) { bool allUngrouped = true; for (auto&& command : commands) { allUngrouped &= !command->IsGrouped(); diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp index f269698dfe..295134a76b 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp @@ -161,7 +161,7 @@ void CommandScheduler::Schedule(Command* command) { } void CommandScheduler::Schedule(bool interruptible, - wpi::ArrayRef commands) { + wpi::span commands) { for (auto command : commands) { Schedule(interruptible, command); } @@ -174,7 +174,7 @@ void CommandScheduler::Schedule(bool interruptible, } } -void CommandScheduler::Schedule(wpi::ArrayRef commands) { +void CommandScheduler::Schedule(wpi::span commands) { for (auto command : commands) { Schedule(true, command); } @@ -284,7 +284,8 @@ void CommandScheduler::RegisterSubsystem( } } -void CommandScheduler::RegisterSubsystem(wpi::ArrayRef subsystems) { +void CommandScheduler::RegisterSubsystem( + wpi::span subsystems) { for (auto* subsystem : subsystems) { RegisterSubsystem(subsystem); } @@ -298,7 +299,7 @@ void CommandScheduler::UnregisterSubsystem( } void CommandScheduler::UnregisterSubsystem( - wpi::ArrayRef subsystems) { + wpi::span subsystems) { for (auto* subsystem : subsystems) { UnregisterSubsystem(subsystem); } @@ -340,7 +341,7 @@ void CommandScheduler::Cancel(Command* command) { } } -void CommandScheduler::Cancel(wpi::ArrayRef commands) { +void CommandScheduler::Cancel(wpi::span commands) { for (auto command : commands) { Cancel(command); } @@ -370,7 +371,7 @@ units::second_t CommandScheduler::TimeSinceScheduled( } } bool CommandScheduler::IsScheduled( - wpi::ArrayRef commands) const { + wpi::span 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{}); + nt::NetworkTableEntry(cancelEntry).SetDoubleArray({}); } wpi::SmallVector names; diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp index ab0a3bbb28..0c45099d68 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp @@ -21,7 +21,7 @@ FunctionalCommand::FunctionalCommand(std::function onInit, std::function onExecute, std::function onEnd, std::function isFinished, - wpi::ArrayRef requirements) + wpi::span requirements) : m_onInit{std::move(onInit)}, m_onExecute{std::move(onExecute)}, m_onEnd{std::move(onEnd)}, diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp index b7a6ae7d86..1e9d173c9b 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp @@ -13,7 +13,7 @@ InstantCommand::InstantCommand(std::function toRun, } InstantCommand::InstantCommand(std::function toRun, - wpi::ArrayRef requirements) + wpi::span requirements) : m_toRun{std::move(toRun)} { AddRequirements(requirements); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp index f5e1cc178c..b7a5dcbd59 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp @@ -102,7 +102,7 @@ MecanumControllerCommand::MecanumControllerCommand( std::function output, - wpi::ArrayRef requirements) + wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), m_feedforward(feedforward), @@ -139,7 +139,7 @@ MecanumControllerCommand::MecanumControllerCommand( std::function output, - wpi::ArrayRef requirements) + wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), m_feedforward(feedforward), @@ -218,7 +218,7 @@ MecanumControllerCommand::MecanumControllerCommand( std::function output, - wpi::ArrayRef requirements) + wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), m_kinematics(kinematics), @@ -239,7 +239,7 @@ MecanumControllerCommand::MecanumControllerCommand( std::function output, - wpi::ArrayRef requirements) + wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), m_kinematics(kinematics), diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp index 6928a35094..37e5bc6ae4 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp @@ -15,7 +15,7 @@ NotifierCommand::NotifierCommand(std::function toRun, NotifierCommand::NotifierCommand(std::function toRun, units::second_t period, - wpi::ArrayRef requirements) + wpi::span requirements) : m_toRun(toRun), m_notifier{std::move(toRun)}, m_period{period} { AddRequirements(requirements); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp index 5e13ee0d04..d11735aa71 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp @@ -24,7 +24,7 @@ PIDCommand::PIDCommand(PIDController controller, std::function measurementSource, std::function setpointSource, std::function useOutput, - wpi::ArrayRef requirements) + wpi::span 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 measurementSource, double setpoint, std::function useOutput, - wpi::ArrayRef requirements) + wpi::span requirements) : PIDCommand( controller, measurementSource, [setpoint] { return setpoint; }, useOutput, requirements) {} diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp index d0307d34ca..0c199f2d05 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp @@ -7,7 +7,7 @@ using namespace frc2; PerpetualCommand::PerpetualCommand(std::unique_ptr&& command) { - if (!CommandGroupBase::RequireUngrouped(command)) { + if (!CommandGroupBase::RequireUngrouped(*command)) { return; } m_command = std::move(command); diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp index 52e34d0f4e..116ce3c112 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp @@ -6,10 +6,15 @@ using namespace frc2; -ProxyScheduleCommand::ProxyScheduleCommand(wpi::ArrayRef toSchedule) { +ProxyScheduleCommand::ProxyScheduleCommand( + wpi::span toSchedule) { SetInsert(m_toSchedule, toSchedule); } +ProxyScheduleCommand::ProxyScheduleCommand(Command* toSchedule) { + SetInsert(m_toSchedule, {&toSchedule, 1}); +} + void ProxyScheduleCommand::Initialize() { for (auto* command : m_toSchedule) { command->Schedule(); diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp index c974e19f83..0c0b852419 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp @@ -39,7 +39,7 @@ RamseteCommand::RamseteCommand( std::function wheelSpeeds, frc2::PIDController leftController, frc2::PIDController rightController, std::function output, - wpi::ArrayRef requirements) + wpi::span 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 output, - wpi::ArrayRef requirements) + wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), m_controller(controller), diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp index 1e073c903e..c63e5d6eb8 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp @@ -13,7 +13,7 @@ RunCommand::RunCommand(std::function toRun, } RunCommand::RunCommand(std::function toRun, - wpi::ArrayRef requirements) + wpi::span requirements) : m_toRun{std::move(toRun)} { AddRequirements(requirements); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp index bd580118ac..ff50bc5e2d 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp @@ -6,10 +6,14 @@ using namespace frc2; -ScheduleCommand::ScheduleCommand(wpi::ArrayRef toSchedule) { +ScheduleCommand::ScheduleCommand(wpi::span toSchedule) { SetInsert(m_toSchedule, toSchedule); } +ScheduleCommand::ScheduleCommand(Command* toSchedule) { + SetInsert(m_toSchedule, {&toSchedule, 1}); +} + void ScheduleCommand::Initialize() { for (auto command : m_toSchedule) { command->Schedule(); diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp index a53ad8a179..dc40200690 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp @@ -15,7 +15,7 @@ StartEndCommand::StartEndCommand(std::function onInit, StartEndCommand::StartEndCommand(std::function onInit, std::function onEnd, - wpi::ArrayRef requirements) + wpi::span requirements) : m_onInit{std::move(onInit)}, m_onEnd{std::move(onEnd)} { AddRequirements(requirements); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp index 37e818455d..955830a672 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp @@ -20,7 +20,7 @@ Button Button::WhenPressed(std::function toRun, } Button Button::WhenPressed(std::function toRun, - wpi::ArrayRef requirements) { + wpi::span requirements) { WhenActive(std::move(toRun), requirements); return *this; } @@ -37,7 +37,7 @@ Button Button::WhileHeld(std::function toRun, } Button Button::WhileHeld(std::function toRun, - wpi::ArrayRef requirements) { + wpi::span requirements) { WhileActiveContinous(std::move(toRun), requirements); return *this; } @@ -59,7 +59,7 @@ Button Button::WhenReleased(std::function toRun, } Button Button::WhenReleased(std::function toRun, - wpi::ArrayRef requirements) { + wpi::span requirements) { WhenInactive(std::move(toRun), requirements); return *this; } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp index 8b5737fc04..322420202f 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp @@ -27,12 +27,12 @@ Trigger Trigger::WhenActive(Command* command, bool interruptible) { Trigger Trigger::WhenActive(std::function toRun, std::initializer_list 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 toRun, - wpi::ArrayRef requirements) { + wpi::span requirements) { return WhenActive(InstantCommand(std::move(toRun), requirements)); } @@ -55,13 +55,12 @@ Trigger Trigger::WhileActiveContinous(Command* command, bool interruptible) { Trigger Trigger::WhileActiveContinous( std::function toRun, std::initializer_list 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 toRun, - wpi::ArrayRef requirements) { +Trigger Trigger::WhileActiveContinous( + std::function toRun, wpi::span requirements) { return WhileActiveContinous(InstantCommand(std::move(toRun), requirements)); } @@ -97,12 +96,12 @@ Trigger Trigger::WhenInactive(Command* command, bool interruptible) { Trigger Trigger::WhenInactive(std::function toRun, std::initializer_list 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 toRun, - wpi::ArrayRef requirements) { + wpi::span requirements) { return WhenInactive(InstantCommand(std::move(toRun), requirements)); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h index 7bdc1c926a..b2ff4d9a26 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h @@ -10,9 +10,9 @@ #include #include -#include #include #include +#include #include "frc2/command/Subsystem.h" @@ -140,7 +140,7 @@ class Command { */ SequentialCommandGroup BeforeStarting( std::function toRun, - wpi::ArrayRef requirements = {}) &&; + wpi::span requirements = {}) &&; /** * Decorates this command with a runnable to run after the command finishes. @@ -162,7 +162,7 @@ class Command { */ SequentialCommandGroup AndThen( std::function toRun, - wpi::ArrayRef requirements = {}) &&; + wpi::span requirements = {}) &&; /** * Decorates this command to run perpetually, ignoring its ordinary end diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h index b37f3df417..473daae48c 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h @@ -10,8 +10,8 @@ #include #include -#include #include +#include #include "frc2/command/Command.h" @@ -35,7 +35,7 @@ class CommandBase : public Command, * * @param requirements the requirements to add */ - void AddRequirements(wpi::ArrayRef requirements); + void AddRequirements(wpi::span requirements); void AddRequirements(wpi::SmallSet requirements); diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h index aa940c6182..0ba17d7d16 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h @@ -8,7 +8,7 @@ #include #include -#include +#include #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>); + static bool RequireUngrouped(wpi::span>); /** * 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); + static bool RequireUngrouped(std::initializer_list); /** * Adds the given commands to the command group. diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h index 26de78319f..e041670c09 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h @@ -13,8 +13,8 @@ #include #include #include -#include #include +#include 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 commands); + void Schedule(bool interruptible, wpi::span 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 commands); + void Schedule(wpi::span 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 subsystems); - void RegisterSubsystem(wpi::ArrayRef subsystems); + void RegisterSubsystem(wpi::span subsystems); void UnregisterSubsystem(std::initializer_list subsystems); - void UnregisterSubsystem(wpi::ArrayRef subsystems); + void UnregisterSubsystem(wpi::span 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 commands); + void Cancel(wpi::span 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 commands) const; + bool IsScheduled(wpi::span commands) const; /** * Whether the given commands are running. Note that this only works on diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h index f3b60d1878..31b2ada3f9 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -52,7 +52,7 @@ class FunctionalCommand : public CommandHelper { std::function onExecute, std::function onEnd, std::function isFinished, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); FunctionalCommand(FunctionalCommand&& other) = default; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h index 08651ebbe1..3aba587e24 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -38,7 +38,7 @@ class InstantCommand : public CommandHelper { * @param requirements the subsystems required by this command */ explicit InstantCommand(std::function toRun, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); InstantCommand(InstantCommand&& other) = default; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h index 9427be81ab..90d3033a32 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include "CommandBase.h" #include "CommandHelper.h" @@ -204,7 +204,7 @@ class MecanumControllerCommand std::function output, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Constructs a new MecanumControllerCommand that when executed will follow @@ -257,7 +257,7 @@ class MecanumControllerCommand std::function output, - wpi::ArrayRef requirements = {}); + wpi::span 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 requirements = {}); + wpi::span 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 requirements = {}); + wpi::span requirements = {}); void Initialize() override; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h index 4083273450..f4f31e3790 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -45,7 +45,7 @@ class NotifierCommand : public CommandHelper { * @param requirements the subsystems required by this command */ NotifierCommand(std::function toRun, units::second_t period, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); NotifierCommand(NotifierCommand&& other); diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h index 918d44e60c..31baf9eb43 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h @@ -8,6 +8,7 @@ #include #include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -53,7 +54,7 @@ class PIDCommand : public CommandHelper { std::function measurementSource, std::function setpointSource, std::function useOutput, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Creates a new PIDCommand, which controls the given output with a @@ -83,7 +84,7 @@ class PIDCommand : public CommandHelper { PIDCommand(PIDController controller, std::function measurementSource, double setpoint, std::function useOutput, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); PIDCommand(PIDCommand&& other) = default; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h index 747b7ca767..b02c81d249 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -70,7 +70,7 @@ class ProfiledPIDCommand std::function measurementSource, std::function goalSource, std::function useOutput, - wpi::ArrayRef requirements = {}) + wpi::span requirements = {}) : m_controller{controller}, m_measurement{std::move(measurementSource)}, m_goal{std::move(goalSource)}, @@ -114,7 +114,7 @@ class ProfiledPIDCommand std::function measurementSource, std::function goalSource, std::function useOutput, - wpi::ArrayRef requirements = {}) + wpi::span requirements = {}) : ProfiledPIDCommand( controller, measurementSource, [&goalSource]() { @@ -153,7 +153,7 @@ class ProfiledPIDCommand ProfiledPIDCommand(frc::ProfiledPIDController controller, std::function measurementSource, State goal, std::function useOutput, - wpi::ArrayRef requirements = {}) + wpi::span requirements = {}) : ProfiledPIDCommand( controller, measurementSource, [goal] { return goal; }, useOutput, requirements) {} @@ -191,7 +191,7 @@ class ProfiledPIDCommand std::function measurementSource, Distance_t goal, std::function useOutput, - wpi::ArrayRef requirements = {}) + wpi::span requirements = {}) : ProfiledPIDCommand( controller, measurementSource, [goal] { return goal; }, useOutput, requirements) {} diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h index 439d57227a..ad603f941c 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h @@ -4,8 +4,8 @@ #pragma once -#include #include +#include #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 toSchedule); + explicit ProxyScheduleCommand(wpi::span toSchedule); + + explicit ProxyScheduleCommand(Command* toSchedule); ProxyScheduleCommand(ProxyScheduleCommand&& other) = default; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h index 79e418be35..5f8499729d 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -114,7 +114,7 @@ class RamseteCommand : public CommandHelper { frc2::PIDController leftController, frc2::PIDController rightController, std::function output, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Constructs a new RamseteCommand that, when executed, will follow the @@ -162,7 +162,7 @@ class RamseteCommand : public CommandHelper { std::function output, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); void Initialize() override; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h index 2d994705f6..510840ef34 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -39,7 +39,7 @@ class RunCommand : public CommandHelper { * @param requirements the subsystems to require */ explicit RunCommand(std::function toRun, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); RunCommand(RunCommand&& other) = default; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h index 8a426a75b6..ca476d0779 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h @@ -4,8 +4,8 @@ #pragma once -#include #include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -26,7 +26,9 @@ class ScheduleCommand : public CommandHelper { * * @param toSchedule the commands to schedule */ - explicit ScheduleCommand(wpi::ArrayRef toSchedule); + explicit ScheduleCommand(wpi::span toSchedule); + + explicit ScheduleCommand(Command* toSchedule); ScheduleCommand(ScheduleCommand&& other) = default; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h index 34062a3e26..b4e7f898b3 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h @@ -59,7 +59,7 @@ class SelectCommand : public CommandHelper> { ...); for (auto&& command : foo) { - if (!CommandGroupBase::RequireUngrouped(command.second)) { + if (!CommandGroupBase::RequireUngrouped(*command.second)) { return; } } @@ -76,7 +76,7 @@ class SelectCommand : public CommandHelper> { std::vector>>&& commands) : m_selector{std::move(selector)} { for (auto&& command : commands) { - if (!CommandGroupBase::RequireUngrouped(command.second)) { + if (!CommandGroupBase::RequireUngrouped(*command.second)) { return; } } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h b/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h index 253abb28c1..4b09544b12 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h @@ -15,8 +15,6 @@ #include #include -#include - #include "frc2/command/CommandGroupBase.h" #include "frc2/command/CommandHelper.h" diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h b/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h index fc7efe414c..d40fbecaa6 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h @@ -4,12 +4,12 @@ #pragma once -#include #include +#include namespace frc2 { template -void SetInsert(wpi::SmallVectorImpl& vector, wpi::ArrayRef toAdd) { +void SetInsert(wpi::SmallVectorImpl& vector, wpi::span toAdd) { for (auto addCommand : toAdd) { bool exists = false; for (auto existingCommand : vector) { diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h index 4c239d0e06..d364696360 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -42,7 +42,7 @@ class StartEndCommand : public CommandHelper { * @param requirements the subsystems required by this command */ StartEndCommand(std::function onInit, std::function onEnd, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); StartEndCommand(StartEndCommand&& other) = default; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h index 459cec992a..13733fe6b1 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include "CommandBase.h" #include "CommandHelper.h" @@ -167,7 +167,7 @@ class SwerveControllerCommand std::function desiredRotation, std::function)> output, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Constructs a new SwerveControllerCommand that when executed will follow the @@ -205,7 +205,7 @@ class SwerveControllerCommand frc::ProfiledPIDController thetaController, std::function)> output, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); void Initialize() override; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc index 19fb719365..1f65b788f1 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc @@ -56,7 +56,7 @@ SwerveControllerCommand::SwerveControllerCommand( frc::ProfiledPIDController thetaController, std::function desiredRotation, std::function)> output, - wpi::ArrayRef requirements) + wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), m_kinematics(kinematics), @@ -73,7 +73,7 @@ SwerveControllerCommand::SwerveControllerCommand( frc2::PIDController xController, frc2::PIDController yController, frc::ProfiledPIDController thetaController, std::function)> output, - wpi::ArrayRef requirements) + wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), m_kinematics(kinematics), diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h index d3e33dcfdb..4cfbd23177 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include "frc2/command/CommandBase.h" #include "frc2/command/CommandHelper.h" @@ -54,7 +54,7 @@ class TrapezoidProfileCommand */ TrapezoidProfileCommand(frc::TrapezoidProfile profile, std::function output, - wpi::ArrayRef requirements = {}) + wpi::span requirements = {}) : m_profile(profile), m_output(output) { this->AddRequirements(requirements); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h index faff8f4e7d..3540432a53 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include "Trigger.h" @@ -79,7 +79,7 @@ class Button : public Trigger { * @param requirements the required subsystems. */ Button WhenPressed(std::function toRun, - wpi::ArrayRef requirements = {}); + wpi::span 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 toRun, - wpi::ArrayRef requirements = {}); + wpi::span 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 toRun, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Binds a command to start when the button is pressed, and be canceled when diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h index 101b395bc0..67a194f5de 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include "frc2/command/Command.h" #include "frc2/command/CommandScheduler.h" @@ -101,7 +101,7 @@ class Trigger { * @paaram requirements the required subsystems. */ Trigger WhenActive(std::function toRun, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Binds a command to be started repeatedly while the trigger is active, and @@ -161,7 +161,7 @@ class Trigger { * @param requirements the required subsystems. */ Trigger WhileActiveContinous(std::function toRun, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Binds a command to be started when the trigger becomes active, and @@ -261,7 +261,7 @@ class Trigger { * @param requirements the required subsystems. */ Trigger WhenInactive(std::function toRun, - wpi::ArrayRef requirements = {}); + wpi::span requirements = {}); /** * Binds a command to start when the trigger becomes active, and be canceled diff --git a/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp b/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp index 4543dc0cf2..8baa62f5c3 100644 --- a/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp +++ b/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp @@ -165,7 +165,7 @@ void Scheduler::InitSendable(SendableBuilder& builder) { builder.SetUpdateTable([=]() { // Get the list of possible commands to cancel auto new_toCancel = cancelEntry.GetValue(); - wpi::ArrayRef toCancel; + wpi::span toCancel; if (new_toCancel) { toCancel = new_toCancel->GetDoubleArray(); } diff --git a/wpilibc/src/main/native/cpp/AddressableLED.cpp b/wpilibc/src/main/native/cpp/AddressableLED.cpp index 320eac2463..759c3864d5 100644 --- a/wpilibc/src/main/native/cpp/AddressableLED.cpp +++ b/wpilibc/src/main/native/cpp/AddressableLED.cpp @@ -51,7 +51,7 @@ void AddressableLED::SetLength(int length) { static_assert(sizeof(AddressableLED::LEDData) == sizeof(HAL_AddressableLEDData), "LED Structs MUST be the same size"); -void AddressableLED::SetData(wpi::ArrayRef ledData) { +void AddressableLED::SetData(wpi::span ledData) { int32_t status = 0; HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(), &status); diff --git a/wpilibc/src/main/native/cpp/SPI.cpp b/wpilibc/src/main/native/cpp/SPI.cpp index 91df304d54..74df512daf 100644 --- a/wpilibc/src/main/native/cpp/SPI.cpp +++ b/wpilibc/src/main/native/cpp/SPI.cpp @@ -260,7 +260,8 @@ void SPI::FreeAuto() { FRC_CheckErrorStatus(status, "Port {}", m_port); } -void SPI::SetAutoTransmitData(wpi::ArrayRef dataToSend, int zeroSize) { +void SPI::SetAutoTransmitData(wpi::span dataToSend, + int zeroSize) { int32_t status = 0; HAL_SetSPIAutoTransmitData(m_port, dataToSend.data(), dataToSend.size(), zeroSize, &status); diff --git a/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp b/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp index 005eb08b7d..5dcd2876c1 100644 --- a/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp +++ b/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp @@ -42,7 +42,7 @@ double RobotDriveBase::ApplyDeadband(double value, double deadband) { } } -void RobotDriveBase::Normalize(wpi::MutableArrayRef wheelSpeeds) { +void RobotDriveBase::Normalize(wpi::span wheelSpeeds) { double maxMagnitude = std::abs(wheelSpeeds[0]); for (size_t i = 1; i < wheelSpeeds.size(); i++) { double temp = std::abs(wheelSpeeds[i]); diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp index bf36ea66fb..2112a4d317 100644 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp +++ b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp @@ -110,17 +110,17 @@ SimpleWidget& ShuffleboardContainer::Add(std::string_view title, } SimpleWidget& ShuffleboardContainer::Add(std::string_view title, - wpi::ArrayRef defaultValue) { + wpi::span defaultValue) { return Add(title, nt::Value::MakeBooleanArray(defaultValue)); } SimpleWidget& ShuffleboardContainer::Add(std::string_view title, - wpi::ArrayRef defaultValue) { + wpi::span defaultValue) { return Add(title, nt::Value::MakeDoubleArray(defaultValue)); } SimpleWidget& ShuffleboardContainer::Add( - std::string_view title, wpi::ArrayRef defaultValue) { + std::string_view title, wpi::span defaultValue) { return Add(title, nt::Value::MakeStringArray(defaultValue)); } @@ -254,17 +254,17 @@ SimpleWidget& ShuffleboardContainer::AddPersistent( } SimpleWidget& ShuffleboardContainer::AddPersistent( - std::string_view title, wpi::ArrayRef defaultValue) { + std::string_view title, wpi::span defaultValue) { return AddPersistent(title, nt::Value::MakeBooleanArray(defaultValue)); } SimpleWidget& ShuffleboardContainer::AddPersistent( - std::string_view title, wpi::ArrayRef defaultValue) { + std::string_view title, wpi::span defaultValue) { return AddPersistent(title, nt::Value::MakeDoubleArray(defaultValue)); } SimpleWidget& ShuffleboardContainer::AddPersistent( - std::string_view title, wpi::ArrayRef defaultValue) { + std::string_view title, wpi::span defaultValue) { return AddPersistent(title, nt::Value::MakeStringArray(defaultValue)); } diff --git a/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp index 1483716da6..bad7288aee 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp @@ -28,12 +28,12 @@ FieldObject2d& FieldObject2d::operator=(FieldObject2d&& rhs) { } void FieldObject2d::SetPose(const Pose2d& pose) { - SetPoses(wpi::makeArrayRef(pose)); + SetPoses({pose}); } void FieldObject2d::SetPose(units::meter_t x, units::meter_t y, Rotation2d rotation) { - SetPoses(wpi::makeArrayRef(Pose2d{x, y, rotation})); + SetPoses({{x, y, rotation}}); } Pose2d FieldObject2d::GetPose() const { @@ -45,14 +45,14 @@ Pose2d FieldObject2d::GetPose() const { return m_poses[0]; } -void FieldObject2d::SetPoses(wpi::ArrayRef poses) { +void FieldObject2d::SetPoses(wpi::span poses) { std::scoped_lock lock(m_mutex); m_poses.assign(poses.begin(), poses.end()); UpdateEntry(); } void FieldObject2d::SetPoses(std::initializer_list poses) { - SetPoses(wpi::makeArrayRef(poses.begin(), poses.end())); + SetPoses({poses.begin(), poses.end()}); } void FieldObject2d::SetTrajectory(const Trajectory& trajectory) { @@ -71,7 +71,7 @@ std::vector FieldObject2d::GetPoses() const { return std::vector(m_poses.begin(), m_poses.end()); } -wpi::ArrayRef FieldObject2d::GetPoses( +wpi::span FieldObject2d::GetPoses( wpi::SmallVectorImpl& out) const { std::scoped_lock lock(m_mutex); UpdateFromEntry(); diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp index 7a3a5f009f..3e294dc337 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp @@ -177,7 +177,7 @@ void SendableBuilderImpl::AddStringProperty( void SendableBuilderImpl::AddBooleanArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) { + std::function)> setter) { m_properties.emplace_back(*m_table, key); if (getter) { m_properties.back().update = [=](nt::NetworkTableEntry entry, @@ -203,7 +203,7 @@ void SendableBuilderImpl::AddBooleanArrayProperty( void SendableBuilderImpl::AddDoubleArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) { + std::function)> setter) { m_properties.emplace_back(*m_table, key); if (getter) { m_properties.back().update = [=](nt::NetworkTableEntry entry, @@ -229,7 +229,7 @@ void SendableBuilderImpl::AddDoubleArrayProperty( void SendableBuilderImpl::AddStringArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) { + std::function)> setter) { m_properties.emplace_back(*m_table, key); if (getter) { m_properties.back().update = [=](nt::NetworkTableEntry entry, @@ -331,8 +331,8 @@ void SendableBuilderImpl::AddSmallStringProperty( void SendableBuilderImpl::AddSmallBooleanArrayProperty( std::string_view key, - std::function(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) { + std::function(wpi::SmallVectorImpl& buf)> getter, + std::function)> setter) { m_properties.emplace_back(*m_table, key); if (getter) { m_properties.back().update = [=](nt::NetworkTableEntry entry, @@ -359,9 +359,9 @@ void SendableBuilderImpl::AddSmallBooleanArrayProperty( void SendableBuilderImpl::AddSmallDoubleArrayProperty( std::string_view key, - std::function(wpi::SmallVectorImpl& buf)> + std::function(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) { + std::function)> setter) { m_properties.emplace_back(*m_table, key); if (getter) { m_properties.back().update = [=](nt::NetworkTableEntry entry, @@ -389,9 +389,9 @@ void SendableBuilderImpl::AddSmallDoubleArrayProperty( void SendableBuilderImpl::AddSmallStringArrayProperty( std::string_view key, std::function< - wpi::ArrayRef(wpi::SmallVectorImpl& buf)> + wpi::span(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) { + std::function)> setter) { m_properties.emplace_back(*m_table, key); if (getter) { m_properties.back().update = [=](nt::NetworkTableEntry entry, diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp index d7794707f2..d8743fcb63 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp @@ -170,52 +170,52 @@ std::string SmartDashboard::GetString(std::string_view keyName, } bool SmartDashboard::PutBooleanArray(std::string_view key, - wpi::ArrayRef value) { + wpi::span value) { return Singleton::GetInstance().table->GetEntry(key).SetBooleanArray(value); } bool SmartDashboard::SetDefaultBooleanArray(std::string_view key, - wpi::ArrayRef defaultValue) { + wpi::span defaultValue) { return Singleton::GetInstance().table->GetEntry(key).SetDefaultBooleanArray( defaultValue); } std::vector SmartDashboard::GetBooleanArray( - std::string_view key, wpi::ArrayRef defaultValue) { + std::string_view key, wpi::span defaultValue) { return Singleton::GetInstance().table->GetEntry(key).GetBooleanArray( defaultValue); } bool SmartDashboard::PutNumberArray(std::string_view key, - wpi::ArrayRef value) { + wpi::span value) { return Singleton::GetInstance().table->GetEntry(key).SetDoubleArray(value); } -bool SmartDashboard::SetDefaultNumberArray(std::string_view key, - wpi::ArrayRef defaultValue) { +bool SmartDashboard::SetDefaultNumberArray( + std::string_view key, wpi::span defaultValue) { return Singleton::GetInstance().table->GetEntry(key).SetDefaultDoubleArray( defaultValue); } std::vector SmartDashboard::GetNumberArray( - std::string_view key, wpi::ArrayRef defaultValue) { + std::string_view key, wpi::span defaultValue) { return Singleton::GetInstance().table->GetEntry(key).GetDoubleArray( defaultValue); } bool SmartDashboard::PutStringArray(std::string_view key, - wpi::ArrayRef value) { + wpi::span value) { return Singleton::GetInstance().table->GetEntry(key).SetStringArray(value); } bool SmartDashboard::SetDefaultStringArray( - std::string_view key, wpi::ArrayRef defaultValue) { + std::string_view key, wpi::span defaultValue) { return Singleton::GetInstance().table->GetEntry(key).SetDefaultStringArray( defaultValue); } std::vector SmartDashboard::GetStringArray( - std::string_view key, wpi::ArrayRef defaultValue) { + std::string_view key, wpi::span defaultValue) { return Singleton::GetInstance().table->GetEntry(key).GetStringArray( defaultValue); } diff --git a/wpilibc/src/main/native/include/frc/AddressableLED.h b/wpilibc/src/main/native/include/frc/AddressableLED.h index 710cf1522d..e38b4cd097 100644 --- a/wpilibc/src/main/native/include/frc/AddressableLED.h +++ b/wpilibc/src/main/native/include/frc/AddressableLED.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include "util/Color.h" #include "util/Color8Bit.h" @@ -107,7 +107,7 @@ class AddressableLED { * * @param ledData the buffer to write */ - void SetData(wpi::ArrayRef ledData); + void SetData(wpi::span ledData); /** * Sets the led output data. diff --git a/wpilibc/src/main/native/include/frc/SPI.h b/wpilibc/src/main/native/include/frc/SPI.h index 0a864be251..0f3c85737f 100644 --- a/wpilibc/src/main/native/include/frc/SPI.h +++ b/wpilibc/src/main/native/include/frc/SPI.h @@ -10,8 +10,8 @@ #include #include -#include #include +#include namespace frc { @@ -173,7 +173,7 @@ class SPI { * @param dataToSend data to send (maximum 16 bytes) * @param zeroSize number of zeros to send after the data */ - void SetAutoTransmitData(wpi::ArrayRef dataToSend, int zeroSize); + void SetAutoTransmitData(wpi::span dataToSend, int zeroSize); /** * Start running the automatic SPI transfer engine at a periodic rate. diff --git a/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h b/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h index dea3cd33be..87003d5bf1 100644 --- a/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h +++ b/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include "frc/MotorSafety.h" @@ -82,7 +82,7 @@ class RobotDriveBase : public MotorSafety { * Normalize all wheel speeds if the magnitude of any wheel is greater than * 1.0. */ - static void Normalize(wpi::MutableArrayRef wheelSpeeds); + static void Normalize(wpi::span wheelSpeeds); double m_deadband = 0.02; double m_maxOutput = 1.0; diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h index e0f7b467b2..2bfc9902a0 100644 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h +++ b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h @@ -12,9 +12,9 @@ #include #include -#include #include #include +#include #include "frc/shuffleboard/BuiltInLayouts.h" #include "frc/shuffleboard/LayoutType.h" @@ -228,19 +228,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue { * container with the given title * @see #addPersistent(String, Object) add(String title, Object defaultValue) */ - SimpleWidget& Add(std::string_view title, wpi::ArrayRef defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see #addPersistent(String, Object) add(String title, Object defaultValue) - */ - SimpleWidget& Add(std::string_view title, wpi::ArrayRef defaultValue); + SimpleWidget& Add(std::string_view title, wpi::span defaultValue); /** * Adds a widget to this container to display the given data. @@ -253,7 +241,20 @@ class ShuffleboardContainer : public virtual ShuffleboardValue { * @see #addPersistent(String, Object) add(String title, Object defaultValue) */ SimpleWidget& Add(std::string_view title, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); + + /** + * Adds a widget to this container to display the given data. + * + * @param title the title of the widget + * @param defaultValue the default value of the widget + * @return a widget to display the sendable data + * @throws IllegalArgumentException if a widget already exists in this + * container with the given title + * @see #addPersistent(String, Object) add(String title, Object defaultValue) + */ + SimpleWidget& Add(std::string_view title, + wpi::span defaultValue); /** * Adds a widget to this container. The widget will display the data provided @@ -432,7 +433,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue { * @see #add(String, Object) add(String title, Object defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); /** * Adds a widget to this container to display a simple piece of data. @@ -447,7 +448,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue { * @see #add(String, Object) add(String title, Object defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); /** * Adds a widget to this container to display a simple piece of data. @@ -462,7 +463,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue { * @see #add(String, Object) add(String title, Object defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); void EnableIfActuator() override; diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/FieldObject2d.h b/wpilibc/src/main/native/include/frc/smartdashboard/FieldObject2d.h index 69cce223d2..29cec86d7c 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/FieldObject2d.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/FieldObject2d.h @@ -12,9 +12,9 @@ #include #include -#include #include #include +#include #include "frc/geometry/Pose2d.h" #include "frc/geometry/Rotation2d.h" @@ -66,7 +66,7 @@ class FieldObject2d { * * @param poses array of 2D poses */ - void SetPoses(wpi::ArrayRef poses); + void SetPoses(wpi::span poses); /** * Set multiple poses from an array of Pose objects. @@ -97,9 +97,9 @@ class FieldObject2d { * * @param obj Object entry * @param out output SmallVector to hold 2D poses - * @return ArrayRef referring to output SmallVector + * @return span referring to output SmallVector */ - wpi::ArrayRef GetPoses(wpi::SmallVectorImpl& out) const; + wpi::span GetPoses(wpi::SmallVectorImpl& out) const; private: void UpdateEntry(bool setDefault = false); diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilder.h b/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilder.h index 3ec3831cef..e7bc2d09ab 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilder.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilder.h @@ -13,8 +13,8 @@ #include #include #include -#include #include +#include namespace frc { @@ -107,7 +107,7 @@ class SendableBuilder { */ virtual void AddBooleanArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) = 0; + std::function)> setter) = 0; /** * Add a double array property. @@ -118,7 +118,7 @@ class SendableBuilder { */ virtual void AddDoubleArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) = 0; + std::function)> setter) = 0; /** * Add a string array property. @@ -129,7 +129,7 @@ class SendableBuilder { */ virtual void AddStringArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) = 0; + std::function)> setter) = 0; /** * Add a raw property. @@ -174,8 +174,9 @@ class SendableBuilder { */ virtual void AddSmallBooleanArrayProperty( std::string_view key, - std::function(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) = 0; + std::function(wpi::SmallVectorImpl& buf)> + getter, + std::function)> setter) = 0; /** * Add a double array property (SmallVector form). @@ -186,9 +187,9 @@ class SendableBuilder { */ virtual void AddSmallDoubleArrayProperty( std::string_view key, - std::function(wpi::SmallVectorImpl& buf)> + std::function(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) = 0; + std::function)> setter) = 0; /** * Add a string array property (SmallVector form). @@ -200,9 +201,9 @@ class SendableBuilder { virtual void AddSmallStringArrayProperty( std::string_view key, std::function< - wpi::ArrayRef(wpi::SmallVectorImpl& buf)> + wpi::span(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) = 0; + std::function)> setter) = 0; /** * Add a raw property (SmallVector form). diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h b/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h index 34b9d59673..10125fbd40 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h @@ -14,8 +14,8 @@ #include #include #include -#include #include +#include #include "frc/smartdashboard/SendableBuilder.h" @@ -104,15 +104,15 @@ class SendableBuilderImpl : public SendableBuilder { void AddBooleanArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) override; + std::function)> setter) override; void AddDoubleArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) override; + std::function)> setter) override; void AddStringArrayProperty( std::string_view key, std::function()> getter, - std::function)> setter) override; + std::function)> setter) override; void AddRawProperty(std::string_view key, std::function getter, std::function setter) override; @@ -128,21 +128,22 @@ class SendableBuilderImpl : public SendableBuilder { void AddSmallBooleanArrayProperty( std::string_view key, - std::function(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) override; + std::function(wpi::SmallVectorImpl& buf)> + getter, + std::function)> setter) override; void AddSmallDoubleArrayProperty( std::string_view key, - std::function(wpi::SmallVectorImpl& buf)> + std::function(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) override; + std::function)> setter) override; void AddSmallStringArrayProperty( std::string_view key, std::function< - wpi::ArrayRef(wpi::SmallVectorImpl& buf)> + wpi::span(wpi::SmallVectorImpl& buf)> getter, - std::function)> setter) override; + std::function)> setter) override; void AddSmallRawProperty( std::string_view key, diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h b/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h index 1ce7762392..c15b26a783 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h @@ -11,6 +11,7 @@ #include #include +#include #include "frc/smartdashboard/ListenerExecutor.h" #include "frc/smartdashboard/Sendable.h" @@ -243,7 +244,7 @@ class SmartDashboard : public Sendable, public SendableHelper { * std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - static bool PutBooleanArray(std::string_view key, wpi::ArrayRef value); + static bool PutBooleanArray(std::string_view key, wpi::span value); /** * Gets the current value in the table, setting it if it does not exist. @@ -253,7 +254,7 @@ class SmartDashboard : public Sendable, public SendableHelper { * @returns False if the table key exists with a different type */ static bool SetDefaultBooleanArray(std::string_view key, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); /** * Returns the boolean array the key maps to. @@ -274,7 +275,7 @@ class SmartDashboard : public Sendable, public SendableHelper { * non-zero value is true. */ static std::vector GetBooleanArray(std::string_view key, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); /** * Put a number array in the table. @@ -283,7 +284,8 @@ class SmartDashboard : public Sendable, public SendableHelper { * @param value The value that will be assigned. * @return False if the table key already exists with a different type */ - static bool PutNumberArray(std::string_view key, wpi::ArrayRef value); + static bool PutNumberArray(std::string_view key, + wpi::span value); /** * Gets the current value in the table, setting it if it does not exist. @@ -293,7 +295,7 @@ class SmartDashboard : public Sendable, public SendableHelper { * @returns False if the table key exists with a different type */ static bool SetDefaultNumberArray(std::string_view key, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); /** * Returns the number array the key maps to. @@ -309,8 +311,8 @@ class SmartDashboard : public Sendable, public SendableHelper { * @note This makes a copy of the array. If the overhead of this is a concern, * use GetValue() instead. */ - static std::vector GetNumberArray(std::string_view key, - wpi::ArrayRef defaultValue); + static std::vector GetNumberArray( + std::string_view key, wpi::span defaultValue); /** * Put a string array in the table. @@ -320,7 +322,7 @@ class SmartDashboard : public Sendable, public SendableHelper { * @return False if the table key already exists with a different type */ static bool PutStringArray(std::string_view key, - wpi::ArrayRef value); + wpi::span value); /** * Gets the current value in the table, setting it if it does not exist. @@ -330,7 +332,7 @@ class SmartDashboard : public Sendable, public SendableHelper { * @returns False if the table key exists with a different type */ static bool SetDefaultStringArray(std::string_view key, - wpi::ArrayRef defaultValue); + wpi::span defaultValue); /** * Returns the string array the key maps to. @@ -347,7 +349,7 @@ class SmartDashboard : public Sendable, public SendableHelper { * use GetValue() instead. */ static std::vector GetStringArray( - std::string_view key, wpi::ArrayRef defaultValue); + std::string_view key, wpi::span defaultValue); /** * Put a raw value (byte array) in the table. diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI.cpp b/wpimath/src/main/native/cpp/jni/WPIMathJNI.cpp index 52e68679e5..9a2083d5a0 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI.cpp +++ b/wpimath/src/main/native/cpp/jni/WPIMathJNI.cpp @@ -62,7 +62,7 @@ std::vector GetElementsFromTrajectory( return elements; } -frc::Trajectory CreateTrajectoryFromElements(wpi::ArrayRef elements) { +frc::Trajectory CreateTrajectoryFromElements(wpi::span elements) { // Make sure that the elements have the correct length. assert(elements.size() % 7 == 0); diff --git a/wpimath/src/main/native/include/frc/LinearFilter.h b/wpimath/src/main/native/include/frc/LinearFilter.h index 51b6a7f266..1c22ba1330 100644 --- a/wpimath/src/main/native/include/frc/LinearFilter.h +++ b/wpimath/src/main/native/include/frc/LinearFilter.h @@ -10,8 +10,8 @@ #include #include -#include #include +#include #include "units/time.h" #include "wpimath/MathShared.h" @@ -77,11 +77,11 @@ class LinearFilter { * @param ffGains The "feed forward" or FIR gains. * @param fbGains The "feed back" or IIR gains. */ - LinearFilter(wpi::ArrayRef ffGains, wpi::ArrayRef fbGains) + LinearFilter(wpi::span ffGains, wpi::span fbGains) : m_inputs(ffGains.size()), m_outputs(fbGains.size()), - m_inputGains(ffGains), - m_outputGains(fbGains) { + m_inputGains(ffGains.begin(), ffGains.end()), + m_outputGains(fbGains.begin(), fbGains.end()) { for (size_t i = 0; i < ffGains.size(); ++i) { m_inputs.emplace_front(0.0); } @@ -103,8 +103,8 @@ class LinearFilter { */ LinearFilter(std::initializer_list ffGains, std::initializer_list fbGains) - : LinearFilter(wpi::makeArrayRef(ffGains.begin(), ffGains.end()), - wpi::makeArrayRef(fbGains.begin(), fbGains.end())) {} + : LinearFilter({ffGains.begin(), ffGains.end()}, + {fbGains.begin(), fbGains.end()}) {} // Static methods to create commonly used filters /** @@ -124,7 +124,7 @@ class LinearFilter { static LinearFilter SinglePoleIIR(double timeConstant, units::second_t period) { double gain = std::exp(-period.to() / timeConstant); - return LinearFilter(1.0 - gain, -gain); + return LinearFilter({1.0 - gain}, {-gain}); } /** diff --git a/wpiutil/src/main/native/cpp/HttpServerConnection.cpp b/wpiutil/src/main/native/cpp/HttpServerConnection.cpp index 7ef52273e8..716d2af11a 100644 --- a/wpiutil/src/main/native/cpp/HttpServerConnection.cpp +++ b/wpiutil/src/main/native/cpp/HttpServerConnection.cpp @@ -7,6 +7,7 @@ #include "fmt/format.h" #include "wpi/SmallString.h" #include "wpi/SmallVector.h" +#include "wpi/SpanExtras.h" #include "wpi/StringExtras.h" #include "wpi/fmt/raw_ostream.h" #include "wpi/raw_uv_ostream.h" @@ -83,10 +84,9 @@ void HttpServerConnection::BuildHeader(raw_ostream& os, int code, os << "\r\n"; // header ends with a blank line } -void HttpServerConnection::SendData(ArrayRef bufs, +void HttpServerConnection::SendData(span bufs, bool closeAfter) { - m_stream.Write(bufs, [closeAfter, stream = &m_stream]( - MutableArrayRef bufs, uv::Error) { + m_stream.Write(bufs, [closeAfter, stream = &m_stream](auto bufs, uv::Error) { for (auto&& buf : bufs) { buf.Deallocate(); } @@ -126,9 +126,9 @@ void HttpServerConnection::SendStaticResponse( bufs.emplace_back(content); m_stream.Write(bufs, [closeAfter = !m_keepAlive, stream = &m_stream]( - MutableArrayRef bufs, uv::Error) { + auto bufs, uv::Error) { // don't deallocate the static content - for (auto&& buf : bufs.drop_back()) { + for (auto&& buf : wpi::drop_back(bufs)) { buf.Deallocate(); } if (closeAfter) { diff --git a/wpiutil/src/main/native/cpp/HttpUtil.cpp b/wpiutil/src/main/native/cpp/HttpUtil.cpp index 802432e31e..07aa3523ff 100644 --- a/wpiutil/src/main/native/cpp/HttpUtil.cpp +++ b/wpiutil/src/main/native/cpp/HttpUtil.cpp @@ -132,7 +132,7 @@ HttpPath::HttpPath(std::string_view path) { } bool HttpPath::startswith(size_t start, - ArrayRef match) const { + span match) const { if (m_pathEnds.size() < (start + match.size())) { return false; } diff --git a/wpiutil/src/main/native/cpp/PortForwarder.cpp b/wpiutil/src/main/native/cpp/PortForwarder.cpp index 797c7c7fdb..a423d48bd3 100644 --- a/wpiutil/src/main/native/cpp/PortForwarder.cpp +++ b/wpiutil/src/main/native/cpp/PortForwarder.cpp @@ -36,7 +36,7 @@ static void CopyStream(uv::Stream& in, std::weak_ptr outWeak) { in.Close(); return; } - out->Write(buf2, [](auto bufs, uv::Error) { + out->Write({buf2}, [](auto bufs, uv::Error) { for (auto buf : bufs) { buf.Deallocate(); } diff --git a/wpiutil/src/main/native/cpp/TCPConnector_parallel.cpp b/wpiutil/src/main/native/cpp/TCPConnector_parallel.cpp index dc4f4b106c..ff177bfc6f 100644 --- a/wpiutil/src/main/native/cpp/TCPConnector_parallel.cpp +++ b/wpiutil/src/main/native/cpp/TCPConnector_parallel.cpp @@ -24,7 +24,7 @@ using namespace wpi; #endif std::unique_ptr TCPConnector::connect_parallel( - ArrayRef> servers, Logger& logger, + span> servers, Logger& logger, int timeout) { if (servers.empty()) { return nullptr; diff --git a/wpiutil/src/main/native/cpp/UDPClient.cpp b/wpiutil/src/main/native/cpp/UDPClient.cpp index 3e90d47dca..108ef5424c 100644 --- a/wpiutil/src/main/native/cpp/UDPClient.cpp +++ b/wpiutil/src/main/native/cpp/UDPClient.cpp @@ -133,7 +133,8 @@ void UDPClient::shutdown() { } } -int UDPClient::send(ArrayRef data, std::string_view server, int port) { +int UDPClient::send(span data, std::string_view server, + int port) { // server must be a resolvable IP address struct sockaddr_in addr; std::memset(&addr, 0, sizeof(addr)); diff --git a/wpiutil/src/main/native/cpp/WebSocket.cpp b/wpiutil/src/main/native/cpp/WebSocket.cpp index e7a38736c7..c44c26adea 100644 --- a/wpiutil/src/main/native/cpp/WebSocket.cpp +++ b/wpiutil/src/main/native/cpp/WebSocket.cpp @@ -22,13 +22,13 @@ namespace { class WebSocketWriteReq : public uv::WriteReq { public: explicit WebSocketWriteReq( - std::function, uv::Error)> callback) { + std::function, uv::Error)> callback) { finish.connect([=](uv::Error err) { - MutableArrayRef bufs{m_bufs}; - for (auto&& buf : bufs.slice(0, m_startUser)) { + span bufs{m_bufs}; + for (auto&& buf : bufs.subspan(0, m_startUser)) { buf.Deallocate(); } - callback(bufs.slice(m_startUser), err); + callback(bufs.subspan(m_startUser), err); }); } @@ -99,7 +99,7 @@ WebSocket::~WebSocket() = default; std::shared_ptr WebSocket::CreateClient( uv::Stream& stream, std::string_view uri, std::string_view host, - ArrayRef protocols, const ClientOptions& options) { + span protocols, const ClientOptions& options) { auto ws = std::make_shared(stream, false, private_init{}); stream.SetData(ws); ws->StartClient(uri, host, protocols, options); @@ -141,7 +141,7 @@ void WebSocket::Terminate(uint16_t code, std::string_view reason) { } void WebSocket::StartClient(std::string_view uri, std::string_view host, - ArrayRef protocols, + span protocols, const ClientOptions& options) { // Create client handshake data m_clientHandshake = std::make_unique(); @@ -317,7 +317,7 @@ void WebSocket::SendClose(uint16_t code, std::string_view reason) { raw_uv_ostream os{bufs, 4096}; const uint8_t codeMsb[] = {static_cast((code >> 8) & 0xff), static_cast(code & 0xff)}; - os << ArrayRef(codeMsb); + os << span{codeMsb}; os << reason; } Send(kFlagFin | kOpClose, bufs, [](auto bufs, uv::Error) { @@ -459,8 +459,7 @@ void WebSocket::HandleIncoming(uv::Buffer& buf, size_t size) { m_header[m_headerSize - 4], m_header[m_headerSize - 3], m_header[m_headerSize - 2], m_header[m_headerSize - 1]}; int n = 0; - for (uint8_t& ch : - MutableArrayRef{m_payload}.slice(m_frameStart)) { + for (uint8_t& ch : span{m_payload}.subspan(m_frameStart)) { ch ^= key[n++]; if (n >= 4) { n = 0; @@ -575,8 +574,8 @@ void WebSocket::HandleIncoming(uv::Buffer& buf, size_t size) { } void WebSocket::Send( - uint8_t opcode, ArrayRef data, - std::function, uv::Error)> callback) { + uint8_t opcode, span data, + std::function, uv::Error)> callback) { // If we're not open, emit an error and don't send the data if (m_state != OPEN) { int err; @@ -607,7 +606,7 @@ void WebSocket::Send( os << static_cast((m_server ? 0x00 : kFlagMasking) | 126); const uint8_t sizeMsb[] = {static_cast((size >> 8) & 0xff), static_cast(size & 0xff)}; - os << ArrayRef(sizeMsb); + os << span{sizeMsb}; } else { os << static_cast((m_server ? 0x00 : kFlagMasking) | 127); const uint8_t sizeMsb[] = {static_cast((size >> 56) & 0xff), @@ -618,7 +617,7 @@ void WebSocket::Send( static_cast((size >> 16) & 0xff), static_cast((size >> 8) & 0xff), static_cast(size & 0xff)}; - os << ArrayRef(sizeMsb); + os << span{sizeMsb}; } // clients need to mask the input data @@ -631,7 +630,7 @@ void WebSocket::Send( for (uint8_t& v : key) { v = dist(gen); } - os << ArrayRef{key, 4}; + os << span{key, 4}; // copy and mask data int n = 0; for (auto&& buf : data) { @@ -645,8 +644,7 @@ void WebSocket::Send( req->m_startUser = req->m_bufs.size(); req->m_bufs.append(data.begin(), data.end()); // don't send the user bufs as we copied their data - m_stream.Write(ArrayRef{req->m_bufs}.slice(0, req->m_startUser), - req); + m_stream.Write(span{req->m_bufs}.subspan(0, req->m_startUser), req); } else { // servers can just send the buffers directly without masking req->m_startUser = req->m_bufs.size(); diff --git a/wpiutil/src/main/native/cpp/WebSocketServer.cpp b/wpiutil/src/main/native/cpp/WebSocketServer.cpp index 45b9fda7b2..1562f3bf04 100644 --- a/wpiutil/src/main/native/cpp/WebSocketServer.cpp +++ b/wpiutil/src/main/native/cpp/WebSocketServer.cpp @@ -46,7 +46,7 @@ WebSocketServerHelper::WebSocketServerHelper(HttpParser& req) { } std::pair WebSocketServerHelper::MatchProtocol( - ArrayRef protocols) { + span protocols) { if (protocols.empty() && m_protocols.empty()) { return {true, {}}; } @@ -61,7 +61,7 @@ std::pair WebSocketServerHelper::MatchProtocol( } WebSocketServer::WebSocketServer(uv::Stream& stream, - ArrayRef protocols, + span protocols, ServerOptions options, const private_init&) : m_stream{stream}, m_helper{m_req}, @@ -138,7 +138,7 @@ WebSocketServer::WebSocketServer(uv::Stream& stream, } std::shared_ptr WebSocketServer::Create( - uv::Stream& stream, ArrayRef protocols, + uv::Stream& stream, span protocols, const ServerOptions& options) { auto server = std::make_shared(stream, protocols, options, private_init{}); diff --git a/wpiutil/src/main/native/cpp/json_binary_reader.cpp b/wpiutil/src/main/native/cpp/json_binary_reader.cpp index 86d28332cf..cee5e3942a 100644 --- a/wpiutil/src/main/native/cpp/json_binary_reader.cpp +++ b/wpiutil/src/main/native/cpp/json_binary_reader.cpp @@ -1384,7 +1384,7 @@ json json::from_cbor(raw_istream& is, const bool strict) return binary_reader(is).parse_cbor(strict); } -json json::from_cbor(ArrayRef arr, const bool strict) +json json::from_cbor(span arr, const bool strict) { raw_mem_istream is(arr); return from_cbor(is, strict); @@ -1395,7 +1395,7 @@ json json::from_msgpack(raw_istream& is, const bool strict) return binary_reader(is).parse_msgpack(strict); } -json json::from_msgpack(ArrayRef arr, const bool strict) +json json::from_msgpack(span arr, const bool strict) { raw_mem_istream is(arr); return from_msgpack(is, strict); @@ -1406,7 +1406,7 @@ json json::from_ubjson(raw_istream& is, const bool strict) return binary_reader(is).parse_ubjson(strict); } -json json::from_ubjson(ArrayRef arr, const bool strict) +json json::from_ubjson(span arr, const bool strict) { raw_mem_istream is(arr); return from_ubjson(is, strict); diff --git a/wpiutil/src/main/native/cpp/json_binary_writer.cpp b/wpiutil/src/main/native/cpp/json_binary_writer.cpp index 0b6e6b7a16..db23f8dda1 100644 --- a/wpiutil/src/main/native/cpp/json_binary_writer.cpp +++ b/wpiutil/src/main/native/cpp/json_binary_writer.cpp @@ -813,7 +813,7 @@ void json::binary_writer::write_number(const NumberType n) std::reverse(vec.begin(), vec.end()); } - o << ArrayRef(vec.data(), sizeof(NumberType)); + o << span{vec.data(), sizeof(NumberType)}; } template json::to_cbor(const json& j) return result; } -ArrayRef json::to_cbor(const json& j, std::vector& buf) +span json::to_cbor(const json& j, std::vector& buf) { buf.clear(); raw_uvector_ostream os(buf); @@ -1012,7 +1012,7 @@ ArrayRef json::to_cbor(const json& j, std::vector& buf) return os.array(); } -ArrayRef json::to_cbor(const json& j, SmallVectorImpl& buf) +span json::to_cbor(const json& j, SmallVectorImpl& buf) { buf.clear(); raw_usvector_ostream os(buf); @@ -1033,7 +1033,7 @@ std::vector json::to_msgpack(const json& j) return result; } -ArrayRef json::to_msgpack(const json& j, std::vector& buf) +span json::to_msgpack(const json& j, std::vector& buf) { buf.clear(); raw_uvector_ostream os(buf); @@ -1041,7 +1041,7 @@ ArrayRef json::to_msgpack(const json& j, std::vector& buf) return os.array(); } -ArrayRef json::to_msgpack(const json& j, SmallVectorImpl& buf) +span json::to_msgpack(const json& j, SmallVectorImpl& buf) { buf.clear(); raw_usvector_ostream os(buf); @@ -1064,8 +1064,8 @@ std::vector json::to_ubjson(const json& j, return result; } -ArrayRef json::to_ubjson(const json& j, std::vector& buf, - const bool use_size, const bool use_type) +span json::to_ubjson(const json& j, std::vector& buf, + const bool use_size, const bool use_type) { buf.clear(); raw_uvector_ostream os(buf); @@ -1073,8 +1073,8 @@ ArrayRef json::to_ubjson(const json& j, std::vector& buf, return os.array(); } -ArrayRef json::to_ubjson(const json& j, SmallVectorImpl& buf, - const bool use_size, const bool use_type) +span json::to_ubjson(const json& j, SmallVectorImpl& buf, + const bool use_size, const bool use_type) { buf.clear(); raw_usvector_ostream os(buf); diff --git a/wpiutil/src/main/native/cpp/json_parser.cpp b/wpiutil/src/main/native/cpp/json_parser.cpp index bae8c118b6..db1ed11d42 100644 --- a/wpiutil/src/main/native/cpp/json_parser.cpp +++ b/wpiutil/src/main/native/cpp/json_parser.cpp @@ -1921,11 +1921,11 @@ json json::parse(std::string_view s, const parser_callback_t cb, const bool allow_exceptions) { - raw_mem_istream is(makeArrayRef(s.data(), s.size())); + raw_mem_istream is(span(s.data(), s.size())); return parse(is, cb, allow_exceptions); } -json json::parse(ArrayRef arr, +json json::parse(span arr, const parser_callback_t cb, const bool allow_exceptions) { @@ -1944,11 +1944,11 @@ json json::parse(raw_istream& i, bool json::accept(std::string_view s) { - raw_mem_istream is(makeArrayRef(s.data(), s.size())); + raw_mem_istream is(span(s.data(), s.size())); return parser(is).accept(true); } -bool json::accept(ArrayRef arr) +bool json::accept(span arr) { raw_mem_istream is(arr); return parser(is).accept(true); diff --git a/wpiutil/src/main/native/cpp/llvm/ConvertUTFWrapper.cpp b/wpiutil/src/main/native/cpp/llvm/ConvertUTFWrapper.cpp index bf9b1ad745..db190d0bb6 100644 --- a/wpiutil/src/main/native/cpp/llvm/ConvertUTFWrapper.cpp +++ b/wpiutil/src/main/native/cpp/llvm/ConvertUTFWrapper.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "wpi/ConvertUTF.h" +#include "wpi/SmallVector.h" #include #include @@ -28,13 +29,13 @@ bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr) { return true; } -bool hasUTF16ByteOrderMark(ArrayRef S) { +bool hasUTF16ByteOrderMark(span S) { return (S.size() >= 2 && ((S[0] == '\xff' && S[1] == '\xfe') || (S[0] == '\xfe' && S[1] == '\xff'))); } -bool convertUTF16ToUTF8String(ArrayRef SrcUTF16, +bool convertUTF16ToUTF8String(span SrcUTF16, SmallVectorImpl &DstUTF8) { assert(DstUTF8.empty()); diff --git a/wpiutil/src/main/native/cpp/llvm/SmallPtrSet.cpp b/wpiutil/src/main/native/cpp/llvm/SmallPtrSet.cpp index 1dab1fcf0e..1b33f4c5ac 100644 --- a/wpiutil/src/main/native/cpp/llvm/SmallPtrSet.cpp +++ b/wpiutil/src/main/native/cpp/llvm/SmallPtrSet.cpp @@ -15,6 +15,7 @@ #include "wpi/SmallPtrSet.h" #include "wpi/DenseMapInfo.h" #include "wpi/MathExtras.h" +#include "wpi/MemAlloc.h" #include "wpi/ErrorHandling.h" #include #include diff --git a/wpiutil/src/main/native/cpp/sha1.cpp b/wpiutil/src/main/native/cpp/sha1.cpp index 5319afb1db..8ec7cb1396 100644 --- a/wpiutil/src/main/native/cpp/sha1.cpp +++ b/wpiutil/src/main/native/cpp/sha1.cpp @@ -217,7 +217,7 @@ SHA1::SHA1() { } void SHA1::Update(std::string_view s) { - raw_mem_istream is(makeArrayRef(s.data(), s.size())); + raw_mem_istream is(span(s.data(), s.size())); Update(is); } diff --git a/wpiutil/src/main/native/cpp/uv/Process.cpp b/wpiutil/src/main/native/cpp/uv/Process.cpp index f41f492a6c..c8d522904c 100644 --- a/wpiutil/src/main/native/cpp/uv/Process.cpp +++ b/wpiutil/src/main/native/cpp/uv/Process.cpp @@ -11,7 +11,7 @@ namespace wpi::uv { std::shared_ptr Process::SpawnArray(Loop& loop, std::string_view file, - ArrayRef