mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Upgrade to C++20 (#4239)
* Use explicit this capture required by C++20 * Use C++20 span * Replace wpi::numbers with std::numbers * Fix C++20 clang-tidy warning false positive in fmt * Remove ciso646 include since C++20 removed that header * Fix global-buffer-overflow asan warnings in ntcore tests * Add DIOSetProxy constructor to HAL * Upgrade MSVC compiler to 2022 * Bump native-utils to 2023.2.7 (changes to std=c++20) Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
This commit is contained in:
@@ -52,9 +52,9 @@ class CImpl : public ServerMessageHandler {
|
||||
CImpl(uint64_t curTimeMs, int inst, WireConnection& wire, wpi::Logger& logger,
|
||||
std::function<void(uint32_t repeatMs)> setPeriodic);
|
||||
|
||||
void ProcessIncomingBinary(wpi::span<const uint8_t> data);
|
||||
void ProcessIncomingBinary(std::span<const uint8_t> data);
|
||||
void HandleLocal(std::vector<ClientMessage>&& msgs);
|
||||
void SendOutgoing(wpi::span<const ClientMessage> msgs);
|
||||
void SendOutgoing(std::span<const ClientMessage> msgs);
|
||||
bool SendControl(uint64_t curTimeMs);
|
||||
void SendValues(uint64_t curTimeMs);
|
||||
bool CheckNetworkReady();
|
||||
@@ -120,7 +120,7 @@ CImpl::CImpl(uint64_t curTimeMs, int inst, WireConnection& wire,
|
||||
m_setPeriodic(m_periodMs);
|
||||
}
|
||||
|
||||
void CImpl::ProcessIncomingBinary(wpi::span<const uint8_t> data) {
|
||||
void CImpl::ProcessIncomingBinary(std::span<const uint8_t> data) {
|
||||
for (;;) {
|
||||
if (data.empty()) {
|
||||
break;
|
||||
@@ -419,7 +419,7 @@ void ClientImpl::ProcessIncomingText(std::string_view data) {
|
||||
WireDecodeText(data, *m_impl, m_impl->m_logger);
|
||||
}
|
||||
|
||||
void ClientImpl::ProcessIncomingBinary(wpi::span<const uint8_t> data) {
|
||||
void ClientImpl::ProcessIncomingBinary(std::span<const uint8_t> data) {
|
||||
m_impl->ProcessIncomingBinary(data);
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ void ClientStartup::Publish(NT_Publisher pubHandle, NT_Topic topicHandle,
|
||||
}
|
||||
|
||||
void ClientStartup::Subscribe(NT_Subscriber subHandle,
|
||||
wpi::span<const std::string> prefixes,
|
||||
std::span<const std::string> prefixes,
|
||||
const PubSubOptions& options) {
|
||||
WPI_DEBUG4(m_client.m_impl->m_logger, "StartupSubscribe({})", subHandle);
|
||||
WireEncodeSubscribe(m_textWriter.Add(), Handle{subHandle}.GetIndex(),
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
#include "WireConnection.h"
|
||||
|
||||
@@ -42,7 +41,7 @@ class ClientImpl {
|
||||
~ClientImpl();
|
||||
|
||||
void ProcessIncomingText(std::string_view data);
|
||||
void ProcessIncomingBinary(wpi::span<const uint8_t> data);
|
||||
void ProcessIncomingBinary(std::span<const uint8_t> data);
|
||||
void HandleLocal(std::vector<ClientMessage>&& msgs);
|
||||
|
||||
void SendControl(uint64_t curTimeMs);
|
||||
@@ -66,7 +65,7 @@ class ClientStartup final : public NetworkStartupInterface {
|
||||
void Publish(NT_Publisher pubHandle, NT_Topic topicHandle,
|
||||
std::string_view name, std::string_view typeStr,
|
||||
const wpi::json& properties, const PubSubOptions& options) final;
|
||||
void Subscribe(NT_Subscriber subHandle, wpi::span<const std::string> prefixes,
|
||||
void Subscribe(NT_Subscriber subHandle, std::span<const std::string> prefixes,
|
||||
const PubSubOptions& options) final;
|
||||
void SetValue(NT_Publisher pubHandle, const Value& value) final;
|
||||
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
@@ -45,7 +44,7 @@ class NetworkStartupInterface {
|
||||
const wpi::json& properties,
|
||||
const PubSubOptions& options) = 0;
|
||||
virtual void Subscribe(NT_Subscriber subHandle,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) = 0;
|
||||
virtual void SetValue(NT_Publisher pubHandle, const Value& value) = 0;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -37,7 +38,7 @@ class NetworkLoopQueue : public NetworkInterface {
|
||||
void SetProperties(NT_Topic topicHandle, std::string_view name,
|
||||
const wpi::json& update) final;
|
||||
void Subscribe(NT_Subscriber subHandle,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) final;
|
||||
void Unsubscribe(NT_Subscriber subHandle) final;
|
||||
void SetValue(NT_Publisher pubHandle, const Value& value) final;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -55,7 +56,7 @@ inline void NetworkLoopQueue::SetProperties(NT_Topic topicHandle,
|
||||
}
|
||||
|
||||
inline void NetworkLoopQueue::Subscribe(NT_Subscriber subHandle,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_queue.emplace_back(ClientMessage{SubscribeMsg{
|
||||
|
||||
@@ -91,7 +91,7 @@ class ClientData {
|
||||
virtual ~ClientData() = default;
|
||||
|
||||
virtual void ProcessIncomingText(std::string_view data) = 0;
|
||||
virtual void ProcessIncomingBinary(wpi::span<const uint8_t> data) = 0;
|
||||
virtual void ProcessIncomingBinary(std::span<const uint8_t> data) = 0;
|
||||
|
||||
enum SendMode { kSendDisabled = 0, kSendAll, kSendNormal, kSendImmNoFlush };
|
||||
|
||||
@@ -151,7 +151,7 @@ class ClientData4Base : public ClientData, protected ClientMessageHandler {
|
||||
void ClientUnpublish(int64_t pubuid) final;
|
||||
void ClientSetProperties(std::string_view name,
|
||||
const wpi::json& update) final;
|
||||
void ClientSubscribe(int64_t subuid, wpi::span<const std::string> topicNames,
|
||||
void ClientSubscribe(int64_t subuid, std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) final;
|
||||
void ClientUnsubscribe(int64_t subuid) final;
|
||||
|
||||
@@ -168,7 +168,7 @@ class ClientDataLocal final : public ClientData4Base {
|
||||
: ClientData4Base{"", "", true, [](uint32_t) {}, server, id, logger} {}
|
||||
|
||||
void ProcessIncomingText(std::string_view data) final {}
|
||||
void ProcessIncomingBinary(wpi::span<const uint8_t> data) final {}
|
||||
void ProcessIncomingBinary(std::span<const uint8_t> data) final {}
|
||||
|
||||
void SendValue(TopicData* topic, const Value& value, SendMode mode) final;
|
||||
void SendAnnounce(TopicData* topic, std::optional<int64_t> pubuid) final;
|
||||
@@ -178,7 +178,7 @@ class ClientDataLocal final : public ClientData4Base {
|
||||
void SendOutgoing(uint64_t curTimeMs) final {}
|
||||
void Flush() final {}
|
||||
|
||||
void HandleLocal(wpi::span<const ClientMessage> msgs);
|
||||
void HandleLocal(std::span<const ClientMessage> msgs);
|
||||
};
|
||||
|
||||
class ClientData4 final : public ClientData4Base {
|
||||
@@ -190,7 +190,7 @@ class ClientData4 final : public ClientData4Base {
|
||||
m_wire{wire} {}
|
||||
|
||||
void ProcessIncomingText(std::string_view data) final;
|
||||
void ProcessIncomingBinary(wpi::span<const uint8_t> data) final;
|
||||
void ProcessIncomingBinary(std::span<const uint8_t> data) final;
|
||||
|
||||
void SendValue(TopicData* topic, const Value& value, SendMode mode) final;
|
||||
void SendAnnounce(TopicData* topic, std::optional<int64_t> pubuid) final;
|
||||
@@ -245,7 +245,7 @@ class ClientData3 final : public ClientData, private net3::MessageHandler3 {
|
||||
m_decoder{*this} {}
|
||||
|
||||
void ProcessIncomingText(std::string_view data) final {}
|
||||
void ProcessIncomingBinary(wpi::span<const uint8_t> data) final;
|
||||
void ProcessIncomingBinary(std::span<const uint8_t> data) final;
|
||||
|
||||
void SendValue(TopicData* topic, const Value& value, SendMode mode) final;
|
||||
void SendAnnounce(TopicData* topic, std::optional<int64_t> pubuid) final;
|
||||
@@ -272,9 +272,9 @@ class ClientData3 final : public ClientData, private net3::MessageHandler3 {
|
||||
void FlagsUpdate(unsigned int id, unsigned int flags) final;
|
||||
void EntryDelete(unsigned int id) final;
|
||||
void ExecuteRpc(unsigned int id, unsigned int uid,
|
||||
wpi::span<const uint8_t> params) final {}
|
||||
std::span<const uint8_t> params) final {}
|
||||
void RpcResponse(unsigned int id, unsigned int uid,
|
||||
wpi::span<const uint8_t> result) final {}
|
||||
std::span<const uint8_t> result) final {}
|
||||
|
||||
ServerImpl::Connected3Func m_connected;
|
||||
net3::WireConnection3& m_wire;
|
||||
@@ -350,7 +350,7 @@ struct PublisherData {
|
||||
};
|
||||
|
||||
struct SubscriberData {
|
||||
SubscriberData(ClientData* client, wpi::span<const std::string> topicNames,
|
||||
SubscriberData(ClientData* client, std::span<const std::string> topicNames,
|
||||
int64_t subuid, const PubSubOptions& options)
|
||||
: client{client},
|
||||
topicNames{topicNames.begin(), topicNames.end()},
|
||||
@@ -362,7 +362,7 @@ struct SubscriberData {
|
||||
}
|
||||
}
|
||||
|
||||
void Update(wpi::span<const std::string> topicNames_,
|
||||
void Update(std::span<const std::string> topicNames_,
|
||||
const PubSubOptions& options_) {
|
||||
topicNames = {topicNames_.begin(), topicNames_.end()};
|
||||
options = options_;
|
||||
@@ -599,7 +599,7 @@ void ClientData4Base::ClientSetProperties(std::string_view name,
|
||||
}
|
||||
|
||||
void ClientData4Base::ClientSubscribe(int64_t subuid,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) {
|
||||
DEBUG4("ClientSubscribe({}, ({}), {})", m_id, fmt::join(topicNames, ","),
|
||||
subuid);
|
||||
@@ -757,7 +757,7 @@ void ClientDataLocal::SendPropertiesUpdate(TopicData* topic,
|
||||
}
|
||||
}
|
||||
|
||||
void ClientDataLocal::HandleLocal(wpi::span<const ClientMessage> msgs) {
|
||||
void ClientDataLocal::HandleLocal(std::span<const ClientMessage> msgs) {
|
||||
DEBUG4("{}", "HandleLocal()");
|
||||
// just map as a normal client into client=0 calls
|
||||
for (const auto& elem : msgs) { // NOLINT
|
||||
@@ -782,7 +782,7 @@ void ClientData4::ProcessIncomingText(std::string_view data) {
|
||||
WireDecodeText(data, *this, m_logger);
|
||||
}
|
||||
|
||||
void ClientData4::ProcessIncomingBinary(wpi::span<const uint8_t> data) {
|
||||
void ClientData4::ProcessIncomingBinary(std::span<const uint8_t> data) {
|
||||
for (;;) {
|
||||
if (data.empty()) {
|
||||
break;
|
||||
@@ -947,7 +947,7 @@ bool ClientData3::TopicData3::UpdateFlags(TopicData* topic) {
|
||||
return updated;
|
||||
}
|
||||
|
||||
void ClientData3::ProcessIncomingBinary(wpi::span<const uint8_t> data) {
|
||||
void ClientData3::ProcessIncomingBinary(std::span<const uint8_t> data) {
|
||||
if (!m_decoder.Execute(&data)) {
|
||||
m_wire.Disconnect(m_decoder.GetError());
|
||||
}
|
||||
@@ -1199,7 +1199,7 @@ void ClientData3::ClientHello(std::string_view self_id,
|
||||
PubSubOptions options;
|
||||
options.prefixMatch = true;
|
||||
sub = std::make_unique<SubscriberData>(
|
||||
this, wpi::span<const std::string>{{prefix}}, 0, options);
|
||||
this, std::span<const std::string>{{prefix}}, 0, options);
|
||||
m_periodMs = std::gcd(m_periodMs, sub->periodMs);
|
||||
if (m_periodMs < kMinPeriodMs) {
|
||||
m_periodMs = kMinPeriodMs;
|
||||
@@ -2253,7 +2253,7 @@ void ServerImpl::SendValues(int clientId, uint64_t curTimeMs) {
|
||||
client->Flush();
|
||||
}
|
||||
|
||||
void ServerImpl::HandleLocal(wpi::span<const ClientMessage> msgs) {
|
||||
void ServerImpl::HandleLocal(std::span<const ClientMessage> msgs) {
|
||||
// just map as a normal client into client=0 calls
|
||||
m_impl->m_localClient->HandleLocal(msgs);
|
||||
}
|
||||
@@ -2278,7 +2278,7 @@ void ServerImpl::ProcessIncomingText(int clientId, std::string_view data) {
|
||||
}
|
||||
|
||||
void ServerImpl::ProcessIncomingBinary(int clientId,
|
||||
wpi::span<const uint8_t> data) {
|
||||
std::span<const uint8_t> data) {
|
||||
m_impl->m_clients[clientId]->ProcessIncomingBinary(data);
|
||||
}
|
||||
|
||||
@@ -2329,7 +2329,7 @@ void ServerStartup::Publish(NT_Publisher pubHandle, NT_Topic topicHandle,
|
||||
}
|
||||
|
||||
void ServerStartup::Subscribe(NT_Subscriber subHandle,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) {
|
||||
m_server.m_impl->m_localClient->ClientSubscribe(subHandle, topicNames,
|
||||
options);
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
#include "net3/WireConnection3.h"
|
||||
|
||||
@@ -46,11 +45,11 @@ class ServerImpl final {
|
||||
void SendControl(uint64_t curTimeMs);
|
||||
void SendValues(int clientId, uint64_t curTimeMs);
|
||||
|
||||
void HandleLocal(wpi::span<const ClientMessage> msgs);
|
||||
void HandleLocal(std::span<const ClientMessage> msgs);
|
||||
void SetLocal(LocalInterface* local);
|
||||
|
||||
void ProcessIncomingText(int clientId, std::string_view data);
|
||||
void ProcessIncomingBinary(int clientId, wpi::span<const uint8_t> data);
|
||||
void ProcessIncomingBinary(int clientId, std::span<const uint8_t> data);
|
||||
|
||||
// Returns -1 if cannot add client (e.g. due to duplicate name).
|
||||
// Caller must ensure WireConnection lifetime lasts until RemoveClient() call.
|
||||
@@ -83,7 +82,7 @@ class ServerStartup final : public NetworkStartupInterface {
|
||||
std::string_view name, std::string_view typeStr,
|
||||
const wpi::json& properties, const PubSubOptions& options) final;
|
||||
void Subscribe(NT_Subscriber subHandle,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) final;
|
||||
void SetValue(NT_Publisher pubHandle, const Value& value) final;
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "WebSocketConnection.h"
|
||||
|
||||
#include <span>
|
||||
|
||||
#include <wpi/SpanExtras.h>
|
||||
#include <wpinet/WebSocket.h>
|
||||
|
||||
@@ -37,7 +39,7 @@ void WebSocketConnection::Flush() {
|
||||
m_ws_frames.reserve(m_frames.size());
|
||||
for (auto&& frame : m_frames) {
|
||||
m_ws_frames.emplace_back(frame.opcode,
|
||||
wpi::span{frame.bufs->begin() + frame.start,
|
||||
std::span{frame.bufs->begin() + frame.start,
|
||||
frame.bufs->begin() + frame.end});
|
||||
}
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ void nt::net::WireDecodeText(std::string_view in, ServerMessageHandler& out,
|
||||
::WireDecodeTextImpl(in, out, logger);
|
||||
}
|
||||
|
||||
bool nt::net::WireDecodeBinary(wpi::span<const uint8_t>* in, int64_t* outId,
|
||||
bool nt::net::WireDecodeBinary(std::span<const uint8_t>* in, int64_t* outId,
|
||||
Value* outValue, std::string* error,
|
||||
int64_t localTimeOffset) {
|
||||
mpack_reader_t reader;
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
namespace wpi {
|
||||
class Logger;
|
||||
class json;
|
||||
@@ -35,7 +34,7 @@ class ClientMessageHandler {
|
||||
virtual void ClientSetProperties(std::string_view name,
|
||||
const wpi::json& update) = 0;
|
||||
virtual void ClientSubscribe(int64_t subuid,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) = 0;
|
||||
virtual void ClientUnsubscribe(int64_t subuid) = 0;
|
||||
};
|
||||
@@ -58,7 +57,7 @@ void WireDecodeText(std::string_view in, ServerMessageHandler& out,
|
||||
wpi::Logger& logger);
|
||||
|
||||
// returns true if successfully decoded a message
|
||||
bool WireDecodeBinary(wpi::span<const uint8_t>* in, int64_t* outId,
|
||||
bool WireDecodeBinary(std::span<const uint8_t>* in, int64_t* outId,
|
||||
Value* outValue, std::string* error,
|
||||
int64_t localTimeOffset);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ void nt::net::WireEncodeSetProperties(wpi::raw_ostream& os,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void EncodePrefixes(wpi::raw_ostream& os, wpi::span<const T> topicNames,
|
||||
static void EncodePrefixes(wpi::raw_ostream& os, std::span<const T> topicNames,
|
||||
wpi::json::serializer& s) {
|
||||
os << '[';
|
||||
bool first = true;
|
||||
@@ -75,7 +75,7 @@ static void EncodePrefixes(wpi::raw_ostream& os, wpi::span<const T> topicNames,
|
||||
|
||||
template <typename T>
|
||||
static void WireEncodeSubscribeImpl(wpi::raw_ostream& os, int64_t subuid,
|
||||
wpi::span<const T> topicNames,
|
||||
std::span<const T> topicNames,
|
||||
const PubSubOptions& options) {
|
||||
wpi::json::serializer s{os, ' ', 0};
|
||||
os << "{\"method\":\"" << SubscribeMsg::kMethodStr << "\",\"params\":{";
|
||||
@@ -114,13 +114,13 @@ static void WireEncodeSubscribeImpl(wpi::raw_ostream& os, int64_t subuid,
|
||||
}
|
||||
|
||||
void nt::net::WireEncodeSubscribe(wpi::raw_ostream& os, int64_t subuid,
|
||||
wpi::span<const std::string_view> topicNames,
|
||||
std::span<const std::string_view> topicNames,
|
||||
const PubSubOptions& options) {
|
||||
WireEncodeSubscribeImpl(os, subuid, topicNames, options);
|
||||
}
|
||||
|
||||
void nt::net::WireEncodeSubscribe(wpi::raw_ostream& os, int64_t subuid,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options) {
|
||||
WireEncodeSubscribeImpl(os, subuid, topicNames, options);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
namespace wpi {
|
||||
class json;
|
||||
class raw_ostream;
|
||||
@@ -33,10 +32,10 @@ void WireEncodeUnpublish(wpi::raw_ostream& os, int64_t pubuid);
|
||||
void WireEncodeSetProperties(wpi::raw_ostream& os, std::string_view name,
|
||||
const wpi::json& update);
|
||||
void WireEncodeSubscribe(wpi::raw_ostream& os, int64_t subuid,
|
||||
wpi::span<const std::string_view> topicNames,
|
||||
std::span<const std::string_view> topicNames,
|
||||
const PubSubOptions& options);
|
||||
void WireEncodeSubscribe(wpi::raw_ostream& os, int64_t subuid,
|
||||
wpi::span<const std::string> topicNames,
|
||||
std::span<const std::string> topicNames,
|
||||
const PubSubOptions& options);
|
||||
void WireEncodeUnsubscribe(wpi::raw_ostream& os, int64_t subuid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user