mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#include <hal/simulation/DriverStationData.h>
|
||||
#include <hal/simulation/MockHooks.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/Format.h>
|
||||
|
||||
using namespace halsim;
|
||||
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string_view>
|
||||
|
||||
#include <DSCommPacket.h>
|
||||
#include <fmt/format.h>
|
||||
#include <hal/Extensions.h>
|
||||
#include <wpi/EventLoopRunner.h>
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
#include <wpi/raw_uv_ostream.h>
|
||||
#include <wpi/uv/Tcp.h>
|
||||
#include <wpi/uv/Timer.h>
|
||||
@@ -50,13 +51,13 @@ static SimpleBufferPool<4>& GetBufferPool() {
|
||||
}
|
||||
|
||||
static void HandleTcpDataStream(Buffer& buf, size_t size, DataStore& store) {
|
||||
wpi::StringRef data{buf.base, size};
|
||||
std::string_view data{buf.base, size};
|
||||
while (!data.empty()) {
|
||||
if (store.m_frameSize == (std::numeric_limits<size_t>::max)()) {
|
||||
if (store.m_frame.size() < 2u) {
|
||||
size_t toCopy = (std::min)(2u - store.m_frame.size(), data.size());
|
||||
store.m_frame.append(data.bytes_begin(), data.bytes_begin() + toCopy);
|
||||
data = data.drop_front(toCopy);
|
||||
store.m_frame.append(data.data(), data.data() + toCopy);
|
||||
data.remove_prefix(toCopy);
|
||||
if (store.m_frame.size() < 2u) {
|
||||
return; // need more data
|
||||
}
|
||||
@@ -67,8 +68,8 @@ static void HandleTcpDataStream(Buffer& buf, size_t size, DataStore& store) {
|
||||
if (store.m_frameSize != (std::numeric_limits<size_t>::max)()) {
|
||||
size_t need = store.m_frameSize - (store.m_frame.size() - 2);
|
||||
size_t toCopy = (std::min)(need, data.size());
|
||||
store.m_frame.append(data.bytes_begin(), data.bytes_begin() + toCopy);
|
||||
data = data.drop_front(toCopy);
|
||||
store.m_frame.append(data.data(), data.data() + toCopy);
|
||||
data.remove_prefix(toCopy);
|
||||
need -= toCopy;
|
||||
if (need == 0) {
|
||||
auto ds = store.dsPacket;
|
||||
@@ -118,8 +119,8 @@ static void SetupUdp(wpi::uv::Loop& loop) {
|
||||
udpLocal->Send(simAddr, wpi::ArrayRef<Buffer>{singleByte.get(), 1},
|
||||
[](auto buf, Error err) {
|
||||
if (err) {
|
||||
wpi::errs() << err.str() << "\n";
|
||||
wpi::errs().flush();
|
||||
fmt::print(stderr, "{}\n", err.str());
|
||||
std::fflush(stderr);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -146,8 +147,8 @@ static void SetupUdp(wpi::uv::Loop& loop) {
|
||||
udpLocal->Send(outAddr, sendBufs, [](auto bufs, Error err) {
|
||||
GetBufferPool().Release(bufs);
|
||||
if (err) {
|
||||
wpi::errs() << err.str() << "\n";
|
||||
wpi::errs().flush();
|
||||
fmt::print(stderr, "{}\n", err.str());
|
||||
std::fflush(stderr);
|
||||
}
|
||||
});
|
||||
ds->SendUDPToHALSim();
|
||||
@@ -177,12 +178,12 @@ __declspec(dllexport)
|
||||
static bool once = false;
|
||||
|
||||
if (once) {
|
||||
wpi::errs() << "Error: cannot invoke HALSIM_InitExtension twice.\n";
|
||||
std::fputs("Error: cannot invoke HALSIM_InitExtension twice.\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
once = true;
|
||||
|
||||
wpi::outs() << "DriverStationSocket Initializing.\n";
|
||||
std::puts("DriverStationSocket Initializing.");
|
||||
|
||||
HAL_RegisterExtension("ds_socket", &gDSConnected);
|
||||
|
||||
@@ -192,7 +193,7 @@ __declspec(dllexport)
|
||||
|
||||
eventLoopRunner->ExecAsync(SetupEventLoop);
|
||||
|
||||
wpi::outs() << "DriverStationSocket Initialized!\n";
|
||||
std::puts("DriverStationSocket Initialized!");
|
||||
return 0;
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user