Use wpi::span instead of wpi::ArrayRef across all libraries (#3414)

- Remove ArrayRef.h
- Add SpanExtras.h for a couple of convenience functions
This commit is contained in:
Peter Johnson
2021-06-06 19:51:14 -07:00
committed by GitHub
parent 2abbbd9e70
commit 64f5413253
167 changed files with 974 additions and 1433 deletions

View File

@@ -12,8 +12,8 @@
#include <string_view>
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/span.h>
#include "cscore_c.h"
@@ -203,7 +203,7 @@ CS_Source CreateUsbCameraPath(std::string_view name, std::string_view path,
CS_Source CreateHttpCamera(std::string_view name, std::string_view url,
CS_HttpCameraKind kind, CS_Status* status);
CS_Source CreateHttpCamera(std::string_view name,
wpi::ArrayRef<std::string> urls,
wpi::span<const std::string> urls,
CS_HttpCameraKind kind, CS_Status* status);
CS_Source CreateCvSource(std::string_view name, const VideoMode& mode,
CS_Status* status);
@@ -230,7 +230,7 @@ bool IsSourceConnected(CS_Source source, CS_Status* status);
bool IsSourceEnabled(CS_Source source, CS_Status* status);
CS_Property GetSourceProperty(CS_Source source, std::string_view name,
CS_Status* status);
wpi::ArrayRef<CS_Property> EnumerateSourceProperties(
wpi::span<CS_Property> EnumerateSourceProperties(
CS_Source source, wpi::SmallVectorImpl<CS_Property>& vec,
CS_Status* status);
VideoMode GetSourceVideoMode(CS_Source source, CS_Status* status);
@@ -249,9 +249,9 @@ std::string GetSourceConfigJson(CS_Source source, CS_Status* status);
wpi::json GetSourceConfigJsonObject(CS_Source source, CS_Status* status);
std::vector<VideoMode> EnumerateSourceVideoModes(CS_Source source,
CS_Status* status);
wpi::ArrayRef<CS_Sink> EnumerateSourceSinks(CS_Source source,
wpi::SmallVectorImpl<CS_Sink>& vec,
CS_Status* status);
wpi::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
wpi::SmallVectorImpl<CS_Sink>& vec,
CS_Status* status);
CS_Source CopySource(CS_Source source, CS_Status* status);
void ReleaseSource(CS_Source source, CS_Status* status);
/** @} */
@@ -285,7 +285,7 @@ UsbCameraInfo GetUsbCameraInfo(CS_Source source, CS_Status* status);
* @{
*/
CS_HttpCameraKind GetHttpCameraKind(CS_Source source, CS_Status* status);
void SetHttpCameraUrls(CS_Source source, wpi::ArrayRef<std::string> urls,
void SetHttpCameraUrls(CS_Source source, wpi::span<const std::string> urls,
CS_Status* status);
std::vector<std::string> GetHttpCameraUrls(CS_Source source, CS_Status* status);
/** @} */
@@ -304,7 +304,7 @@ CS_Property CreateSourceProperty(CS_Source source, std::string_view name,
int step, int defaultValue, int value,
CS_Status* status);
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
wpi::ArrayRef<std::string> choices,
wpi::span<const std::string> choices,
CS_Status* status);
/** @} */
@@ -335,7 +335,7 @@ std::string_view GetSinkDescription(CS_Sink sink,
CS_Status* status);
CS_Property GetSinkProperty(CS_Sink sink, std::string_view name,
CS_Status* status);
wpi::ArrayRef<CS_Property> EnumerateSinkProperties(
wpi::span<CS_Property> EnumerateSinkProperties(
CS_Sink sink, wpi::SmallVectorImpl<CS_Property>& vec, CS_Status* status);
void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status);
CS_Property GetSinkSourceProperty(CS_Sink sink, std::string_view name,
@@ -430,10 +430,10 @@ void Shutdown();
*/
std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status);
wpi::ArrayRef<CS_Source> EnumerateSourceHandles(
wpi::span<CS_Source> EnumerateSourceHandles(
wpi::SmallVectorImpl<CS_Source>& vec, CS_Status* status);
wpi::ArrayRef<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
CS_Status* status);
wpi::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
CS_Status* status);
std::string GetHostname();

View File

@@ -11,6 +11,8 @@
#include <utility>
#include <vector>
#include <wpi/span.h>
#include "cscore_cpp.h"
namespace cs {
@@ -514,7 +516,7 @@ class HttpCamera : public VideoCamera {
* @param urls Array of Camera URLs
* @param kind Camera kind (e.g. kAxis)
*/
HttpCamera(std::string_view name, wpi::ArrayRef<std::string> urls,
HttpCamera(std::string_view name, wpi::span<const std::string> urls,
HttpCameraKind kind = kUnknown);
/**
@@ -539,7 +541,7 @@ class HttpCamera : public VideoCamera {
/**
* Change the URLs used to connect to the camera.
*/
void SetUrls(wpi::ArrayRef<std::string> urls);
void SetUrls(wpi::span<const std::string> urls);
/**
* Change the URLs used to connect to the camera.
@@ -558,7 +560,7 @@ class HttpCamera : public VideoCamera {
*/
class AxisCamera : public HttpCamera {
static std::string HostToUrl(std::string_view host);
static std::vector<std::string> HostToUrl(wpi::ArrayRef<std::string> hosts);
static std::vector<std::string> HostToUrl(wpi::span<const std::string> hosts);
template <typename T>
static std::vector<std::string> HostToUrl(std::initializer_list<T> hosts);
@@ -597,7 +599,7 @@ class AxisCamera : public HttpCamera {
* @param hosts Array of Camera host IPs/DNS names
* @param kind Camera kind (e.g. kAxis)
*/
AxisCamera(std::string_view name, wpi::ArrayRef<std::string> hosts);
AxisCamera(std::string_view name, wpi::span<const std::string> hosts);
/**
* Create a source for an Axis IP camera.
@@ -698,7 +700,7 @@ class ImageSource : public VideoSource {
* @param choices Choices
*/
void SetEnumPropertyChoices(const VideoProperty& property,
wpi::ArrayRef<std::string> choices);
wpi::span<const std::string> choices);
/**
* Configure enum property choices.

View File

@@ -302,7 +302,7 @@ inline HttpCamera::HttpCamera(std::string_view name, const std::string& url,
: HttpCamera(name, std::string_view{url}, kind) {}
inline HttpCamera::HttpCamera(std::string_view name,
wpi::ArrayRef<std::string> urls,
wpi::span<const std::string> urls,
HttpCameraKind kind) {
m_handle = CreateHttpCamera(
name, urls, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
@@ -329,7 +329,7 @@ inline HttpCamera::HttpCameraKind HttpCamera::GetHttpCameraKind() const {
static_cast<int>(::cs::GetHttpCameraKind(m_handle, &m_status)));
}
inline void HttpCamera::SetUrls(wpi::ArrayRef<std::string> urls) {
inline void HttpCamera::SetUrls(wpi::span<const std::string> urls) {
m_status = 0;
::cs::SetHttpCameraUrls(m_handle, urls, &m_status);
}
@@ -351,7 +351,7 @@ inline std::vector<std::string> HttpCamera::GetUrls() const {
}
inline std::vector<std::string> AxisCamera::HostToUrl(
wpi::ArrayRef<std::string> hosts) {
wpi::span<const std::string> hosts) {
std::vector<std::string> rv;
rv.reserve(hosts.size());
for (const auto& host : hosts) {
@@ -381,7 +381,7 @@ inline AxisCamera::AxisCamera(std::string_view name, const std::string& host)
: HttpCamera(name, HostToUrl(std::string_view{host}), kAxis) {}
inline AxisCamera::AxisCamera(std::string_view name,
wpi::ArrayRef<std::string> hosts)
wpi::span<const std::string> hosts)
: HttpCamera(name, HostToUrl(hosts), kAxis) {}
template <typename T>
@@ -452,7 +452,7 @@ inline VideoProperty ImageSource::CreateStringProperty(std::string_view name,
}
inline void ImageSource::SetEnumPropertyChoices(
const VideoProperty& property, wpi::ArrayRef<std::string> choices) {
const VideoProperty& property, wpi::span<const std::string> choices) {
m_status = 0;
SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices, &m_status);
}