From b243a581b2a1db76271d37b09bd03964f3d4a464 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 19 Nov 2023 10:40:14 -0800 Subject: [PATCH] Use std::bit_cast --- .../src/main/native/cpp/net3/WireDecoder3.cpp | 4 +-- .../src/main/native/cpp/net3/WireEncoder3.cpp | 5 ++-- .../halsim_xrp/src/main/native/cpp/XRP.cpp | 26 +++++++++---------- .../src/netconsoleServer/native/cpp/main.cpp | 5 ++-- wpinet/src/netconsoleTee/native/cpp/main.cpp | 5 ++-- wpiutil/src/main/native/cpp/DataLog.cpp | 12 ++++----- wpiutil/src/main/native/cpp/DataLogReader.cpp | 10 +++---- 7 files changed, 33 insertions(+), 34 deletions(-) diff --git a/ntcore/src/main/native/cpp/net3/WireDecoder3.cpp b/ntcore/src/main/native/cpp/net3/WireDecoder3.cpp index 03bc9c11c9c..dea6349b010 100644 --- a/ntcore/src/main/native/cpp/net3/WireDecoder3.cpp +++ b/ntcore/src/main/native/cpp/net3/WireDecoder3.cpp @@ -5,11 +5,11 @@ #include "WireDecoder3.h" #include +#include #include #include #include -#include #include #include "Message3.h" @@ -74,7 +74,7 @@ std::optional WireDecoder3::SimpleValueReader::Read64( std::optional WireDecoder3::SimpleValueReader::ReadDouble( std::span* in) { if (auto val = Read64(in)) { - return wpi::bit_cast(val.value()); + return std::bit_cast(val.value()); } else { return std::nullopt; } diff --git a/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp b/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp index 7f587c9f604..0ac2bd38ec2 100644 --- a/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp +++ b/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp @@ -4,8 +4,9 @@ #include "WireEncoder3.h" +#include + #include -#include #include #include #include @@ -33,7 +34,7 @@ static void Write32(wpi::raw_ostream& os, uint32_t val) { static void WriteDouble(wpi::raw_ostream& os, double val) { uint8_t buf[8]; - wpi::support::endian::write64be(buf, wpi::bit_cast(val)); + wpi::support::endian::write64be(buf, std::bit_cast(val)); os << buf; } diff --git a/simulation/halsim_xrp/src/main/native/cpp/XRP.cpp b/simulation/halsim_xrp/src/main/native/cpp/XRP.cpp index ffa1a5e56c1..812ebacb9bd 100644 --- a/simulation/halsim_xrp/src/main/native/cpp/XRP.cpp +++ b/simulation/halsim_xrp/src/main/native/cpp/XRP.cpp @@ -4,11 +4,11 @@ #include "XRP.h" +#include #include #include #include -#include #include using namespace wpilibxrp; @@ -245,7 +245,7 @@ void XRP::SetupMotorTag(wpi::raw_uv_ostream& buf) { // Convert the value wpi::support::endian::write32be(value, - wpi::bit_cast(motor.second)); + std::bit_cast(motor.second)); buf << value[0] << value[1] << value[2] << value[3]; } } @@ -261,7 +261,7 @@ void XRP::SetupServoTag(wpi::raw_uv_ostream& buf) { // Convert the value wpi::support::endian::write32be(value, - wpi::bit_cast(servo.second)); + std::bit_cast(servo.second)); buf << value[0] << value[1] << value[2] << value[3]; } } @@ -283,17 +283,17 @@ void XRP::ReadGyroTag(std::span packet) { packet = packet.subspan(2); // Skip past the size and tag float rate_x = - wpi::bit_cast(wpi::support::endian::read32be(&packet[0])); + std::bit_cast(wpi::support::endian::read32be(&packet[0])); float rate_y = - wpi::bit_cast(wpi::support::endian::read32be(&packet[4])); + std::bit_cast(wpi::support::endian::read32be(&packet[4])); float rate_z = - wpi::bit_cast(wpi::support::endian::read32be(&packet[8])); + std::bit_cast(wpi::support::endian::read32be(&packet[8])); float angle_x = - wpi::bit_cast(wpi::support::endian::read32be(&packet[12])); + std::bit_cast(wpi::support::endian::read32be(&packet[12])); float angle_y = - wpi::bit_cast(wpi::support::endian::read32be(&packet[16])); + std::bit_cast(wpi::support::endian::read32be(&packet[16])); float angle_z = - wpi::bit_cast(wpi::support::endian::read32be(&packet[20])); + std::bit_cast(wpi::support::endian::read32be(&packet[20])); // Make the json object wpi::json gyroJson; @@ -314,11 +314,11 @@ void XRP::ReadAccelTag(std::span packet) { packet = packet.subspan(2); // Skip past the size and tag float accel_x = - wpi::bit_cast(wpi::support::endian::read32be(&packet[0])); + std::bit_cast(wpi::support::endian::read32be(&packet[0])); float accel_y = - wpi::bit_cast(wpi::support::endian::read32be(&packet[4])); + std::bit_cast(wpi::support::endian::read32be(&packet[4])); float accel_z = - wpi::bit_cast(wpi::support::endian::read32be(&packet[8])); + std::bit_cast(wpi::support::endian::read32be(&packet[8])); wpi::json accelJson; accelJson["type"] = "Accel"; @@ -409,7 +409,7 @@ void XRP::ReadAnalogTag(std::span packet) { packet = packet.subspan(3); float voltage = - wpi::bit_cast(wpi::support::endian::read32be(&packet[0])); + std::bit_cast(wpi::support::endian::read32be(&packet[0])); wpi::json analogJson; analogJson["type"] = "AI"; diff --git a/wpinet/src/netconsoleServer/native/cpp/main.cpp b/wpinet/src/netconsoleServer/native/cpp/main.cpp index f65ada535a0..8c6a1626855 100644 --- a/wpinet/src/netconsoleServer/native/cpp/main.cpp +++ b/wpinet/src/netconsoleServer/native/cpp/main.cpp @@ -8,15 +8,14 @@ #include #endif +#include #include #include #include #include -#include #include #include -#include #include #include @@ -52,7 +51,7 @@ static bool NewlineBuffer(std::string& rem, uv::Buffer& buf, size_t len, if (tcp) { // Header is 2 byte len, 1 byte type, 4 byte timestamp, 2 byte sequence num uint32_t ts = - wpi::bit_cast((wpi::Now() - startTime) * 1.0e-6); + std::bit_cast((wpi::Now() - startTime) * 1.0e-6); uint16_t len = rem.size() + toCopy.size() + 1 + 4 + 2; const uint8_t header[] = {static_cast((len >> 8) & 0xff), static_cast(len & 0xff), diff --git a/wpinet/src/netconsoleTee/native/cpp/main.cpp b/wpinet/src/netconsoleTee/native/cpp/main.cpp index bd3da809e9a..142719ba75d 100644 --- a/wpinet/src/netconsoleTee/native/cpp/main.cpp +++ b/wpinet/src/netconsoleTee/native/cpp/main.cpp @@ -2,15 +2,14 @@ // 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 #include #include -#include #include #include -#include #include #include @@ -43,7 +42,7 @@ static bool NewlineBuffer(std::string& rem, uv::Buffer& buf, size_t len, if (tcp) { // Header is 2 byte len, 1 byte type, 4 byte timestamp, 2 byte sequence num uint32_t ts = - wpi::bit_cast((wpi::Now() - startTime) * 1.0e-6); + std::bit_cast((wpi::Now() - startTime) * 1.0e-6); uint16_t len = rem.size() + toCopy.size() + 1 + 4 + 2; const uint8_t header[] = {static_cast((len >> 8) & 0xff), static_cast(len & 0xff), diff --git a/wpiutil/src/main/native/cpp/DataLog.cpp b/wpiutil/src/main/native/cpp/DataLog.cpp index 86649beecf4..705da5c0d37 100644 --- a/wpiutil/src/main/native/cpp/DataLog.cpp +++ b/wpiutil/src/main/native/cpp/DataLog.cpp @@ -377,7 +377,7 @@ void DataLog::AppendFloat(int entry, float value, int64_t timestamp) { if constexpr (std::endian::native == std::endian::little) { std::memcpy(buf, &value, 4); } else { - wpi::support::endian::write32le(buf, wpi::bit_cast(value)); + wpi::support::endian::write32le(buf, std::bit_cast(value)); } } @@ -393,7 +393,7 @@ void DataLog::AppendDouble(int entry, double value, int64_t timestamp) { if constexpr (std::endian::native == std::endian::little) { std::memcpy(buf, &value, 8); } else { - wpi::support::endian::write64le(buf, wpi::bit_cast(value)); + wpi::support::endian::write64le(buf, std::bit_cast(value)); } } @@ -508,14 +508,14 @@ void DataLog::AppendFloatArray(int entry, std::span arr, while ((arr.size() * 4) > kBlockSize) { buf = Reserve(kBlockSize); for (auto val : arr.subspan(0, kBlockSize / 4)) { - wpi::support::endian::write32le(buf, wpi::bit_cast(val)); + wpi::support::endian::write32le(buf, std::bit_cast(val)); buf += 4; } arr = arr.subspan(kBlockSize / 4); } buf = Reserve(arr.size() * 4); for (auto val : arr) { - wpi::support::endian::write32le(buf, wpi::bit_cast(val)); + wpi::support::endian::write32le(buf, std::bit_cast(val)); buf += 4; } } @@ -540,14 +540,14 @@ void DataLog::AppendDoubleArray(int entry, std::span arr, while ((arr.size() * 8) > kBlockSize) { buf = Reserve(kBlockSize); for (auto val : arr.subspan(0, kBlockSize / 8)) { - wpi::support::endian::write64le(buf, wpi::bit_cast(val)); + wpi::support::endian::write64le(buf, std::bit_cast(val)); buf += 8; } arr = arr.subspan(kBlockSize / 8); } buf = Reserve(arr.size() * 8); for (auto val : arr) { - wpi::support::endian::write64le(buf, wpi::bit_cast(val)); + wpi::support::endian::write64le(buf, std::bit_cast(val)); buf += 8; } } diff --git a/wpiutil/src/main/native/cpp/DataLogReader.cpp b/wpiutil/src/main/native/cpp/DataLogReader.cpp index 17b2c9fa018..7eb88a6518b 100644 --- a/wpiutil/src/main/native/cpp/DataLogReader.cpp +++ b/wpiutil/src/main/native/cpp/DataLogReader.cpp @@ -4,11 +4,11 @@ #include "wpi/DataLogReader.h" +#include #include #include "wpi/DataLog.h" #include "wpi/Endian.h" -#include "wpi/MathExtras.h" using namespace wpi::log; @@ -97,7 +97,7 @@ bool DataLogRecord::GetFloat(float* value) const { if (m_data.size() != 4) { return false; } - *value = wpi::bit_cast(wpi::support::endian::read32le(m_data.data())); + *value = std::bit_cast(wpi::support::endian::read32le(m_data.data())); return true; } @@ -105,7 +105,7 @@ bool DataLogRecord::GetDouble(double* value) const { if (m_data.size() != 8) { return false; } - *value = wpi::bit_cast(wpi::support::endian::read64le(m_data.data())); + *value = std::bit_cast(wpi::support::endian::read64le(m_data.data())); return true; } @@ -143,7 +143,7 @@ bool DataLogRecord::GetFloatArray(std::vector* arr) const { arr->reserve(m_data.size() / 4); for (size_t pos = 0; pos < m_data.size(); pos += 4) { arr->push_back( - wpi::bit_cast(wpi::support::endian::read32le(&m_data[pos]))); + std::bit_cast(wpi::support::endian::read32le(&m_data[pos]))); } return true; } @@ -156,7 +156,7 @@ bool DataLogRecord::GetDoubleArray(std::vector* arr) const { arr->reserve(m_data.size() / 8); for (size_t pos = 0; pos < m_data.size(); pos += 8) { arr->push_back( - wpi::bit_cast(wpi::support::endian::read64le(&m_data[pos]))); + std::bit_cast(wpi::support::endian::read64le(&m_data[pos]))); } return true; }