mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41: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:
@@ -6,12 +6,11 @@
|
||||
#define WPIUTIL_WPI_BASE64_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
class SmallVectorImpl;
|
||||
@@ -26,8 +25,8 @@ std::string_view Base64Decode(std::string_view encoded, size_t* num_read,
|
||||
|
||||
size_t Base64Decode(std::string_view encoded, std::vector<uint8_t>* plain);
|
||||
|
||||
span<uint8_t> Base64Decode(std::string_view encoded, size_t* num_read,
|
||||
SmallVectorImpl<uint8_t>& buf);
|
||||
std::span<uint8_t> Base64Decode(std::string_view encoded, size_t* num_read,
|
||||
SmallVectorImpl<uint8_t>& buf);
|
||||
|
||||
void Base64Encode(raw_ostream& os, std::string_view plain);
|
||||
|
||||
@@ -36,11 +35,11 @@ void Base64Encode(std::string_view plain, std::string* encoded);
|
||||
std::string_view Base64Encode(std::string_view plain,
|
||||
SmallVectorImpl<char>& buf);
|
||||
|
||||
void Base64Encode(raw_ostream& os, span<const uint8_t> plain);
|
||||
void Base64Encode(raw_ostream& os, std::span<const uint8_t> plain);
|
||||
|
||||
void Base64Encode(span<const uint8_t> plain, std::string* encoded);
|
||||
void Base64Encode(std::span<const uint8_t> plain, std::string* encoded);
|
||||
|
||||
std::string_view Base64Encode(span<const uint8_t> plain,
|
||||
std::string_view Base64Encode(std::span<const uint8_t> plain,
|
||||
SmallVectorImpl<char>& buf);
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
@@ -18,7 +19,6 @@
|
||||
#include "wpi/StringMap.h"
|
||||
#include "wpi/condition_variable.h"
|
||||
#include "wpi/mutex.h"
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace wpi {
|
||||
class Logger;
|
||||
@@ -106,7 +106,7 @@ class DataLog final {
|
||||
* this is a time/storage tradeoff
|
||||
* @param extraHeader extra header data
|
||||
*/
|
||||
explicit DataLog(std::function<void(wpi::span<const uint8_t> data)> write,
|
||||
explicit DataLog(std::function<void(std::span<const uint8_t> data)> write,
|
||||
double period = 0.25, std::string_view extraHeader = "");
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ class DataLog final {
|
||||
* @param extraHeader extra header data
|
||||
*/
|
||||
explicit DataLog(wpi::Logger& msglog,
|
||||
std::function<void(wpi::span<const uint8_t> data)> write,
|
||||
std::function<void(std::span<const uint8_t> data)> write,
|
||||
double period = 0.25, std::string_view extraHeader = "");
|
||||
|
||||
~DataLog();
|
||||
@@ -196,7 +196,7 @@ class DataLog final {
|
||||
* @param data Data to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void AppendRaw(int entry, wpi::span<const uint8_t> data, int64_t timestamp);
|
||||
void AppendRaw(int entry, std::span<const uint8_t> data, int64_t timestamp);
|
||||
|
||||
/**
|
||||
* Appends a record to the log.
|
||||
@@ -205,7 +205,7 @@ class DataLog final {
|
||||
* @param data Data to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void AppendRaw2(int entry, wpi::span<const wpi::span<const uint8_t>> data,
|
||||
void AppendRaw2(int entry, std::span<const std::span<const uint8_t>> data,
|
||||
int64_t timestamp);
|
||||
|
||||
void AppendBoolean(int entry, bool value, int64_t timestamp);
|
||||
@@ -213,33 +213,33 @@ class DataLog final {
|
||||
void AppendFloat(int entry, float value, int64_t timestamp);
|
||||
void AppendDouble(int entry, double value, int64_t timestamp);
|
||||
void AppendString(int entry, std::string_view value, int64_t timestamp);
|
||||
void AppendBooleanArray(int entry, wpi::span<const bool> arr,
|
||||
void AppendBooleanArray(int entry, std::span<const bool> arr,
|
||||
int64_t timestamp);
|
||||
void AppendBooleanArray(int entry, wpi::span<const int> arr,
|
||||
void AppendBooleanArray(int entry, std::span<const int> arr,
|
||||
int64_t timestamp);
|
||||
void AppendBooleanArray(int entry, wpi::span<const uint8_t> arr,
|
||||
void AppendBooleanArray(int entry, std::span<const uint8_t> arr,
|
||||
int64_t timestamp);
|
||||
void AppendIntegerArray(int entry, wpi::span<const int64_t> arr,
|
||||
void AppendIntegerArray(int entry, std::span<const int64_t> arr,
|
||||
int64_t timestamp);
|
||||
void AppendFloatArray(int entry, wpi::span<const float> arr,
|
||||
void AppendFloatArray(int entry, std::span<const float> arr,
|
||||
int64_t timestamp);
|
||||
void AppendDoubleArray(int entry, wpi::span<const double> arr,
|
||||
void AppendDoubleArray(int entry, std::span<const double> arr,
|
||||
int64_t timestamp);
|
||||
void AppendStringArray(int entry, wpi::span<const std::string> arr,
|
||||
void AppendStringArray(int entry, std::span<const std::string> arr,
|
||||
int64_t timestamp);
|
||||
void AppendStringArray(int entry, wpi::span<const std::string_view> arr,
|
||||
void AppendStringArray(int entry, std::span<const std::string_view> arr,
|
||||
int64_t timestamp);
|
||||
|
||||
private:
|
||||
void WriterThreadMain(std::string_view dir);
|
||||
void WriterThreadMain(
|
||||
std::function<void(wpi::span<const uint8_t> data)> write);
|
||||
std::function<void(std::span<const uint8_t> data)> write);
|
||||
|
||||
// must be called with m_mutex held
|
||||
uint8_t* StartRecord(uint32_t entry, uint64_t timestamp, uint32_t payloadSize,
|
||||
size_t reserveSize);
|
||||
uint8_t* Reserve(size_t size);
|
||||
void AppendImpl(wpi::span<const uint8_t> data);
|
||||
void AppendImpl(std::span<const uint8_t> data);
|
||||
void AppendStringImpl(std::string_view str);
|
||||
|
||||
wpi::Logger& m_msglog;
|
||||
@@ -338,7 +338,7 @@ class RawLogEntry : public DataLogEntry {
|
||||
* @param data Data to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const uint8_t> data, int64_t timestamp = 0) {
|
||||
void Append(std::span<const uint8_t> data, int64_t timestamp = 0) {
|
||||
m_log->AppendRaw(m_entry, data, timestamp);
|
||||
}
|
||||
};
|
||||
@@ -493,7 +493,7 @@ class BooleanArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const bool> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const bool> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendBooleanArray(m_entry, arr, timestamp);
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ class BooleanArrayLogEntry : public DataLogEntry {
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(std::initializer_list<bool> arr, int64_t timestamp = 0) {
|
||||
Append(wpi::span{arr.begin(), arr.end()}, timestamp);
|
||||
Append(std::span{arr.begin(), arr.end()}, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -513,7 +513,7 @@ class BooleanArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const int> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const int> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendBooleanArray(m_entry, arr, timestamp);
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ class BooleanArrayLogEntry : public DataLogEntry {
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(std::initializer_list<int> arr, int64_t timestamp = 0) {
|
||||
Append(wpi::span{arr.begin(), arr.end()}, timestamp);
|
||||
Append(std::span{arr.begin(), arr.end()}, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -533,7 +533,7 @@ class BooleanArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const uint8_t> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const uint8_t> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendBooleanArray(m_entry, arr, timestamp);
|
||||
}
|
||||
};
|
||||
@@ -559,7 +559,7 @@ class IntegerArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const int64_t> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const int64_t> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendIntegerArray(m_entry, arr, timestamp);
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ class FloatArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const float> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const float> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendFloatArray(m_entry, arr, timestamp);
|
||||
}
|
||||
|
||||
@@ -630,7 +630,7 @@ class DoubleArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const double> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const double> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendDoubleArray(m_entry, arr, timestamp);
|
||||
}
|
||||
|
||||
@@ -666,7 +666,7 @@ class StringArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const std::string> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const std::string> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendStringArray(m_entry, arr, timestamp);
|
||||
}
|
||||
|
||||
@@ -676,7 +676,7 @@ class StringArrayLogEntry : public DataLogEntry {
|
||||
* @param arr Values to record
|
||||
* @param timestamp Time stamp (may be 0 to indicate now)
|
||||
*/
|
||||
void Append(wpi::span<const std::string_view> arr, int64_t timestamp = 0) {
|
||||
void Append(std::span<const std::string_view> arr, int64_t timestamp = 0) {
|
||||
m_log->AppendStringArray(m_entry, arr, timestamp);
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ class StringArrayLogEntry : public DataLogEntry {
|
||||
*/
|
||||
void Append(std::initializer_list<std::string_view> arr,
|
||||
int64_t timestamp = 0) {
|
||||
Append(wpi::span<const std::string_view>{arr.begin(), arr.end()},
|
||||
Append(std::span<const std::string_view>{arr.begin(), arr.end()},
|
||||
timestamp);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "wpi/MemoryBuffer.h"
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace wpi::log {
|
||||
|
||||
@@ -54,7 +54,7 @@ struct MetadataRecordData {
|
||||
class DataLogRecord {
|
||||
public:
|
||||
DataLogRecord() = default;
|
||||
DataLogRecord(int entry, int64_t timestamp, wpi::span<const uint8_t> data)
|
||||
DataLogRecord(int entry, int64_t timestamp, std::span<const uint8_t> data)
|
||||
: m_timestamp{timestamp}, m_data{data}, m_entry{entry} {}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ class DataLogRecord {
|
||||
* Gets the raw data. Use the GetX functions to decode based on the data type
|
||||
* in the entry's start record.
|
||||
*/
|
||||
wpi::span<const uint8_t> GetRaw() const { return m_data; }
|
||||
std::span<const uint8_t> GetRaw() const { return m_data; }
|
||||
|
||||
/**
|
||||
* Returns true if the record is a control record.
|
||||
@@ -241,7 +241,7 @@ class DataLogRecord {
|
||||
|
||||
private:
|
||||
int64_t m_timestamp{0};
|
||||
wpi::span<const uint8_t> m_data;
|
||||
std::span<const uint8_t> m_data;
|
||||
int m_entry{-1};
|
||||
};
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "wpi/mpack.h"
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace mpack {
|
||||
|
||||
@@ -19,13 +19,13 @@ inline void mpack_write_str(mpack_writer_t* writer, std::string_view str) {
|
||||
}
|
||||
|
||||
inline void mpack_write_bytes(mpack_writer_t* writer,
|
||||
wpi::span<const uint8_t> data) {
|
||||
std::span<const uint8_t> data) {
|
||||
mpack_write_bytes(writer, reinterpret_cast<const char*>(data.data()),
|
||||
data.size());
|
||||
}
|
||||
|
||||
inline void mpack_reader_init_data(mpack_reader_t* reader,
|
||||
wpi::span<const uint8_t> data) {
|
||||
std::span<const uint8_t> data) {
|
||||
mpack_reader_init_data(reader, reinterpret_cast<const char*>(data.data()),
|
||||
data.size());
|
||||
}
|
||||
|
||||
@@ -5,21 +5,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "wpi/span.h"
|
||||
#include <span>
|
||||
|
||||
namespace wpi {
|
||||
|
||||
/// Drop the first \p N elements of the array.
|
||||
template <typename T>
|
||||
constexpr span<T> drop_front(span<T> in, typename span<T>::size_type n = 1) {
|
||||
constexpr std::span<T> drop_front(std::span<T> in,
|
||||
typename std::span<T>::size_type n = 1) {
|
||||
assert(in.size() >= n && "Dropping more elements than exist");
|
||||
return in.subspan(n, in.size() - n);
|
||||
}
|
||||
|
||||
/// Drop the last \p N elements of the array.
|
||||
template <typename T>
|
||||
constexpr span<T> drop_back(span<T> in, typename span<T>::size_type n = 1) {
|
||||
constexpr std::span<T> drop_back(std::span<T> in,
|
||||
typename std::span<T>::size_type n = 1) {
|
||||
assert(in.size() >= n && "Dropping more elements than exist");
|
||||
return in.subspan(0, in.size() - n);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <initializer_list>
|
||||
|
||||
#include "wpi/span.h"
|
||||
#include <span>
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -149,8 +148,8 @@ bool WaitForObject(WPI_Handle handle, double timeout, bool* timedOut);
|
||||
* least the size of the handles input array
|
||||
* @return array of signaled handles (points into signaled array)
|
||||
*/
|
||||
wpi::span<WPI_Handle> WaitForObjects(wpi::span<const WPI_Handle> handles,
|
||||
wpi::span<WPI_Handle> signaled);
|
||||
std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
|
||||
std::span<WPI_Handle> signaled);
|
||||
|
||||
/**
|
||||
* Waits for one or more handles to be signaled.
|
||||
@@ -163,9 +162,9 @@ wpi::span<WPI_Handle> WaitForObjects(wpi::span<const WPI_Handle> handles,
|
||||
* least the size of the handles input array
|
||||
* @return array of signaled handles (points into signaled array)
|
||||
*/
|
||||
inline wpi::span<WPI_Handle> WaitForObjects(
|
||||
std::initializer_list<WPI_Handle> handles, wpi::span<WPI_Handle> signaled) {
|
||||
return WaitForObjects(wpi::span{handles.begin(), handles.size()}, signaled);
|
||||
inline std::span<WPI_Handle> WaitForObjects(
|
||||
std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled) {
|
||||
return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,8 +181,8 @@ inline wpi::span<WPI_Handle> WaitForObjects(
|
||||
* handle being signaled; set to false otherwise (output)
|
||||
* @return array of signaled handles (points into signaled array)
|
||||
*/
|
||||
wpi::span<WPI_Handle> WaitForObjects(wpi::span<const WPI_Handle> handles,
|
||||
wpi::span<WPI_Handle> signaled,
|
||||
std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
|
||||
std::span<WPI_Handle> signaled,
|
||||
double timeout, bool* timedOut);
|
||||
/**
|
||||
* Waits for one or more handles to be signaled, with timeout.
|
||||
@@ -199,10 +198,10 @@ wpi::span<WPI_Handle> WaitForObjects(wpi::span<const WPI_Handle> handles,
|
||||
* handle being signaled; set to false otherwise (output)
|
||||
* @return array of signaled handles (points into signaled array)
|
||||
*/
|
||||
inline wpi::span<WPI_Handle> WaitForObjects(
|
||||
std::initializer_list<WPI_Handle> handles, wpi::span<WPI_Handle> signaled,
|
||||
inline std::span<WPI_Handle> WaitForObjects(
|
||||
std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled,
|
||||
double timeout, bool* timedOut) {
|
||||
return WaitForObjects(wpi::span{handles.begin(), handles.size()}, signaled,
|
||||
return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled,
|
||||
timeout, timedOut);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <queue>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
@@ -21,7 +22,6 @@
|
||||
#include "wpi/StringExtras.h"
|
||||
#include "wpi/mutex.h"
|
||||
#include "wpi/raw_ostream.h"
|
||||
#include "wpi/span.h"
|
||||
|
||||
/** Java Native Interface (JNI) utility functions */
|
||||
namespace wpi::java {
|
||||
@@ -154,7 +154,7 @@ class JStringRef {
|
||||
jsize size = env->GetStringLength(str);
|
||||
const jchar* chars = env->GetStringCritical(str, nullptr);
|
||||
if (chars) {
|
||||
convertUTF16ToUTF8String(wpi::span<const jchar>(chars, size), m_str);
|
||||
convertUTF16ToUTF8String(std::span<const jchar>(chars, size), m_str);
|
||||
env->ReleaseStringCritical(str, chars);
|
||||
}
|
||||
} else {
|
||||
@@ -181,7 +181,7 @@ namespace detail {
|
||||
template <typename C, typename T>
|
||||
class JArrayRefInner {
|
||||
public:
|
||||
operator span<const T>() const { // NOLINT
|
||||
operator std::span<const T>() const { // NOLINT
|
||||
return static_cast<const C*>(this)->array();
|
||||
}
|
||||
};
|
||||
@@ -203,7 +203,7 @@ class JArrayRefInner<C, jbyte> {
|
||||
return {reinterpret_cast<const char*>(arr.data()), arr.size()};
|
||||
}
|
||||
|
||||
span<const uint8_t> uarray() const {
|
||||
std::span<const uint8_t> uarray() const {
|
||||
auto arr = static_cast<const C*>(this)->array();
|
||||
if (arr.empty()) {
|
||||
return {};
|
||||
@@ -222,7 +222,7 @@ class JArrayRefInner<C, jlong> {
|
||||
template <typename U,
|
||||
typename = std::enable_if_t<sizeof(U) == sizeof(jlong) &&
|
||||
std::is_integral_v<U>>>
|
||||
operator span<const U>() const { // NOLINT
|
||||
operator std::span<const U>() const { // NOLINT
|
||||
auto arr = static_cast<const C*>(this)->array();
|
||||
if (arr.empty()) {
|
||||
return {};
|
||||
@@ -239,7 +239,7 @@ class JArrayRefBase : public JArrayRefInner<JArrayRefBase<T>, T> {
|
||||
public:
|
||||
explicit operator bool() const { return this->m_elements != nullptr; }
|
||||
|
||||
span<const T> array() const {
|
||||
std::span<const T> array() const {
|
||||
if (!this->m_elements) {
|
||||
return {};
|
||||
}
|
||||
@@ -406,7 +406,7 @@ namespace detail {
|
||||
template <typename T,
|
||||
bool = (std::is_integral<T>::value && sizeof(jint) == sizeof(T))>
|
||||
struct ConvertIntArray {
|
||||
static jintArray ToJava(JNIEnv* env, span<const T> arr) {
|
||||
static jintArray ToJava(JNIEnv* env, std::span<const T> arr) {
|
||||
jintArray jarr = env->NewIntArray(arr.size());
|
||||
if (!jarr) {
|
||||
return nullptr;
|
||||
@@ -429,7 +429,7 @@ struct ConvertIntArray {
|
||||
*/
|
||||
template <typename T>
|
||||
struct ConvertIntArray<T, true> {
|
||||
static jintArray ToJava(JNIEnv* env, span<const T> arr) {
|
||||
static jintArray ToJava(JNIEnv* env, std::span<const T> arr) {
|
||||
jintArray jarr = env->NewIntArray(arr.size());
|
||||
if (!jarr) {
|
||||
return nullptr;
|
||||
@@ -449,7 +449,7 @@ struct ConvertIntArray<T, true> {
|
||||
* @param arr Span to convert.
|
||||
*/
|
||||
template <typename T>
|
||||
inline jintArray MakeJIntArray(JNIEnv* env, span<const T> arr) {
|
||||
inline jintArray MakeJIntArray(JNIEnv* env, std::span<const T> arr) {
|
||||
return detail::ConvertIntArray<T>::ToJava(env, arr);
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ inline jintArray MakeJIntArray(JNIEnv* env, span<const T> arr) {
|
||||
* @param arr Span to convert.
|
||||
*/
|
||||
template <typename T>
|
||||
inline jintArray MakeJIntArray(JNIEnv* env, span<T> arr) {
|
||||
inline jintArray MakeJIntArray(JNIEnv* env, std::span<T> arr) {
|
||||
return detail::ConvertIntArray<T>::ToJava(env, arr);
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ inline jintArray MakeJIntArray(JNIEnv* env, const std::vector<T>& arr) {
|
||||
* @param env JRE environment.
|
||||
* @param str span to convert.
|
||||
*/
|
||||
inline jbyteArray MakeJByteArray(JNIEnv* env, span<const uint8_t> str) {
|
||||
inline jbyteArray MakeJByteArray(JNIEnv* env, std::span<const uint8_t> str) {
|
||||
jbyteArray jarr = env->NewByteArray(str.size());
|
||||
if (!jarr) {
|
||||
return nullptr;
|
||||
@@ -514,7 +514,7 @@ inline jbyteArray MakeJByteArray(JNIEnv* env, span<const uint8_t> str) {
|
||||
* @param env JRE environment.
|
||||
* @param arr Array to convert.
|
||||
*/
|
||||
inline jbooleanArray MakeJBooleanArray(JNIEnv* env, span<const int> arr) {
|
||||
inline jbooleanArray MakeJBooleanArray(JNIEnv* env, std::span<const int> arr) {
|
||||
jbooleanArray jarr = env->NewBooleanArray(arr.size());
|
||||
if (!jarr) {
|
||||
return nullptr;
|
||||
@@ -537,7 +537,7 @@ inline jbooleanArray MakeJBooleanArray(JNIEnv* env, span<const int> arr) {
|
||||
* @param env JRE environment.
|
||||
* @param arr Array to convert.
|
||||
*/
|
||||
inline jbooleanArray MakeJBooleanArray(JNIEnv* env, span<const bool> arr) {
|
||||
inline jbooleanArray MakeJBooleanArray(JNIEnv* env, std::span<const bool> arr) {
|
||||
jbooleanArray jarr = env->NewBooleanArray(arr.size());
|
||||
if (!jarr) {
|
||||
return nullptr;
|
||||
@@ -556,14 +556,14 @@ inline jbooleanArray MakeJBooleanArray(JNIEnv* env, span<const bool> arr) {
|
||||
|
||||
// Other MakeJ*Array conversions.
|
||||
|
||||
#define WPI_JNI_MAKEJARRAY(T, F) \
|
||||
inline T##Array MakeJ##F##Array(JNIEnv* env, span<const T> arr) { \
|
||||
T##Array jarr = env->New##F##Array(arr.size()); \
|
||||
if (!jarr) { \
|
||||
return nullptr; \
|
||||
} \
|
||||
env->Set##F##ArrayRegion(jarr, 0, arr.size(), arr.data()); \
|
||||
return jarr; \
|
||||
#define WPI_JNI_MAKEJARRAY(T, F) \
|
||||
inline T##Array MakeJ##F##Array(JNIEnv* env, std::span<const T> arr) { \
|
||||
T##Array jarr = env->New##F##Array(arr.size()); \
|
||||
if (!jarr) { \
|
||||
return nullptr; \
|
||||
} \
|
||||
env->Set##F##ArrayRegion(jarr, 0, arr.size(), arr.data()); \
|
||||
return jarr; \
|
||||
}
|
||||
|
||||
WPI_JNI_MAKEJARRAY(jboolean, Boolean)
|
||||
@@ -593,7 +593,8 @@ inline jlongArray MakeJLongArray(JNIEnv* env, const T& arr) {
|
||||
* @param env JRE environment.
|
||||
* @param arr Array to convert.
|
||||
*/
|
||||
inline jobjectArray MakeJStringArray(JNIEnv* env, span<const std::string> arr) {
|
||||
inline jobjectArray MakeJStringArray(JNIEnv* env,
|
||||
std::span<const std::string> arr) {
|
||||
static JClass stringCls{env, "java/lang/String"};
|
||||
if (!stringCls) {
|
||||
return nullptr;
|
||||
@@ -615,7 +616,8 @@ inline jobjectArray MakeJStringArray(JNIEnv* env, span<const std::string> arr) {
|
||||
* @param env JRE environment.
|
||||
* @param arr Array to convert.
|
||||
*/
|
||||
inline jobjectArray MakeJStringArray(JNIEnv* env, span<std::string_view> arr) {
|
||||
inline jobjectArray MakeJStringArray(JNIEnv* env,
|
||||
std::span<std::string_view> arr) {
|
||||
static JClass stringCls{env, "java/lang/String"};
|
||||
if (!stringCls) {
|
||||
return nullptr;
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "wpi/span.h"
|
||||
#include <span>
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -100,7 +99,7 @@ class Uleb128Reader {
|
||||
* is left when function returns).
|
||||
* @return value (in std::optional)
|
||||
*/
|
||||
std::optional<uint64_t> ReadOne(span<const uint8_t>* in);
|
||||
std::optional<uint64_t> ReadOne(std::span<const uint8_t>* in);
|
||||
|
||||
private:
|
||||
uint64_t m_result = 0;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/numbers"
|
||||
|
||||
// clang-format off
|
||||
#ifdef _MSC_VER
|
||||
#pragma message("warning: Use <wpi/numbers> and wpi::numbers instead to reflect C++20 <numbers> and std::numbers")
|
||||
#else
|
||||
#warning "Use <wpi/numbers> and wpi::numbers instead to reflect C++20 <numbers> and std::numbers"
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
namespace wpi::math {
|
||||
using namespace wpi::numbers;
|
||||
} // namespace wpi::math
|
||||
@@ -1,64 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace wpi::numbers {
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T e_v = 2.718281828459045235360287471352662498L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T log2e_v = 1.442695040888963407359924681001892137L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T log10e_v = 0.434294481903251827651128918916605082L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T pi_v = 3.141592653589793238462643383279502884L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T inv_pi_v = 0.318309886183790671537767526745028724L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T inv_sqrtpi_v = 0.564189583547756286948079451560772586L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T ln2_v = 0.693147180559945309417232121458176568L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T ln10_v = 2.302585092994045684017991454684364208L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T sqrt2_v = 1.414213562373095048801688724209698078L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T sqrt3_v = 1.732050807568877293527446341505872366L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T inv_sqrt3_v = 0.577350269189625764509148780501957456L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T egamma_v = 0.577215664901532860606512090082402431L;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
|
||||
inline constexpr T phi_v = 1.618033988749894848204586834365638117L;
|
||||
|
||||
inline constexpr double e = e_v<double>;
|
||||
inline constexpr double log2e = log2e_v<double>;
|
||||
inline constexpr double log10e = log10e_v<double>;
|
||||
inline constexpr double pi = pi_v<double>;
|
||||
inline constexpr double inv_pi = inv_pi_v<double>;
|
||||
inline constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
|
||||
inline constexpr double ln2 = ln2_v<double>;
|
||||
inline constexpr double ln10 = ln10_v<double>;
|
||||
inline constexpr double sqrt2 = sqrt2_v<double>;
|
||||
inline constexpr double sqrt3 = sqrt3_v<double>;
|
||||
inline constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
|
||||
inline constexpr double egamma = egamma_v<double>;
|
||||
inline constexpr double phi = phi_v<double>;
|
||||
|
||||
} // namespace wpi::numbers
|
||||
@@ -9,13 +9,13 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
#include "wpi/SmallVector.h"
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -133,9 +133,9 @@ class raw_mem_istream : public raw_istream {
|
||||
// not const as we don't want to allow temporaries
|
||||
explicit raw_mem_istream(std::string& str)
|
||||
: raw_mem_istream(str.data(), str.size()) {}
|
||||
explicit raw_mem_istream(span<const char> mem)
|
||||
explicit raw_mem_istream(std::span<const char> mem)
|
||||
: raw_mem_istream(mem.data(), mem.size()) {}
|
||||
explicit raw_mem_istream(span<const uint8_t> mem)
|
||||
explicit raw_mem_istream(std::span<const uint8_t> mem)
|
||||
: raw_mem_istream(reinterpret_cast<const char*>(mem.data()), mem.size()) {
|
||||
}
|
||||
explicit raw_mem_istream(const char* str)
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "wpi/SmallVector.h"
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -112,7 +112,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddBooleanArrayProperty(
|
||||
std::string_view key, std::function<std::vector<int>()> getter,
|
||||
std::function<void(wpi::span<const int>)> setter) = 0;
|
||||
std::function<void(std::span<const int>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add an integer array property.
|
||||
@@ -123,7 +123,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddIntegerArrayProperty(
|
||||
std::string_view key, std::function<std::vector<int64_t>()> getter,
|
||||
std::function<void(wpi::span<const int64_t>)> setter) = 0;
|
||||
std::function<void(std::span<const int64_t>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a float array property.
|
||||
@@ -134,7 +134,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddFloatArrayProperty(
|
||||
std::string_view key, std::function<std::vector<float>()> getter,
|
||||
std::function<void(wpi::span<const float>)> setter) = 0;
|
||||
std::function<void(std::span<const float>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a double array property.
|
||||
@@ -145,7 +145,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddDoubleArrayProperty(
|
||||
std::string_view key, std::function<std::vector<double>()> getter,
|
||||
std::function<void(wpi::span<const double>)> setter) = 0;
|
||||
std::function<void(std::span<const double>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string array property.
|
||||
@@ -156,7 +156,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddStringArrayProperty(
|
||||
std::string_view key, std::function<std::vector<std::string>()> getter,
|
||||
std::function<void(wpi::span<const std::string>)> setter) = 0;
|
||||
std::function<void(std::span<const std::string>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a raw property.
|
||||
@@ -169,7 +169,7 @@ class SendableBuilder {
|
||||
virtual void AddRawProperty(
|
||||
std::string_view key, std::string_view typeString,
|
||||
std::function<std::vector<uint8_t>()> getter,
|
||||
std::function<void(wpi::span<const uint8_t>)> setter) = 0;
|
||||
std::function<void(std::span<const uint8_t>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string property (SmallString form).
|
||||
@@ -192,9 +192,9 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallBooleanArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::span<const int>(wpi::SmallVectorImpl<int>& buf)>
|
||||
std::function<std::span<const int>(wpi::SmallVectorImpl<int>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const int>)> setter) = 0;
|
||||
std::function<void(std::span<const int>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add an integer array property (SmallVector form).
|
||||
@@ -206,9 +206,9 @@ class SendableBuilder {
|
||||
virtual void AddSmallIntegerArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<
|
||||
wpi::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
|
||||
std::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const int64_t>)> setter) = 0;
|
||||
std::function<void(std::span<const int64_t>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a float array property (SmallVector form).
|
||||
@@ -219,9 +219,9 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallFloatArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::span<const float>(wpi::SmallVectorImpl<float>& buf)>
|
||||
std::function<std::span<const float>(wpi::SmallVectorImpl<float>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const float>)> setter) = 0;
|
||||
std::function<void(std::span<const float>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a double array property (SmallVector form).
|
||||
@@ -232,9 +232,9 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallDoubleArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::span<const double>(wpi::SmallVectorImpl<double>& buf)>
|
||||
std::function<std::span<const double>(wpi::SmallVectorImpl<double>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const double>)> setter) = 0;
|
||||
std::function<void(std::span<const double>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string array property (SmallVector form).
|
||||
@@ -246,9 +246,9 @@ class SendableBuilder {
|
||||
virtual void AddSmallStringArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<
|
||||
wpi::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
||||
std::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const std::string>)> setter) = 0;
|
||||
std::function<void(std::span<const std::string>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a raw property (SmallVector form).
|
||||
@@ -260,9 +260,9 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallRawProperty(
|
||||
std::string_view key, std::string_view typeString,
|
||||
std::function<wpi::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
|
||||
std::function<std::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
|
||||
getter,
|
||||
std::function<void(wpi::span<const uint8_t>)> setter) = 0;
|
||||
std::function<void(std::span<const uint8_t>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Gets the kind of backend being used.
|
||||
|
||||
Reference in New Issue
Block a user