SCRIPT namespace replacements

This commit is contained in:
PJ Reiniger
2025-11-07 20:00:05 -05:00
committed by Peter Johnson
parent ae6c043632
commit 9aca8e0fd6
2622 changed files with 22275 additions and 22275 deletions

View File

@@ -63,7 +63,7 @@
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/raw_ostream.hpp"
namespace wpi {
namespace wpi::util {
// aaaack but it's fast and const should make it shared text page.
static const unsigned char pr2six[256] = {
@@ -216,4 +216,4 @@ std::string_view Base64Encode(std::span<const uint8_t> plain,
return os.str();
}
} // namespace wpi
} // namespace wpi::util

View File

@@ -4,7 +4,7 @@
#include "wpi/util/Logger.hpp"
using namespace wpi;
using namespace wpi::util;
void Logger::DoLog(unsigned int level, const char* file, unsigned int line,
const char* msg) {

View File

@@ -31,7 +31,7 @@
#include "wpi/util/WindowsError.hpp"
#endif
using namespace wpi;
using namespace wpi::util;
MappedFileRegion::MappedFileRegion(fs::file_t f, uint64_t length,
uint64_t offset, MapMode mapMode,
@@ -47,7 +47,7 @@ MappedFileRegion::MappedFileRegion(fs::file_t f, uint64_t length,
f, 0, mapMode == kReadOnly ? PAGE_READONLY : PAGE_READWRITE, length >> 32,
length & 0xffffffff, 0);
if (fileMappingHandle == nullptr) {
ec = wpi::mapWindowsError(GetLastError());
ec = wpi::util::mapWindowsError(GetLastError());
return;
}
@@ -66,7 +66,7 @@ MappedFileRegion::MappedFileRegion(fs::file_t f, uint64_t length,
m_mapping = ::MapViewOfFile(fileMappingHandle, dwDesiredAccess, offset >> 32,
offset & 0xffffffff, length);
if (m_mapping == nullptr) {
ec = wpi::mapWindowsError(GetLastError());
ec = wpi::util::mapWindowsError(GetLastError());
::CloseHandle(fileMappingHandle);
return;
}
@@ -79,7 +79,7 @@ MappedFileRegion::MappedFileRegion(fs::file_t f, uint64_t length,
::CloseHandle(fileMappingHandle);
if (!::DuplicateHandle(::GetCurrentProcess(), f, ::GetCurrentProcess(),
&m_fileHandle, 0, 0, DUPLICATE_SAME_ACCESS)) {
ec = wpi::mapWindowsError(GetLastError());
ec = wpi::util::mapWindowsError(GetLastError());
::UnmapViewOfFile(m_mapping);
m_mapping = nullptr;
return;

View File

@@ -14,7 +14,7 @@ int WPI_AllocateRawFrameData(WPI_RawFrame* frame, size_t requestedSize) {
return 0;
}
WPI_FreeRawFrameData(frame);
frame->data = static_cast<uint8_t*>(wpi::safe_malloc(requestedSize));
frame->data = static_cast<uint8_t*>(wpi::util::safe_malloc(requestedSize));
frame->capacity = requestedSize;
frame->size = 0;
return 1;

View File

@@ -8,7 +8,7 @@
#include <memory>
#include <utility>
using namespace wpi;
using namespace wpi::util;
// thread start/stop notifications for bindings that need to set up
// per-thread state
@@ -24,7 +24,7 @@ static std::atomic<int> gSafeThreadRefcount;
static std::atomic<OnThreadStartFn> gOnSafeThreadStart{DefaultOnThreadStart};
static std::atomic<OnThreadEndFn> gOnSafeThreadEnd{DefaultOnThreadEnd};
namespace wpi::impl {
namespace wpi::util::impl {
void SetSafeThreadNotifiers(OnThreadStartFn OnStart, OnThreadEndFn OnEnd) {
if (gSafeThreadRefcount != 0) {
throw std::runtime_error(
@@ -36,7 +36,7 @@ void SetSafeThreadNotifiers(OnThreadStartFn OnStart, OnThreadEndFn OnEnd) {
gOnSafeThreadStart = OnStart ? OnStart : DefaultOnThreadStart;
gOnSafeThreadEnd = OnEnd ? OnEnd : DefaultOnThreadEnd;
}
} // namespace wpi::impl
} // namespace wpi::util::impl
void SafeThread::Stop() {
m_active = false;
@@ -54,7 +54,7 @@ detail::SafeThreadProxyBase::SafeThreadProxyBase(
if (!m_thread) {
return;
}
m_lock = std::unique_lock<wpi::mutex>(m_thread->m_mutex);
m_lock = std::unique_lock<wpi::util::mutex>(m_thread->m_mutex);
if (!m_thread->m_active) {
m_lock.unlock();
m_thread = nullptr;

View File

@@ -8,12 +8,12 @@
#include "wpi/util/StackTrace.hpp"
static std::atomic<std::string (*)(int offset)> gStackTraceImpl{
wpi::GetStackTraceDefault};
wpi::util::GetStackTraceDefault};
std::string wpi::GetStackTrace(int offset) {
std::string wpi::util::GetStackTrace(int offset) {
return (gStackTraceImpl.load())(offset);
}
void wpi::SetGetStackTraceImpl(std::string (*func)(int offset)) {
gStackTraceImpl = func ? func : wpi::GetStackTraceDefault;
void wpi::util::SetGetStackTraceImpl(std::string (*func)(int offset)) {
gStackTraceImpl = func ? func : wpi::util::GetStackTraceDefault;
}

View File

@@ -15,7 +15,7 @@
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/mutex.hpp"
using namespace wpi;
using namespace wpi::util;
// Count of active threads using the handle manager singleton. A negative value
// indicates that the manager is being destroyed. When the manager is being
@@ -34,7 +34,7 @@ namespace {
struct State {
int signaled{0};
bool autoReset{false};
wpi::SmallVector<wpi::condition_variable*, 2> waiters;
wpi::util::SmallVector<wpi::util::condition_variable*, 2> waiters;
};
struct HandleManager {
@@ -67,10 +67,10 @@ struct HandleManager {
}
#endif
}
wpi::mutex mutex;
wpi::UidVector<int, 8> eventIds;
wpi::UidVector<int, 8> semaphoreIds;
wpi::DenseMap<WPI_Handle, State> states;
wpi::util::mutex mutex;
wpi::util::UidVector<int, 8> eventIds;
wpi::util::UidVector<int, 8> semaphoreIds;
wpi::util::DenseMap<WPI_Handle, State> states;
};
class ManagerGuard {
@@ -97,7 +97,7 @@ class ManagerGuard {
} // namespace
WPI_EventHandle wpi::CreateEvent(bool manualReset, bool initialState) {
WPI_EventHandle wpi::util::CreateEvent(bool manualReset, bool initialState) {
ManagerGuard guard;
if (!guard) {
return {};
@@ -115,7 +115,7 @@ WPI_EventHandle wpi::CreateEvent(bool manualReset, bool initialState) {
return handle;
}
void wpi::DestroyEvent(WPI_EventHandle handle) {
void wpi::util::DestroyEvent(WPI_EventHandle handle) {
if ((handle >> 24) != kHandleTypeEvent) {
return;
}
@@ -131,7 +131,7 @@ void wpi::DestroyEvent(WPI_EventHandle handle) {
manager.eventIds.erase(handle & 0xffffff);
}
void wpi::SetEvent(WPI_EventHandle handle) {
void wpi::util::SetEvent(WPI_EventHandle handle) {
if ((handle >> 24) != kHandleTypeEvent) {
return;
}
@@ -139,7 +139,7 @@ void wpi::SetEvent(WPI_EventHandle handle) {
SetSignalObject(handle);
}
void wpi::ResetEvent(WPI_EventHandle handle) {
void wpi::util::ResetEvent(WPI_EventHandle handle) {
if ((handle >> 24) != kHandleTypeEvent) {
return;
}
@@ -147,7 +147,7 @@ void wpi::ResetEvent(WPI_EventHandle handle) {
ResetSignalObject(handle);
}
WPI_SemaphoreHandle wpi::CreateSemaphore(int initialCount, int maximumCount) {
WPI_SemaphoreHandle wpi::util::CreateSemaphore(int initialCount, int maximumCount) {
ManagerGuard guard;
if (!guard) {
return {};
@@ -166,7 +166,7 @@ WPI_SemaphoreHandle wpi::CreateSemaphore(int initialCount, int maximumCount) {
return handle;
}
void wpi::DestroySemaphore(WPI_SemaphoreHandle handle) {
void wpi::util::DestroySemaphore(WPI_SemaphoreHandle handle) {
if ((handle >> 24) != kHandleTypeSemaphore) {
return;
}
@@ -182,7 +182,7 @@ void wpi::DestroySemaphore(WPI_SemaphoreHandle handle) {
manager.eventIds.erase(handle & 0xffffff);
}
bool wpi::ReleaseSemaphore(WPI_SemaphoreHandle handle, int releaseCount,
bool wpi::util::ReleaseSemaphore(WPI_SemaphoreHandle handle, int releaseCount,
int* prevCount) {
if ((handle >> 24) != kHandleTypeSemaphore) {
return false;
@@ -217,11 +217,11 @@ bool wpi::ReleaseSemaphore(WPI_SemaphoreHandle handle, int releaseCount,
return true;
}
bool wpi::WaitForObject(WPI_Handle handle) {
bool wpi::util::WaitForObject(WPI_Handle handle) {
return WaitForObject(handle, -1, nullptr);
}
bool wpi::WaitForObject(WPI_Handle handle, double timeout, bool* timedOut) {
bool wpi::util::WaitForObject(WPI_Handle handle, double timeout, bool* timedOut) {
WPI_Handle signaledValue;
auto signaled = WaitForObjects(
std::span(&handle, 1), std::span(&signaledValue, 1), timeout, timedOut);
@@ -231,12 +231,12 @@ bool wpi::WaitForObject(WPI_Handle handle, double timeout, bool* timedOut) {
return (signaled[0] & 0x80000000ul) == 0;
}
std::span<WPI_Handle> wpi::WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> wpi::util::WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> signaled) {
return WaitForObjects(handles, signaled, -1, nullptr);
}
std::span<WPI_Handle> wpi::WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> wpi::util::WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> signaled,
double timeout, bool* timedOut) {
ManagerGuard guard;
@@ -248,7 +248,7 @@ std::span<WPI_Handle> wpi::WaitForObjects(std::span<const WPI_Handle> handles,
}
auto& manager = guard.GetManager();
std::unique_lock lock{manager.mutex};
wpi::condition_variable cv;
wpi::util::condition_variable cv;
bool addedWaiters = false;
bool timedOutVal = false;
size_t count = 0;
@@ -336,7 +336,7 @@ std::span<WPI_Handle> wpi::WaitForObjects(std::span<const WPI_Handle> handles,
return signaled.subspan(0, count);
}
void wpi::CreateSignalObject(WPI_Handle handle, bool manualReset,
void wpi::util::CreateSignalObject(WPI_Handle handle, bool manualReset,
bool initialState) {
ManagerGuard guard;
if (!guard) {
@@ -349,7 +349,7 @@ void wpi::CreateSignalObject(WPI_Handle handle, bool manualReset,
state.autoReset = !manualReset;
}
void wpi::SetSignalObject(WPI_Handle handle) {
void wpi::util::SetSignalObject(WPI_Handle handle) {
ManagerGuard guard;
if (!guard) {
return;
@@ -371,7 +371,7 @@ void wpi::SetSignalObject(WPI_Handle handle) {
}
}
void wpi::ResetSignalObject(WPI_Handle handle) {
void wpi::util::ResetSignalObject(WPI_Handle handle) {
ManagerGuard guard;
if (!guard) {
return;
@@ -384,7 +384,7 @@ void wpi::ResetSignalObject(WPI_Handle handle) {
}
}
void wpi::DestroySignalObject(WPI_Handle handle) {
void wpi::util::DestroySignalObject(WPI_Handle handle) {
ManagerGuard guard;
if (!guard) {
return;
@@ -405,49 +405,49 @@ void wpi::DestroySignalObject(WPI_Handle handle) {
extern "C" {
WPI_EventHandle WPI_CreateEvent(int manual_reset, int initial_state) {
return wpi::CreateEvent(manual_reset != 0, initial_state != 0);
return wpi::util::CreateEvent(manual_reset != 0, initial_state != 0);
}
void WPI_DestroyEvent(WPI_EventHandle handle) {
wpi::DestroyEvent(handle);
wpi::util::DestroyEvent(handle);
}
void WPI_SetEvent(WPI_EventHandle handle) {
wpi::SetEvent(handle);
wpi::util::SetEvent(handle);
}
void WPI_ResetEvent(WPI_EventHandle handle) {
wpi::ResetEvent(handle);
wpi::util::ResetEvent(handle);
}
WPI_SemaphoreHandle WPI_CreateSemaphore(int initial_count, int maximum_count) {
return wpi::CreateSemaphore(initial_count, maximum_count);
return wpi::util::CreateSemaphore(initial_count, maximum_count);
}
void WPI_DestroySemaphore(WPI_SemaphoreHandle handle) {
wpi::DestroySemaphore(handle);
wpi::util::DestroySemaphore(handle);
}
int WPI_ReleaseSemaphore(WPI_SemaphoreHandle handle, int release_count,
int* prev_count) {
return wpi::ReleaseSemaphore(handle, release_count, prev_count);
return wpi::util::ReleaseSemaphore(handle, release_count, prev_count);
}
int WPI_WaitForObject(WPI_Handle handle) {
return wpi::WaitForObject(handle);
return wpi::util::WaitForObject(handle);
}
int WPI_WaitForObjectTimeout(WPI_Handle handle, double timeout,
int* timed_out) {
bool timedOutBool;
int rv = wpi::WaitForObject(handle, timeout, &timedOutBool);
int rv = wpi::util::WaitForObject(handle, timeout, &timedOutBool);
*timed_out = timedOutBool ? 1 : 0;
return rv;
}
int WPI_WaitForObjects(const WPI_Handle* handles, int handles_count,
WPI_Handle* signaled) {
return wpi::WaitForObjects(std::span(handles, handles_count),
return wpi::util::WaitForObjects(std::span(handles, handles_count),
std::span(signaled, handles_count))
.size();
}
@@ -456,7 +456,7 @@ int WPI_WaitForObjectsTimeout(const WPI_Handle* handles, int handles_count,
WPI_Handle* signaled, double timeout,
int* timed_out) {
bool timedOutBool;
auto signaledResult = wpi::WaitForObjects(std::span(handles, handles_count),
auto signaledResult = wpi::util::WaitForObjects(std::span(handles, handles_count),
std::span(signaled, handles_count),
timeout, &timedOutBool);
*timed_out = timedOutBool ? 1 : 0;
@@ -465,19 +465,19 @@ int WPI_WaitForObjectsTimeout(const WPI_Handle* handles, int handles_count,
void WPI_CreateSignalObject(WPI_Handle handle, int manual_reset,
int initial_state) {
wpi::CreateSignalObject(handle, manual_reset, initial_state);
wpi::util::CreateSignalObject(handle, manual_reset, initial_state);
}
void WPI_SetSignalObject(WPI_Handle handle) {
wpi::SetSignalObject(handle);
wpi::util::SetSignalObject(handle);
}
void WPI_ResetSignalObject(WPI_Handle handle) {
wpi::ResetSignalObject(handle);
wpi::util::ResetSignalObject(handle);
}
void WPI_DestroySignalObject(WPI_Handle handle) {
wpi::DestroySignalObject(handle);
wpi::util::DestroySignalObject(handle);
}
} // extern "C"

View File

@@ -100,7 +100,7 @@ static file_t openFileInternal(const path& Path, std::error_code& EC,
Disp, Flags, NULL);
if (H == INVALID_HANDLE_VALUE) {
DWORD LastError = ::GetLastError();
EC = wpi::mapWindowsError(LastError);
EC = wpi::util::mapWindowsError(LastError);
// Provide a better error message when trying to open directories.
// This only runs if we failed to open the file, so there is probably
// no performances issues.
@@ -121,7 +121,7 @@ static std::error_code setDeleteDisposition(HANDLE Handle, bool Delete) {
Disposition.DeleteFile = Delete;
if (!::SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition,
sizeof(Disposition)))
return wpi::mapWindowsError(::GetLastError());
return wpi::util::mapWindowsError(::GetLastError());
return std::error_code();
}
@@ -153,7 +153,7 @@ file_t OpenFile(const path& Path, std::error_code& EC, CreationDisposition Disp,
::SetFileTime(Result, NULL, &FileTime, NULL) == 0) {
DWORD LastError = ::GetLastError();
::CloseHandle(Result);
EC = wpi::mapWindowsError(LastError);
EC = wpi::util::mapWindowsError(LastError);
return WPI_kInvalidFile;
}
}
@@ -173,7 +173,7 @@ file_t OpenFileForRead(const path& Path, std::error_code& EC, OpenFlags Flags) {
int FileToFd(file_t& F, std::error_code& EC, OpenFlags Flags) {
if (F == WPI_kInvalidFile) {
EC = wpi::mapWindowsError(ERROR_INVALID_HANDLE);
EC = wpi::util::mapWindowsError(ERROR_INVALID_HANDLE);
return -1;
}
@@ -189,7 +189,7 @@ int FileToFd(file_t& F, std::error_code& EC, OpenFlags Flags) {
int ResultFD = ::_open_osfhandle(intptr_t(F), CrtOpenFlags);
if (ResultFD == -1) {
::CloseHandle(F);
EC = wpi::mapWindowsError(ERROR_INVALID_HANDLE);
EC = wpi::util::mapWindowsError(ERROR_INVALID_HANDLE);
return -1;
}
@@ -249,7 +249,7 @@ file_t OpenFile(const path& Path, std::error_code& EC, CreationDisposition Disp,
// Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
// when open is overloaded, such as in Bionic.
auto Open = [&]() { return ::open(Path.c_str(), OpenFlags, Mode); };
if ((ResultFD = wpi::sys::RetryAfterSignal(-1, Open)) < 0) {
if ((ResultFD = wpi::util::sys::RetryAfterSignal(-1, Open)) < 0) {
EC = std::error_code(errno, std::generic_category());
return WPI_kInvalidFile;
}

View File

@@ -6,7 +6,7 @@
#include <utility>
namespace wpi {
namespace wpi::util {
namespace detail {
PromiseFactoryBase::~PromiseFactoryBase() {
@@ -123,4 +123,4 @@ PromiseFactory<void>& PromiseFactory<void>::GetInstance() {
return inst;
}
} // namespace wpi
} // namespace wpi::util

View File

@@ -14,7 +14,7 @@
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
using namespace wpi::java;
using namespace wpi::util::java;
static bool mockTimeEnabled = false;
static uint64_t mockNow = 0;
@@ -34,19 +34,19 @@ static const JExceptionInit exceptions[] = {
{"java/lang/NullPointerException", &nullPointerEx},
{"org/wpilib/util/runtime/MsvcRuntimeException", &msvcRuntimeEx}};
void wpi::ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg) {
void wpi::util::ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg) {
illegalArgEx.Throw(env, msg);
}
void wpi::ThrowIndexOobException(JNIEnv* env, std::string_view msg) {
void wpi::util::ThrowIndexOobException(JNIEnv* env, std::string_view msg) {
indexOobEx.Throw(env, msg);
}
void wpi::ThrowIOException(JNIEnv* env, std::string_view msg) {
void wpi::util::ThrowIOException(JNIEnv* env, std::string_view msg) {
ioEx.Throw(env, msg);
}
void wpi::ThrowNullPointerException(JNIEnv* env, std::string_view msg) {
void wpi::util::ThrowNullPointerException(JNIEnv* env, std::string_view msg) {
nullPointerEx.Throw(env, msg);
}
@@ -98,7 +98,7 @@ Java_org_wpilib_util_WPIUtilJNI_checkMsvcRuntime
&expectedMinor, &runtimePath)) {
static jmethodID ctor =
env->GetMethodID(msvcRuntimeEx, "<init>", "(IIIILjava/lang/String;)V");
jstring jmsvcruntime = MakeJString(env, wpi::to_string_view(&runtimePath));
jstring jmsvcruntime = MakeJString(env, wpi::util::to_string_view(&runtimePath));
jobject exception =
env->NewObject(msvcRuntimeEx, ctor, foundMajor, foundMinor,
expectedMajor, expectedMinor, jmsvcruntime);
@@ -116,7 +116,7 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_writeStderr
(JNIEnv* env, jclass, jstring str)
{
wpi::print(stderr, "{}", JStringRef{env, str}.str());
wpi::util::print(stderr, "{}", JStringRef{env, str}.str());
}
/*
@@ -129,10 +129,10 @@ Java_org_wpilib_util_WPIUtilJNI_enableMockTime
(JNIEnv*, jclass)
{
#ifdef __FRC_SYSTEMCORE__
wpi::print(stderr, "WPIUtil: Mocking time is not available on systemcore\n");
wpi::util::print(stderr, "WPIUtil: Mocking time is not available on systemcore\n");
#else
mockTimeEnabled = true;
wpi::SetNowImpl([] { return mockNow; });
wpi::util::SetNowImpl([] { return mockNow; });
#endif
}
@@ -146,7 +146,7 @@ Java_org_wpilib_util_WPIUtilJNI_disableMockTime
(JNIEnv*, jclass)
{
mockTimeEnabled = false;
wpi::SetNowImpl(nullptr);
wpi::util::SetNowImpl(nullptr);
}
/*
@@ -173,7 +173,7 @@ Java_org_wpilib_util_WPIUtilJNI_now
if (mockTimeEnabled) {
return mockNow;
} else {
return wpi::Now();
return wpi::util::Now();
}
}
@@ -186,7 +186,7 @@ JNIEXPORT jlong JNICALL
Java_org_wpilib_util_WPIUtilJNI_getSystemTime
(JNIEnv*, jclass)
{
return wpi::GetSystemTime();
return wpi::util::GetSystemTime();
}
/*
@@ -198,7 +198,7 @@ JNIEXPORT jint JNICALL
Java_org_wpilib_util_WPIUtilJNI_createEvent
(JNIEnv*, jclass, jboolean manualReset, jboolean initialState)
{
return wpi::CreateEvent(manualReset, initialState);
return wpi::util::CreateEvent(manualReset, initialState);
}
/*
@@ -210,7 +210,7 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_destroyEvent
(JNIEnv*, jclass, jint eventHandle)
{
wpi::DestroyEvent(eventHandle);
wpi::util::DestroyEvent(eventHandle);
}
/*
@@ -222,7 +222,7 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_setEvent
(JNIEnv*, jclass, jint eventHandle)
{
wpi::SetEvent(eventHandle);
wpi::util::SetEvent(eventHandle);
}
/*
@@ -234,7 +234,7 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_resetEvent
(JNIEnv*, jclass, jint eventHandle)
{
wpi::ResetEvent(eventHandle);
wpi::util::ResetEvent(eventHandle);
}
/*
@@ -246,7 +246,7 @@ JNIEXPORT jint JNICALL
Java_org_wpilib_util_WPIUtilJNI_createSemaphore
(JNIEnv*, jclass, jint initialCount, jint maximumCount)
{
return wpi::CreateSemaphore(initialCount, maximumCount);
return wpi::util::CreateSemaphore(initialCount, maximumCount);
}
/*
@@ -258,7 +258,7 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_destroySemaphore
(JNIEnv*, jclass, jint semHandle)
{
wpi::DestroySemaphore(semHandle);
wpi::util::DestroySemaphore(semHandle);
}
/*
@@ -270,7 +270,7 @@ JNIEXPORT jboolean JNICALL
Java_org_wpilib_util_WPIUtilJNI_releaseSemaphore
(JNIEnv*, jclass, jint semHandle, jint releaseCount)
{
return wpi::ReleaseSemaphore(semHandle, releaseCount);
return wpi::util::ReleaseSemaphore(semHandle, releaseCount);
}
/*
@@ -282,7 +282,7 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_waitForObject
(JNIEnv* env, jclass, jint handle)
{
if (!wpi::WaitForObject(handle)) {
if (!wpi::util::WaitForObject(handle)) {
interruptedEx.Throw(env, "WaitForObject interrupted");
}
}
@@ -297,7 +297,7 @@ Java_org_wpilib_util_WPIUtilJNI_waitForObjectTimeout
(JNIEnv* env, jclass, jint handle, jdouble timeout)
{
bool timedOut;
if (!wpi::WaitForObject(handle, timeout, &timedOut) && !timedOut) {
if (!wpi::util::WaitForObject(handle, timeout, &timedOut) && !timedOut) {
interruptedEx.Throw(env, "WaitForObject interrupted");
return false;
}
@@ -314,13 +314,13 @@ Java_org_wpilib_util_WPIUtilJNI_waitForObjects
(JNIEnv* env, jclass, jintArray handles)
{
JSpan<const jint> handlesArr{env, handles};
wpi::SmallVector<WPI_Handle, 8> signaledBuf;
wpi::util::SmallVector<WPI_Handle, 8> signaledBuf;
signaledBuf.resize(handlesArr.size());
std::span<const WPI_Handle> handlesArr2{
reinterpret_cast<const WPI_Handle*>(handlesArr.data()),
handlesArr.size()};
auto signaled = wpi::WaitForObjects(handlesArr2, signaledBuf);
auto signaled = wpi::util::WaitForObjects(handlesArr2, signaledBuf);
if (signaled.empty()) {
interruptedEx.Throw(env, "WaitForObjects interrupted");
return nullptr;
@@ -338,7 +338,7 @@ Java_org_wpilib_util_WPIUtilJNI_waitForObjectsTimeout
(JNIEnv* env, jclass, jintArray handles, jdouble timeout)
{
JSpan<const jint> handlesArr{env, handles};
wpi::SmallVector<WPI_Handle, 8> signaledBuf;
wpi::util::SmallVector<WPI_Handle, 8> signaledBuf;
signaledBuf.resize(handlesArr.size());
std::span<const WPI_Handle> handlesArr2{
reinterpret_cast<const WPI_Handle*>(handlesArr.data()),
@@ -346,7 +346,7 @@ Java_org_wpilib_util_WPIUtilJNI_waitForObjectsTimeout
bool timedOut;
auto signaled =
wpi::WaitForObjects(handlesArr2, signaledBuf, timeout, &timedOut);
wpi::util::WaitForObjects(handlesArr2, signaledBuf, timeout, &timedOut);
if (signaled.empty() && !timedOut) {
interruptedEx.Throw(env, "WaitForObjects interrupted");
return nullptr;
@@ -363,7 +363,7 @@ JNIEXPORT jlong JNICALL
Java_org_wpilib_util_WPIUtilJNI_allocateRawFrame
(JNIEnv*, jclass)
{
return reinterpret_cast<jlong>(new wpi::RawFrame);
return reinterpret_cast<jlong>(new wpi::util::RawFrame);
}
/*
@@ -375,7 +375,7 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_freeRawFrame
(JNIEnv*, jclass, jlong frame)
{
delete reinterpret_cast<wpi::RawFrame*>(frame);
delete reinterpret_cast<wpi::util::RawFrame*>(frame);
}
/*
@@ -387,9 +387,9 @@ JNIEXPORT jlong JNICALL
Java_org_wpilib_util_WPIUtilJNI_getRawFrameDataPtr
(JNIEnv* env, jclass, jlong frame)
{
auto* f = reinterpret_cast<wpi::RawFrame*>(frame);
auto* f = reinterpret_cast<wpi::util::RawFrame*>(frame);
if (!f) {
wpi::ThrowNullPointerException(env, "frame is null");
wpi::util::ThrowNullPointerException(env, "frame is null");
return 0;
}
return reinterpret_cast<jlong>(f->data);
@@ -405,14 +405,14 @@ Java_org_wpilib_util_WPIUtilJNI_setRawFrameData
(JNIEnv* env, jclass, jlong frame, jobject data, jint size, jint width,
jint height, jint stride, jint pixelFormat)
{
auto* f = reinterpret_cast<wpi::RawFrame*>(frame);
auto* f = reinterpret_cast<wpi::util::RawFrame*>(frame);
if (!f) {
wpi::ThrowNullPointerException(env, "frame is null");
wpi::util::ThrowNullPointerException(env, "frame is null");
return;
}
auto buf = env->GetDirectBufferAddress(data);
if (!buf) {
wpi::ThrowNullPointerException(env, "data is null");
wpi::util::ThrowNullPointerException(env, "data is null");
return;
}
// there's no way to free a passed-in direct byte buffer
@@ -433,9 +433,9 @@ JNIEXPORT void JNICALL
Java_org_wpilib_util_WPIUtilJNI_setRawFrameTime
(JNIEnv* env, jclass, jlong frame, jlong time, jint timeSource)
{
auto* f = reinterpret_cast<wpi::RawFrame*>(frame);
auto* f = reinterpret_cast<wpi::util::RawFrame*>(frame);
if (!f) {
wpi::ThrowNullPointerException(env, "frame is null");
wpi::util::ThrowNullPointerException(env, "frame is null");
return;
}
f->timestamp = time;
@@ -452,9 +452,9 @@ Java_org_wpilib_util_WPIUtilJNI_setRawFrameInfo
(JNIEnv* env, jclass, jlong frame, jint size, jint width, jint height,
jint stride, jint pixelFormat)
{
auto* f = reinterpret_cast<wpi::RawFrame*>(frame);
auto* f = reinterpret_cast<wpi::util::RawFrame*>(frame);
if (!f) {
wpi::ThrowNullPointerException(env, "frame is null");
wpi::util::ThrowNullPointerException(env, "frame is null");
return;
}
f->width = width;

View File

@@ -8,11 +8,11 @@
#include <string_view>
namespace wpi {
namespace wpi::util {
void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg);
void ThrowIndexOobException(JNIEnv* env, std::string_view msg);
void ThrowIOException(JNIEnv* env, std::string_view msg);
void ThrowNullPointerException(JNIEnv* env, std::string_view msg);
} // namespace wpi
} // namespace wpi::util

View File

@@ -11,7 +11,7 @@
#include "wpi/util/SmallVector.hpp"
using namespace wpi;
using namespace wpi::util;
std::string detail::GetTypeString(const pb_msgdesc_t* msg) {
return fmt::format("proto:{}", msg->proto_name);
@@ -52,7 +52,7 @@ bool detail::WriteFromStdVector(pb_ostream_t* stream, const pb_byte_t* buf,
bool detail::WriteSubmessage(pb_ostream_t* stream, const pb_msgdesc_t* desc,
const void* msg) {
// Write the submessage to a separate buffer
wpi::SmallVector<uint8_t, 64> buf;
wpi::util::SmallVector<uint8_t, 64> buf;
pb_ostream_t subStream{
.callback = WriteFromSmallVector,
.state = &buf,

View File

@@ -31,7 +31,7 @@
#endif
#endif
using namespace wpi;
using namespace wpi::util;
std::string_view raw_istream::getline(SmallVectorImpl<char>& buf, int maxLen) {
buf.clear();

View File

@@ -17,7 +17,7 @@
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableBuilder.hpp"
using namespace wpi;
using namespace wpi::util;
namespace {
struct Component {
@@ -26,7 +26,7 @@ struct Component {
std::string name;
std::string subsystem = "Ungrouped";
Sendable* parent = nullptr;
wpi::SmallVector<std::shared_ptr<void>, 2> data;
wpi::util::SmallVector<std::shared_ptr<void>, 2> data;
void SetName(std::string_view moduleType, int channel) {
name = fmt::format("{}[{}]", moduleType, channel);
@@ -38,10 +38,10 @@ struct Component {
};
struct SendableRegistryInst {
wpi::recursive_mutex mutex;
wpi::util::recursive_mutex mutex;
wpi::UidVector<std::unique_ptr<Component>, 32> components;
wpi::DenseMap<void*, SendableRegistry::UID> componentMap;
wpi::util::UidVector<std::unique_ptr<Component>, 32> components;
wpi::util::DenseMap<void*, SendableRegistry::UID> componentMap;
int nextDataHandle = 0;
Component& GetOrAdd(void* sendable, SendableRegistry::UID* uid = nullptr);
@@ -72,11 +72,11 @@ static SendableRegistryInst& GetInstance() {
}
#ifndef __FRC_SYSTEMCORE__
namespace wpi::impl {
namespace wpi::util::impl {
void ResetSendableRegistry() {
std::make_unique<SendableRegistryInst>().swap(GetInstanceHolder());
}
} // namespace wpi::impl
} // namespace wpi::util::impl
#endif
void SendableRegistry::EnsureInitialized() {

View File

@@ -26,7 +26,7 @@
#include "wpi/util/raw_istream.hpp"
#include "wpi/util/raw_ostream.hpp"
using namespace wpi;
using namespace wpi::util;
static const size_t BLOCK_INTS =
16; /* number of 32bit integers per SHA1 block */

View File

@@ -46,7 +46,7 @@ char* WPI_AllocateString(struct WPI_String* wpiString, size_t length) {
wpiString->str = nullptr;
return &writeBuffer;
}
char* str = static_cast<char*>(wpi::safe_malloc(length));
char* str = static_cast<char*>(wpi::util::safe_malloc(length));
wpiString->str = str;
wpiString->len = length;
return str;
@@ -61,7 +61,7 @@ void WPI_FreeString(const struct WPI_String* wpiString) {
struct WPI_String* WPI_AllocateStringArray(size_t length) {
return static_cast<struct WPI_String*>(
wpi::safe_malloc(length * sizeof(struct WPI_String)));
wpi::util::safe_malloc(length * sizeof(struct WPI_String)));
}
void WPI_FreeStringArray(const struct WPI_String* wpiStringArray,

View File

@@ -16,7 +16,7 @@
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/struct/SchemaParser.hpp"
using namespace wpi;
using namespace wpi::util;
static size_t TypeToSize(StructFieldType type) {
switch (type) {
@@ -111,7 +111,7 @@ const StructFieldDescriptor* StructDescriptor::FindFieldByName(
}
bool StructDescriptor::CheckCircular(
wpi::SmallVectorImpl<const StructDescriptor*>& stack) const {
wpi::util::SmallVectorImpl<const StructDescriptor*>& stack) const {
stack.emplace_back(this);
for (auto&& ref : m_references) {
if (std::find(stack.begin(), stack.end(), ref) != stack.end()) {
@@ -126,7 +126,7 @@ bool StructDescriptor::CheckCircular(
}
std::string StructDescriptor::CalculateOffsets(
wpi::SmallVectorImpl<const StructDescriptor*>& stack) {
wpi::util::SmallVectorImpl<const StructDescriptor*>& stack) {
size_t offset = 0;
unsigned int shift = 0;
size_t prevBitfieldSize = 0;
@@ -282,7 +282,7 @@ const StructDescriptor* StructDescriptorDatabase::Add(std::string_view name,
theStruct.m_valid = isValid;
if (isValid) {
// we have all the info needed, so calculate field offset & shift
wpi::SmallVector<const StructDescriptor*, 16> stack;
wpi::util::SmallVector<const StructDescriptor*, 16> stack;
auto err2 = theStruct.CalculateOffsets(stack);
if (!err2.empty()) {
*err = std::move(err2);
@@ -290,10 +290,10 @@ const StructDescriptor* StructDescriptorDatabase::Add(std::string_view name,
}
} else {
// check for circular reference
wpi::SmallVector<const StructDescriptor*, 16> stack;
wpi::util::SmallVector<const StructDescriptor*, 16> stack;
if (!theStruct.CheckCircular(stack)) {
wpi::SmallString<128> buf;
wpi::raw_svector_ostream os{buf};
wpi::util::SmallString<128> buf;
wpi::util::raw_svector_ostream os{buf};
for (auto&& elem : stack) {
if (!buf.empty()) {
os << " <- ";

View File

@@ -11,9 +11,9 @@
#include "wpi/util/StringExtras.hpp"
using namespace wpi::structparser;
using namespace wpi::util::structparser;
std::string_view wpi::structparser::ToString(Token::Kind kind) {
std::string_view wpi::util::structparser::ToString(Token::Kind kind) {
switch (kind) {
case Token::kInteger:
return "integer";

View File

@@ -78,7 +78,7 @@ static const uint64_t offset_val = timestamp();
static const uint64_t frequency_val = update_frequency();
#endif
uint64_t wpi::NowDefault() {
uint64_t wpi::util::NowDefault() {
#ifdef _WIN32
assert(offset_val > 0u);
assert(frequency_val > 0u);
@@ -95,36 +95,36 @@ uint64_t wpi::NowDefault() {
#endif
}
static std::atomic<uint64_t (*)()> now_impl{wpi::NowDefault};
static std::atomic<uint64_t (*)()> now_impl{wpi::util::NowDefault};
void wpi::SetNowImpl(uint64_t (*func)(void)) {
void wpi::util::SetNowImpl(uint64_t (*func)(void)) {
now_impl = func ? func : NowDefault;
}
uint64_t wpi::Now() {
uint64_t wpi::util::Now() {
return (now_impl.load())();
}
uint64_t wpi::GetSystemTime() {
uint64_t wpi::util::GetSystemTime() {
return time_since_epoch();
}
extern "C" {
uint64_t WPI_NowDefault(void) {
return wpi::NowDefault();
return wpi::util::NowDefault();
}
void WPI_SetNowImpl(uint64_t (*func)(void)) {
wpi::SetNowImpl(func);
wpi::util::SetNowImpl(func);
}
uint64_t WPI_Now(void) {
return wpi::Now();
return wpi::util::Now();
}
uint64_t WPI_GetSystemTime(void) {
return wpi::GetSystemTime();
return wpi::util::GetSystemTime();
}
} // extern "C"

View File

@@ -9,7 +9,7 @@
#include <utility>
#include <vector>
namespace wpi {
namespace wpi::util {
// Binary insertion into vector; std::log(n) efficiency.
template <typename T>
@@ -32,4 +32,4 @@ constexpr void for_each(F&& f, Ts&&... elems) {
}(std::index_sequence_for<Ts...>{});
}
} // namespace wpi
} // namespace wpi::util

View File

@@ -13,7 +13,7 @@
#include <string_view>
#include <vector>
namespace wpi {
namespace wpi::util {
template <typename T>
class SmallVectorImpl;
class raw_ostream;
@@ -44,6 +44,6 @@ void Base64Encode(std::span<const uint8_t> plain, std::string* encoded);
std::string_view Base64Encode(std::span<const uint8_t> plain,
SmallVectorImpl<char>& buf);
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_BASE64_HPP_

View File

@@ -19,7 +19,7 @@
#include "wpi/util/mutex.hpp"
#include "wpi/util/raw_ostream.hpp"
namespace wpi {
namespace wpi::util {
template <typename Callback>
class CallbackListenerData {
@@ -47,7 +47,7 @@ template <typename Derived, typename TUserInfo,
typename TListenerData =
CallbackListenerData<std::function<void(const TUserInfo& info)>>,
typename TNotifierData = TUserInfo>
class CallbackThread : public wpi::SafeThread {
class CallbackThread : public wpi::util::SafeThread {
public:
using UserInfo = TUserInfo;
using NotifierData = TNotifierData;
@@ -67,10 +67,10 @@ class CallbackThread : public wpi::SafeThread {
void Main() override;
wpi::UidVector<ListenerData, 64> m_listeners;
wpi::util::UidVector<ListenerData, 64> m_listeners;
std::queue<std::pair<unsigned int, NotifierData>> m_queue;
wpi::condition_variable m_queue_empty;
wpi::util::condition_variable m_queue_empty;
struct Poller {
void Terminate() {
@@ -81,12 +81,12 @@ class CallbackThread : public wpi::SafeThread {
poll_cond.notify_all();
}
std::queue<NotifierData> poll_queue;
wpi::mutex poll_mutex;
wpi::condition_variable poll_cond;
wpi::util::mutex poll_mutex;
wpi::util::condition_variable poll_cond;
bool terminating = false;
bool canceling = false;
};
wpi::UidVector<std::shared_ptr<Poller>, 64> m_pollers;
wpi::util::UidVector<std::shared_ptr<Poller>, 64> m_pollers;
std::function<void()> m_on_start;
std::function<void()> m_on_exit;
@@ -379,17 +379,17 @@ class CallbackManager {
thr->m_cond.notify_one();
}
typename wpi::SafeThreadOwner<Thread>::Proxy GetThread() const {
typename wpi::util::SafeThreadOwner<Thread>::Proxy GetThread() const {
return m_owner.GetThread();
}
private:
wpi::SafeThreadOwner<Thread> m_owner;
wpi::util::SafeThreadOwner<Thread> m_owner;
std::function<void()> m_on_start;
std::function<void()> m_on_exit;
};
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_CALLBACKMANAGER_HPP_

View File

@@ -7,11 +7,11 @@
#include <concepts>
#include <type_traits>
namespace wpi {
namespace wpi::util {
template <class Derived, class Base>
concept DecayedDerivedFrom =
std::derived_from<std::decay_t<Derived>, std::decay_t<Base>> &&
std::convertible_to<std::decay_t<Derived>*, std::decay_t<Base>*>;
} // namespace wpi
} // namespace wpi::util

View File

@@ -9,7 +9,7 @@
#include <string_view>
#include <typeinfo>
namespace wpi {
namespace wpi::util {
/**
* Demangle a C++ symbol.
@@ -28,6 +28,6 @@ std::string GetTypeName(const T& type) {
return Demangle(typeid(type).name());
}
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_DEMANGLE_HPP_

View File

@@ -8,10 +8,10 @@
#include "wpi/util/Synchronization.h"
#include "wpi/util/mutex.hpp"
namespace wpi {
namespace wpi::util {
struct EventVector {
wpi::mutex mutex;
wpi::SmallVector<WPI_EventHandle, 4> events;
wpi::util::mutex mutex;
wpi::util::SmallVector<WPI_EventHandle, 4> events;
/**
* Adds an event to the event vector.
@@ -44,8 +44,8 @@ struct EventVector {
void Wakeup() {
std::scoped_lock lock{mutex};
for (auto&& handle : events) {
wpi::SetEvent(handle);
wpi::util::SetEvent(handle);
}
}
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -53,7 +53,7 @@
// Allocates memory sparingly, and only once if the original maximum size
// estimate is never exceeded.
namespace wpi {
namespace wpi::util {
template<typename T, size_t MAX_BLOCK_SIZE = 512>
class FastQueue
@@ -554,4 +554,4 @@ private:
size_t largestBlockSize;
};
} // end namespace wpi
} // end namespace wpi::util

View File

@@ -10,7 +10,7 @@
#include <fmt/format.h>
namespace wpi {
namespace wpi::util {
enum LogLevel {
WPI_LOG_CRITICAL = 50,
@@ -73,22 +73,22 @@ class Logger {
}
#define WPI_ERROR(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_ERROR, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_ERROR, format __VA_OPT__(, ) __VA_ARGS__)
#define WPI_WARNING(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_WARNING, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_WARNING, format __VA_OPT__(, ) __VA_ARGS__)
#define WPI_INFO(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_INFO, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_INFO, format __VA_OPT__(, ) __VA_ARGS__)
#define WPI_DEBUG(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_DEBUG, format __VA_OPT__(, ) __VA_ARGS__)
#define WPI_DEBUG1(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG1, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_DEBUG1, format __VA_OPT__(, ) __VA_ARGS__)
#define WPI_DEBUG2(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG2, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_DEBUG2, format __VA_OPT__(, ) __VA_ARGS__)
#define WPI_DEBUG3(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG3, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_DEBUG3, format __VA_OPT__(, ) __VA_ARGS__)
#define WPI_DEBUG4(inst, format, ...) \
WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG4, format __VA_OPT__(, ) __VA_ARGS__)
WPI_LOG(inst, ::wpi::util::WPI_LOG_DEBUG4, format __VA_OPT__(, ) __VA_ARGS__)
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_LOGGER_HPP_

View File

@@ -18,7 +18,7 @@ using file_t = int;
#endif
} // namespace fs
namespace wpi {
namespace wpi::util {
class MappedFileRegion {
public:
@@ -83,4 +83,4 @@ class MappedFileRegion {
#endif
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -4,7 +4,7 @@
#pragma once
namespace wpi {
namespace wpi::util {
// A struct to use as a deleter when a std::shared_ptr must wrap a raw pointer
// that is being deleted by someone else.
@@ -13,4 +13,4 @@ struct NullDeleter {
void operator()(T*) const noexcept {};
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -61,18 +61,18 @@ enum WPI_PixelFormat {
};
/**
* Timestamp metadata. Timebase is the same as wpi::Now
* Timestamp metadata. Timebase is the same as wpi::util::Now
*/
enum WPI_TimestampSource {
WPI_TIMESRC_UNKNOWN = 0, // unknown
WPI_TIMESRC_FRAME_DEQUEUE, // wpi::Now when the new frame was dequeued by
WPI_TIMESRC_FRAME_DEQUEUE, // wpi::util::Now when the new frame was dequeued by
// CSCore. Does not account for camera exposure
// time or V4L latency.
WPI_TIMESRC_V4L_EOF, // End of Frame. Same as V4L2_BUF_FLAG_TSTAMP_SRC_EOF,
// translated into wpi::Now's timebase.
// translated into wpi::util::Now's timebase.
WPI_TIMESRC_V4L_SOE, // Start of Exposure. Same as
// V4L2_BUF_FLAG_TSTAMP_SRC_SOE, translated into
// wpi::Now's timebase.
// wpi::util::Now's timebase.
};
// Returns nonzero if the frame data was allocated/reallocated
@@ -88,7 +88,7 @@ void WPI_SetRawFrameData(WPI_RawFrame* frame, void* data, size_t size,
#endif
#ifdef __cplusplus
namespace wpi {
namespace wpi::util {
struct RawFrame : public WPI_RawFrame {
RawFrame() {
data = nullptr;
@@ -135,7 +135,7 @@ struct RawFrame : public WPI_RawFrame {
};
#ifdef WPI_RAWFRAME_JNI
template <std::same_as<wpi::RawFrame> T>
template <std::same_as<wpi::util::RawFrame> T>
void SetFrameData(JNIEnv* env, jclass rawFrameCls, jobject jframe,
const T& frame, bool newData) {
if (newData) {
@@ -160,7 +160,7 @@ void SetFrameData(JNIEnv* env, jclass rawFrameCls, jobject jframe,
}
#endif
} // namespace wpi
} // namespace wpi::util
#endif
#endif // WPIUTIL_WPI_UTIL_RAWFRAME_H_

View File

@@ -14,7 +14,7 @@
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi {
namespace wpi::util {
/**
* Base class for SafeThreadOwner threads.
@@ -25,7 +25,7 @@ class SafeThreadBase {
virtual void Main() = 0;
virtual void Stop() = 0;
mutable wpi::mutex m_mutex;
mutable wpi::util::mutex m_mutex;
std::atomic_bool m_active{true};
std::thread::id m_threadId;
};
@@ -34,7 +34,7 @@ class SafeThread : public SafeThreadBase {
public:
void Stop() override;
wpi::condition_variable m_cond;
wpi::util::condition_variable m_cond;
};
class SafeThreadEvent : public SafeThreadBase {
@@ -55,11 +55,11 @@ class SafeThreadProxyBase {
public:
explicit SafeThreadProxyBase(std::shared_ptr<SafeThreadBase> thr);
explicit operator bool() const { return m_thread != nullptr; }
std::unique_lock<wpi::mutex>& GetLock() { return m_lock; }
std::unique_lock<wpi::util::mutex>& GetLock() { return m_lock; }
protected:
std::shared_ptr<SafeThreadBase> m_thread;
std::unique_lock<wpi::mutex> m_lock;
std::unique_lock<wpi::util::mutex> m_lock;
};
/**
@@ -110,7 +110,7 @@ class SafeThreadOwnerBase {
std::shared_ptr<SafeThreadBase> GetThreadSharedPtr() const;
private:
mutable wpi::mutex m_mutex;
mutable wpi::util::mutex m_mutex;
std::thread m_stdThread;
std::weak_ptr<SafeThreadBase> m_thread;
std::atomic_bool m_joinAtExit{true};
@@ -140,6 +140,6 @@ class SafeThreadOwner : public detail::SafeThreadOwnerBase {
}
};
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_SAFETHREAD_HPP_

View File

@@ -7,7 +7,7 @@
#include <cassert>
#include <span>
namespace wpi {
namespace wpi::util {
/// Drop the first \p N elements of the array.
template <typename T, size_t N>
@@ -55,4 +55,4 @@ constexpr std::span<T> take_back(std::span<T, N> in,
return drop_front(in, length - n);
}
} // namespace wpi
} // namespace wpi::util

View File

@@ -7,7 +7,7 @@
#include <string>
namespace wpi {
namespace wpi::util {
/**
* Get a stack trace, ignoring the first "offset" symbols.
@@ -30,6 +30,6 @@ std::string GetStackTraceDefault(int offset);
*/
void SetGetStackTraceImpl(std::string (*func)(int offset));
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_STACKTRACE_HPP_

View File

@@ -13,7 +13,7 @@
#include <type_traits>
#include <utility>
namespace wpi {
namespace wpi::util {
/**
* StringMap is a sorted associative container that contains key-value pairs
@@ -767,11 +767,11 @@ class StringMap : public std::map<std::string, T, std::less<>, Allocator> {
}
};
} // namespace wpi
} // namespace wpi::util
namespace std {
template <typename T>
inline void swap(wpi::StringMap<T>& lhs, wpi::StringMap<T>& rhs) {
inline void swap(wpi::util::StringMap<T>& lhs, wpi::util::StringMap<T>& rhs) {
lhs.swap(rhs);
}
} // namespace std

View File

@@ -29,7 +29,7 @@ typedef WPI_Handle WPI_SemaphoreHandle; // NOLINT
#ifdef __cplusplus
namespace wpi {
namespace wpi::util {
/** Constant representing an invalid handle. */
constexpr unsigned int kInvalidHandle = 0;
@@ -442,7 +442,7 @@ class SignalObject final {
T m_handle;
};
} // namespace wpi
} // namespace wpi::util
extern "C" {

View File

@@ -9,7 +9,7 @@
#include <utility>
#include <vector>
namespace wpi {
namespace wpi::util {
namespace impl {
template <typename It>
@@ -154,6 +154,6 @@ class UidVector {
size_type m_active_count{0};
};
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_UIDVECTOR_HPP_

View File

@@ -10,7 +10,7 @@
#include <tuple>
#include <utility>
namespace wpi {
namespace wpi::util {
struct empty_array_t {};
constexpr empty_array_t empty_array;
@@ -59,42 +59,42 @@ class array : public std::array<T, N> {
template <typename T, std::convertible_to<T>... Ts>
array(T, Ts...) -> array<T, 1 + sizeof...(Ts)>;
} // namespace wpi
} // namespace wpi::util
template <size_t I, typename T, size_t N>
requires(I < N)
constexpr T& get(wpi::array<T, N>& arr) noexcept {
constexpr T& get(wpi::util::array<T, N>& arr) noexcept {
return std::get<I>(static_cast<std::array<T, N>>(arr));
}
template <size_t I, typename T, size_t N>
requires(I < N)
constexpr T&& get(wpi::array<T, N>&& arr) noexcept {
constexpr T&& get(wpi::util::array<T, N>&& arr) noexcept {
return std::move(std::get<I>(arr));
}
template <size_t I, typename T, size_t N>
requires(I < N)
constexpr const T& get(const wpi::array<T, N>& arr) noexcept {
constexpr const T& get(const wpi::util::array<T, N>& arr) noexcept {
return std::get<I>(static_cast<std::array<T, N>>(arr));
}
template <size_t I, typename T, size_t N>
requires(I < N)
constexpr const T&& get(const wpi::array<T, N>&& arr) noexcept {
constexpr const T&& get(const wpi::util::array<T, N>&& arr) noexcept {
return std::move(std::get<I>(arr));
}
// Enables structured bindings
namespace std { // NOLINT
// Partial specialization for wpi::array
// Partial specialization for wpi::util::array
template <typename T, size_t N>
struct tuple_size<wpi::array<T, N>> : public integral_constant<size_t, N> {};
struct tuple_size<wpi::util::array<T, N>> : public integral_constant<size_t, N> {};
// Partial specialization for wpi::array
// Partial specialization for wpi::util::array
template <size_t I, typename T, size_t N>
requires(I < N)
struct tuple_element<I, wpi::array<T, N>> {
struct tuple_element<I, wpi::util::array<T, N>> {
using type = T;
};
} // namespace std

View File

@@ -8,7 +8,7 @@
#include <iterator>
#include <vector>
namespace wpi {
namespace wpi::util {
/**
* This is a simple circular buffer so we don't need to "bucket brigade" copy
@@ -117,7 +117,7 @@ class circular_buffer {
* Returns end iterator.
*/
constexpr iterator end() {
return iterator(this, ::wpi::circular_buffer<T>::size());
return iterator(this, ::wpi::util::circular_buffer<T>::size());
}
/**
@@ -129,7 +129,7 @@ class circular_buffer {
* Returns const end iterator.
*/
constexpr const_iterator end() const {
return const_iterator(this, ::wpi::circular_buffer<T>::size());
return const_iterator(this, ::wpi::util::circular_buffer<T>::size());
}
/**
@@ -141,7 +141,7 @@ class circular_buffer {
* Returns const end iterator.
*/
constexpr const_iterator cend() const {
return const_iterator(this, ::wpi::circular_buffer<T>::size());
return const_iterator(this, ::wpi::util::circular_buffer<T>::size());
}
/**
@@ -431,4 +431,4 @@ class circular_buffer {
}
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -8,7 +8,7 @@
#include "wpi/util/priority_mutex.hpp"
namespace wpi {
namespace wpi::util {
#if defined(__linux__) && defined(WPI_HAVE_PRIORITY_MUTEX)
using condition_variable = ::std::condition_variable_any;
@@ -16,4 +16,4 @@ using condition_variable = ::std::condition_variable_any;
using condition_variable = ::std::condition_variable;
#endif
} // namespace wpi
} // namespace wpi::util

View File

@@ -12,7 +12,7 @@
#include <string>
#include <string_view>
namespace wpi {
namespace wpi::util {
// derived from:
// https://codereview.stackexchange.com/questions/282514/string-literals-concatenation-with-support-for-dynamic-strings
@@ -228,4 +228,4 @@ constexpr auto NumToCtString() {
return res;
}
} // namespace wpi
} // namespace wpi::util

View File

@@ -9,9 +9,9 @@
#include "wpi/util/raw_ostream.hpp"
namespace wpi {
namespace wpi::util {
inline void vprint(wpi::raw_ostream& os, fmt::string_view format_str,
inline void vprint(wpi::util::raw_ostream& os, fmt::string_view format_str,
fmt::format_args args) {
fmt::memory_buffer buffer;
fmt::detail::vformat_to(buffer, format_str, args);
@@ -22,10 +22,10 @@ inline void vprint(wpi::raw_ostream& os, fmt::string_view format_str,
* Prints formatted data to the stream *os*.
*/
template <typename S, typename... Args>
void print(wpi::raw_ostream& os, const S& format_str, Args&&... args) {
void print(wpi::util::raw_ostream& os, const S& format_str, Args&&... args) {
vprint(os, format_str, fmt::make_format_args(args...));
}
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_FMT_RAW_OSTREAM_HPP_

View File

@@ -18,7 +18,7 @@
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi {
namespace wpi::util {
template <typename T>
class PromiseFactory;
@@ -39,16 +39,16 @@ class PromiseFactoryBase {
bool IsActive() const { return m_active; }
wpi::mutex& GetResultMutex() { return m_resultMutex; }
wpi::util::mutex& GetResultMutex() { return m_resultMutex; }
void Notify() { m_resultCv.notify_all(); }
// must be called with locked lock == ResultMutex
void Wait(std::unique_lock<wpi::mutex>& lock) { m_resultCv.wait(lock); }
void Wait(std::unique_lock<wpi::util::mutex>& lock) { m_resultCv.wait(lock); }
// returns false if timeout reached
template <class Clock, class Duration>
bool WaitUntil(std::unique_lock<wpi::mutex>& lock,
bool WaitUntil(std::unique_lock<wpi::util::mutex>& lock,
const std::chrono::time_point<Clock, Duration>& timeout_time) {
return m_resultCv.wait_until(lock, timeout_time) ==
std::cv_status::no_timeout;
@@ -67,9 +67,9 @@ class PromiseFactoryBase {
uint64_t CreateErasedRequest() { return ++m_uid; }
private:
wpi::mutex m_resultMutex;
wpi::util::mutex m_resultMutex;
std::atomic_bool m_active{true};
wpi::condition_variable m_resultCv;
wpi::util::condition_variable m_resultCv;
uint64_t m_uid = 0;
std::vector<uint64_t> m_requests;
@@ -938,6 +938,6 @@ future<void> detail::FutureThen<void, void>::Create(
return factory.CreateFuture(req);
}
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_FUTURE_HPP_

View File

@@ -7,7 +7,7 @@
#include <map>
#include <utility>
namespace wpi {
namespace wpi::util {
/**
* Implements a table of key-value pairs with linear interpolation between
@@ -84,4 +84,4 @@ class interpolating_map {
std::map<Key, Value> m_container;
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -26,7 +26,7 @@
#include "wpi/util/string.h"
/** Java Native Interface (JNI) utility functions */
namespace wpi::java {
namespace wpi::util::java {
/**
* Gets a Java stack trace.
@@ -160,7 +160,7 @@ class JStringRef {
env->ReleaseStringCritical(str, chars);
}
} else {
wpi::print(stderr, "JStringRef was passed a null pointer at\n",
wpi::util::print(stderr, "JStringRef was passed a null pointer at\n",
GetJavaStackTrace(env));
}
// Ensure str is null-terminated.
@@ -172,7 +172,7 @@ class JStringRef {
std::string_view str() const { return m_str.str(); }
const char* c_str() const { return m_str.data(); }
size_t size() const { return m_str.size(); }
WPI_String wpi_str() const { return wpi::make_string(str()); }
WPI_String wpi_str() const { return wpi::util::make_string(str()); }
private:
SmallString<128> m_str;
@@ -284,7 +284,7 @@ class JSpanBase {
m_elements{static_cast<std::remove_cv_t<T>*>(
bb ? env->GetDirectBufferAddress(bb) : nullptr)} {
if (!bb) {
wpi::print(stderr, "JSpan was passed a null pointer at\n",
wpi::util::print(stderr, "JSpan was passed a null pointer at\n",
GetJavaStackTrace(env));
}
}
@@ -303,7 +303,7 @@ class JSpanBase {
m_elements = ArrHelper::GetArrayElements(env, jarr);
}
} else {
wpi::print(stderr, "JSpan was passed a null pointer at\n",
wpi::util::print(stderr, "JSpan was passed a null pointer at\n",
GetJavaStackTrace(env));
}
}
@@ -845,7 +845,7 @@ inline std::string GetJavaStackTrace(JNIEnv* env, std::string_view skipPrefix) {
// add a line to res
JStringRef elem(env, stackElementString);
if (!foundFirst) {
if (wpi::starts_with(elem, skipPrefix)) {
if (wpi::util::starts_with(elem, skipPrefix)) {
continue;
}
foundFirst = true;
@@ -928,7 +928,7 @@ inline std::string GetJavaStackTrace(JNIEnv* env, std::string* func,
if (i == 1) {
*func = elem.str();
} else if (i > 1 && !haveLoc && !excludeFuncPrefix.empty() &&
!wpi::starts_with(elem, excludeFuncPrefix)) {
!wpi::util::starts_with(elem, excludeFuncPrefix)) {
*func = elem.str();
haveLoc = true;
}
@@ -975,6 +975,6 @@ struct JExceptionInit {
JException* cls;
};
} // namespace wpi::java
} // namespace wpi::util::java
#endif // WPIUTIL_WPI_UTIL_JNI_UTIL_HPP_

View File

@@ -8,7 +8,7 @@
#include "wpi/util/priority_mutex.hpp"
namespace wpi {
namespace wpi::util {
#ifdef WPI_HAVE_PRIORITY_MUTEX
using mutex = priority_mutex;
@@ -18,4 +18,4 @@ using mutex = ::std::mutex;
using recursive_mutex = ::std::recursive_mutex;
#endif
} // namespace wpi
} // namespace wpi::util

View File

@@ -14,7 +14,7 @@
#include <fmt/core.h>
#endif
namespace wpi {
namespace wpi::util {
/**
* Wrapper around fmt::print() that squelches write failure exceptions.
@@ -60,4 +60,4 @@ inline void println(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
}
}
} // namespace wpi
} // namespace wpi::util

View File

@@ -11,7 +11,7 @@
#include <mutex>
namespace wpi {
namespace wpi::util {
#if defined(__FRC_SYSTEMCORE__) && !defined(WPI_USE_PRIORITY_MUTEX)
#define WPI_USE_PRIORITY_MUTEX
@@ -75,4 +75,4 @@ class priority_mutex {
#endif // defined(WPI_USE_PRIORITY_MUTEX) && defined(__linux__)
} // namespace wpi
} // namespace wpi::util

View File

@@ -11,7 +11,7 @@
#include <utility>
#include <vector>
namespace wpi {
namespace wpi::util {
/**
* This class is the same as std::priority_queue with two changes:
@@ -111,6 +111,6 @@ class priority_queue {
Compare comp;
};
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_PRIORITY_QUEUE_HPP_

View File

@@ -20,7 +20,7 @@
#include "wpi/util/array.hpp"
#include "wpi/util/function_ref.hpp"
namespace wpi {
namespace wpi::util {
template <typename T>
class SmallVectorImpl;
@@ -36,7 +36,7 @@ template <typename T>
struct Protobuf {};
namespace detail {
using SmallVectorType = wpi::SmallVectorImpl<uint8_t>;
using SmallVectorType = wpi::util::SmallVectorImpl<uint8_t>;
using StdVectorType = std::vector<uint8_t>;
bool WriteFromSmallVector(pb_ostream_t* stream, const pb_byte_t* buf,
size_t count);
@@ -232,25 +232,25 @@ class ProtoOutputStream {
* values into a nanopb Stream and deserialization consists of
* reading values from nanopb Stream.
*
* Implementations must define a template specialization for wpi::Protobuf with
* Implementations must define a template specialization for wpi::util::Protobuf with
* T being the type that is being serialized/deserialized, with the following
* static members (as enforced by this concept):
* - using MessageStruct = nanopb_message_struct_here: typedef to the wpilib
* modified nanopb message struct
* - std::optional<T> Unpack(wpi::ProtoInputStream<T>&): function
* - std::optional<T> Unpack(wpi::util::ProtoInputStream<T>&): function
* for deserialization
* - bool Pack(wpi::ProtoOutputStream<T>&, T&& value): function
* - bool Pack(wpi::util::ProtoOutputStream<T>&, T&& value): function
* for serialization
*
* As a suggestion, 2 extra type usings can be added to simplify the stream
* definitions, however these are not required.
* - using InputStream = wpi::ProtoInputStream<T>;
* - using OutputStream = wpi::ProtoOutputStream<T>;
* - using InputStream = wpi::util::ProtoInputStream<T>;
* - using OutputStream = wpi::util::ProtoOutputStream<T>;
*/
template <typename T>
concept ProtobufSerializable = requires(
wpi::ProtoOutputStream<std::remove_cvref_t<T>>& ostream,
wpi::ProtoInputStream<std::remove_cvref_t<T>>& istream, const T& value) {
wpi::util::ProtoOutputStream<std::remove_cvref_t<T>>& ostream,
wpi::util::ProtoInputStream<std::remove_cvref_t<T>>& istream, const T& value) {
typename Protobuf<typename std::remove_cvref_t<T>>;
{
Protobuf<typename std::remove_cvref_t<T>>::Unpack(istream)
@@ -274,14 +274,14 @@ concept ProtobufSerializable = requires(
* Specifies that a type is capable of in-place protobuf deserialization.
*
* In addition to meeting ProtobufSerializable, implementations must define a
* wpi::Protobuf<T> static member -
* `bool UnpackInto(T*, wpi::ProtoInputStream<T>&)` to update the pointed-to T
* wpi::util::Protobuf<T> static member -
* `bool UnpackInto(T*, wpi::util::ProtoInputStream<T>&)` to update the pointed-to T
* with the contents of the message.
*/
template <typename T>
concept MutableProtobufSerializable =
ProtobufSerializable<T> &&
requires(T* out, wpi::ProtoInputStream<T>& istream) {
requires(T* out, wpi::util::ProtoInputStream<T>& istream) {
{
Protobuf<typename std::remove_cvref_t<T>>::UnpackInto(out, istream)
} -> std::same_as<bool>;
@@ -345,7 +345,7 @@ class ProtobufMessage {
* @param[in] value value
* @return true if successful
*/
bool Pack(wpi::SmallVectorImpl<uint8_t>& out, const T& value) {
bool Pack(wpi::util::SmallVectorImpl<uint8_t>& out, const T& value) {
ProtoOutputStream<std::remove_cvref_t<T>> stream{out};
return Protobuf<std::remove_cvref_t<T>>::Pack(stream, value);
}
@@ -391,4 +391,4 @@ class ProtobufMessage {
}
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -15,7 +15,7 @@
#include "wpi/util/array.hpp"
#include "wpi/util/protobuf/Protobuf.hpp"
namespace wpi {
namespace wpi::util {
/**
* The behavior to use when more elements are in the message then expected when
@@ -268,7 +268,7 @@ class DirectUnpackCallback {
space.size());
} else if constexpr (ProtobufSerializable<T>) {
ProtoInputStream<T> istream{stream};
auto decoded = wpi::Protobuf<T>::Unpack(istream);
auto decoded = wpi::util::Protobuf<T>::Unpack(istream);
if (decoded.has_value()) {
m_storage.emplace_back(std::move(decoded.value()));
return true;
@@ -332,13 +332,13 @@ class DirectUnpackCallback {
*/
template <ProtoCallbackUnpackable T, size_t N = 1>
class UnpackCallback
: public DirectUnpackCallback<T, wpi::SmallVector<T, N>, N> {
: public DirectUnpackCallback<T, wpi::util::SmallVector<T, N>, N> {
public:
/**
* Constructs an UnpackCallback.
*/
UnpackCallback()
: DirectUnpackCallback<T, wpi::SmallVector<T, N>, N>{m_storedBuffer} {
: DirectUnpackCallback<T, wpi::util::SmallVector<T, N>, N>{m_storedBuffer} {
this->SetLimits(DecodeLimits::Ignore);
}
@@ -361,10 +361,10 @@ class UnpackCallback
*
* @return small vector reference
*/
wpi::SmallVector<T, N>& Vec() noexcept { return m_storedBuffer; }
wpi::util::SmallVector<T, N>& Vec() noexcept { return m_storedBuffer; }
private:
wpi::SmallVector<T, N> m_storedBuffer;
wpi::util::SmallVector<T, N> m_storedBuffer;
};
/**
@@ -414,12 +414,12 @@ class StdVectorUnpackCallback
};
/**
* A wrapper around a wpi::array that lets us
* A wrapper around a wpi::util::array that lets us
* treat it as a limited sized vector.
*/
template <ProtoCallbackUnpackable T, size_t N>
struct WpiArrayEmplaceWrapper {
wpi::array<T, N> m_array{wpi::empty_array_t{}};
wpi::util::array<T, N> m_array{wpi::util::empty_array_t{}};
size_t m_currentIndex = 0;
size_t size() const { return m_currentIndex; }
@@ -433,7 +433,7 @@ struct WpiArrayEmplaceWrapper {
};
/**
* A DirectUnpackCallback backed by a wpi::array<T, N>.
* A DirectUnpackCallback backed by a wpi::util::array<T, N>.
*
* Any elements in the packed buffer past N will
* be cause decoding to fail.
@@ -471,7 +471,7 @@ struct WpiArrayUnpackCallback
*
* @return array reference
*/
wpi::array<T, N>& Array() noexcept { return m_array.m_array; }
wpi::util::array<T, N>& Array() noexcept { return m_array.m_array; }
private:
WpiArrayEmplaceWrapper<T, N> m_array;
@@ -581,7 +581,7 @@ class PackCallback {
reinterpret_cast<const pb_byte_t*>(view.data()),
view.size());
} else if constexpr (ProtobufSerializable<T>) {
return wpi::Protobuf<T>::Pack(stream, value);
return wpi::util::Protobuf<T>::Pack(stream, value);
}
}
@@ -667,4 +667,4 @@ class PackCallback {
pb_callback_t m_callback;
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -17,7 +17,7 @@
#include "wpi/util/SmallVector.hpp"
namespace wpi {
namespace wpi::util {
class raw_istream {
public:
@@ -171,6 +171,6 @@ class raw_fd_istream : public raw_istream {
bool m_shouldClose;
};
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_RAW_ISTREAM_HPP_

View File

@@ -10,7 +10,7 @@
#include <span>
#include <type_traits>
namespace wpi {
namespace wpi::util {
/**
* This is a simple rotated span view. Indexed/iterated access provides a
@@ -251,4 +251,4 @@ as_writable_bytes(rotated_span<Type, Extent> sp) noexcept {
return {std::as_writable_bytes(sp.data()), sp.offset() * sizeof(Type)};
}
} // namespace wpi
} // namespace wpi::util

View File

@@ -6,7 +6,7 @@
#include "wpi/util/SymbolExports.hpp"
namespace wpi {
namespace wpi::util {
class SendableBuilder;
@@ -25,4 +25,4 @@ class WPILIB_DLLEXPORT Sendable {
virtual void InitSendable(SendableBuilder& builder) = 0;
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -13,7 +13,7 @@
#include "wpi/util/SmallVector.hpp"
namespace wpi {
namespace wpi::util {
/**
* Helper class for building Sendable dashboard representations.
@@ -277,7 +277,7 @@ class SendableBuilder {
*/
virtual void AddSmallStringProperty(
std::string_view key,
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<std::string_view(wpi::util::SmallVectorImpl<char>& buf)> getter,
std::function<void(std::string_view)> setter) = 0;
/**
@@ -289,7 +289,7 @@ class SendableBuilder {
*/
virtual void AddSmallBooleanArrayProperty(
std::string_view key,
std::function<std::span<const int>(wpi::SmallVectorImpl<int>& buf)>
std::function<std::span<const int>(wpi::util::SmallVectorImpl<int>& buf)>
getter,
std::function<void(std::span<const int>)> setter) = 0;
@@ -303,7 +303,7 @@ class SendableBuilder {
virtual void AddSmallIntegerArrayProperty(
std::string_view key,
std::function<
std::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
std::span<const int64_t>(wpi::util::SmallVectorImpl<int64_t>& buf)>
getter,
std::function<void(std::span<const int64_t>)> setter) = 0;
@@ -316,7 +316,7 @@ class SendableBuilder {
*/
virtual void AddSmallFloatArrayProperty(
std::string_view key,
std::function<std::span<const float>(wpi::SmallVectorImpl<float>& buf)>
std::function<std::span<const float>(wpi::util::SmallVectorImpl<float>& buf)>
getter,
std::function<void(std::span<const float>)> setter) = 0;
@@ -329,7 +329,7 @@ class SendableBuilder {
*/
virtual void AddSmallDoubleArrayProperty(
std::string_view key,
std::function<std::span<const double>(wpi::SmallVectorImpl<double>& buf)>
std::function<std::span<const double>(wpi::util::SmallVectorImpl<double>& buf)>
getter,
std::function<void(std::span<const double>)> setter) = 0;
@@ -343,7 +343,7 @@ class SendableBuilder {
virtual void AddSmallStringArrayProperty(
std::string_view key,
std::function<
std::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
std::span<const std::string>(wpi::util::SmallVectorImpl<std::string>& buf)>
getter,
std::function<void(std::span<const std::string>)> setter) = 0;
@@ -357,7 +357,7 @@ class SendableBuilder {
*/
virtual void AddSmallRawProperty(
std::string_view key, std::string_view typeString,
std::function<std::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
std::function<std::span<uint8_t>(wpi::util::SmallVectorImpl<uint8_t>& buf)>
getter,
std::function<void(std::span<const uint8_t>)> setter) = 0;
@@ -386,4 +386,4 @@ class SendableBuilder {
virtual void ClearProperties() = 0;
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -8,7 +8,7 @@
#include "wpi/util/sendable/SendableRegistry.hpp"
namespace wpi {
namespace wpi::util {
/**
* A helper class for use with objects that add themselves to SendableRegistry.
@@ -59,4 +59,4 @@ class SendableHelper {
}
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -8,7 +8,7 @@
#include <string>
#include <string_view>
namespace wpi {
namespace wpi::util {
class Sendable;
class SendableBuilder;
@@ -237,4 +237,4 @@ class SendableRegistry final {
static void Update(UID sendableUid);
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -25,7 +25,7 @@
#include <string>
#include <string_view>
namespace wpi {
namespace wpi::util {
template <typename T>
class SmallVectorImpl;
class raw_istream;
@@ -47,6 +47,6 @@ class SHA1 {
uint64_t transforms;
};
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_UTIL_SHA1_HPP_

View File

@@ -11,7 +11,7 @@
#include "wpi/util/Compiler.hpp"
namespace wpi {
namespace wpi::util {
/**
* A spinlock mutex. Wraps std::atomic_flag in a std::mutex compatible way.
@@ -141,4 +141,4 @@ using recursive_spinlock = recursive_spinlock2;
using recursive_spinlock = recursive_spinlock1;
#endif
} // namespace wpi
} // namespace wpi::util

View File

@@ -8,7 +8,7 @@
#include <cstddef>
#include <iterator>
namespace wpi {
namespace wpi::util {
/**
* This is a simple circular buffer so we don't need to "bucket brigade" copy
@@ -108,7 +108,7 @@ class static_circular_buffer {
* Returns end iterator.
*/
constexpr iterator end() {
return iterator(this, ::wpi::static_circular_buffer<T, N>::size());
return iterator(this, ::wpi::util::static_circular_buffer<T, N>::size());
}
/**
@@ -120,7 +120,7 @@ class static_circular_buffer {
* Returns const end iterator.
*/
constexpr const_iterator end() const {
return const_iterator(this, ::wpi::static_circular_buffer<T, N>::size());
return const_iterator(this, ::wpi::util::static_circular_buffer<T, N>::size());
}
/**
@@ -132,7 +132,7 @@ class static_circular_buffer {
* Returns const end iterator.
*/
constexpr const_iterator cend() const {
return const_iterator(this, ::wpi::static_circular_buffer<T, N>::size());
return const_iterator(this, ::wpi::util::static_circular_buffer<T, N>::size());
}
/**
@@ -348,4 +348,4 @@ class static_circular_buffer {
}
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -20,7 +20,7 @@ struct WPI_String {
};
#ifdef __cplusplus
namespace wpi {
namespace wpi::util {
/** Converts a WPI_String to a string_view */
constexpr std::string_view to_string_view(const struct WPI_String* str) {
if (str) {
@@ -34,7 +34,7 @@ constexpr std::string_view to_string_view(const struct WPI_String* str) {
constexpr WPI_String make_string(std::string_view view) {
return WPI_String{view.data(), view.size()};
}
} // namespace wpi
} // namespace wpi::util
#endif // __cplusplus
#ifdef __cplusplus
@@ -109,7 +109,7 @@ void WPI_FreeStringArray(const struct WPI_String* wpiStringArray,
#endif // __cplusplus
#ifdef __cplusplus
namespace wpi {
namespace wpi::util {
/** Allocates a copy of a string_view and stores the result into a WPI_String */
inline WPI_String alloc_wpi_string(std::string_view view) {
@@ -126,5 +126,5 @@ inline WPI_String copy_wpi_string(const WPI_String& str) {
}
return alloc_wpi_string(to_string_view(&str));
}
} // namespace wpi
} // namespace wpi::util
#endif

View File

@@ -16,7 +16,7 @@
#include "wpi/util/StringMap.hpp"
#include "wpi/util/bit.hpp"
namespace wpi {
namespace wpi::util {
template <typename T>
class SmallVectorImpl;
@@ -316,9 +316,9 @@ class StructDescriptor {
private:
bool CheckCircular(
wpi::SmallVectorImpl<const StructDescriptor*>& stack) const;
wpi::util::SmallVectorImpl<const StructDescriptor*>& stack) const;
std::string CalculateOffsets(
wpi::SmallVectorImpl<const StructDescriptor*>& stack);
wpi::util::SmallVectorImpl<const StructDescriptor*>& stack);
std::string m_name;
std::string m_schema;
@@ -696,4 +696,4 @@ class DynamicStructObject : private impl::DSOData, public MutableDynamicStruct {
DynamicStructObject& operator=(DynamicStructObject&&) = delete;
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -11,7 +11,7 @@
#include <utility>
#include <vector>
namespace wpi::structparser {
namespace wpi::util::structparser {
/**
* A lexed raw struct schema token.
@@ -196,4 +196,4 @@ class Parser {
std::string m_error;
};
} // namespace wpi::structparser
} // namespace wpi::util::structparser

View File

@@ -25,7 +25,7 @@
#include "wpi/util/mutex.hpp"
#include "wpi/util/type_traits.hpp"
namespace wpi {
namespace wpi::util {
/**
* Struct serialization template. Unspecialized class has no members; only
@@ -47,7 +47,7 @@ struct Struct {};
* values into a mutable std::span and deserialization consists of reading
* values from an immutable std::span.
*
* Implementations must define a template specialization for wpi::Struct with
* Implementations must define a template specialization for wpi::util::Struct with
* T being the type that is being serialized/deserialized, with the following
* static members (as enforced by this concept):
* - std::string_view GetTypeName(): function that returns the type name
@@ -96,7 +96,7 @@ concept StructSerializable = requires(std::span<const uint8_t> in,
* Specifies that a type is capable of in-place raw struct deserialization.
*
* In addition to meeting StructSerializable, implementations must define a
* wpi::Struct<T> static member `void UnpackInto(T*, std::span<const uint8_t>)`
* wpi::util::Struct<T> static member `void UnpackInto(T*, std::span<const uint8_t>)`
* to update the pointed-to T with the contents of the span.
*/
template <typename T, typename... I>
@@ -111,7 +111,7 @@ concept MutableStructSerializable =
* Specifies that a struct type has nested struct declarations.
*
* In addition to meeting StructSerializable, implementations must define a
* wpi::Struct<T> static member
* wpi::util::Struct<T> static member
* `void ForEachNested(std::invocable<std::string_view, std::string_view) auto
* fn)` (or equivalent) and call ForEachStructSchema<Type> on each nested struct
* type.
@@ -169,17 +169,17 @@ inline T UnpackStruct(std::span<const uint8_t> data, const I&... info) {
* @return Deserialized array
*/
template <StructSerializable T, size_t Offset, size_t N>
inline wpi::array<T, N> UnpackStructArray(std::span<const uint8_t> data) {
inline wpi::util::array<T, N> UnpackStructArray(std::span<const uint8_t> data) {
if (is_constexpr([] { Struct<std::remove_cvref_t<T>>::GetSize(); })) {
constexpr auto StructSize = Struct<std::remove_cvref_t<T>>::GetSize();
wpi::array<T, N> arr(wpi::empty_array);
wpi::util::array<T, N> arr(wpi::util::empty_array);
[&]<size_t... Is>(std::index_sequence<Is...>) {
((arr[Is] = UnpackStruct<T, Offset + Is * StructSize>(data)), ...);
}(std::make_index_sequence<N>{});
return arr;
} else {
auto size = Struct<std::remove_cvref_t<T>>::GetSize();
wpi::array<T, N> arr(wpi::empty_array);
wpi::util::array<T, N> arr(wpi::util::empty_array);
for (size_t i = 0; i < N; i++) {
arr[i] = UnpackStruct<T>(data);
data = data.subspan(size);
@@ -232,7 +232,7 @@ inline void PackStruct(std::span<uint8_t> data, T&& value, const I&... info) {
*/
template <size_t Offset, size_t N, StructSerializable T>
inline void PackStructArray(std::span<uint8_t> data,
const wpi::array<T, N>& arr) {
const wpi::util::array<T, N>& arr) {
if (is_constexpr([] { Struct<std::remove_cvref_t<T>>::GetSize(); })) {
constexpr auto StructSize = Struct<std::remove_cvref_t<T>>::GetSize();
[&]<size_t... Is>(std::index_sequence<Is...>) {
@@ -480,7 +480,7 @@ class StructArrayBuffer {
}
private:
wpi::mutex m_mutex;
wpi::util::mutex m_mutex;
std::vector<uint8_t> m_buf;
};
@@ -711,4 +711,4 @@ struct Struct<double> {
}
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -51,7 +51,7 @@ uint64_t WPI_GetSystemTime(void);
#endif
#ifdef __cplusplus
namespace wpi {
namespace wpi::util {
/**
* The default implementation used for Now().
@@ -83,7 +83,7 @@ uint64_t Now();
*/
uint64_t GetSystemTime();
} // namespace wpi
} // namespace wpi::util
#endif
#endif // WPIUTIL_WPI_UTIL_TIMESTAMP_H_

View File

@@ -71,7 +71,7 @@ SOFTWARE.
#define WPI_CUSTOM_STRTOLD strtold
#endif
namespace wpi {
namespace wpi::util {
namespace details { // namespace for helper methods
@@ -2540,4 +2540,4 @@ protected:
std::vector<std::string> m_group_names;
};
} // namespace wpi
} // namespace wpi::util

View File

@@ -3,7 +3,7 @@
#include <debugging/detail/psnip_debug_trap.h>
namespace wpi {
namespace wpi::util {
bool is_debugger_present() noexcept;
@@ -24,6 +24,6 @@ inline void breakpoint_if_debugging() noexcept
if (is_debugger_present()) breakpoint();
}
} // namespace wpi
} // namespace wpi::util
#endif

View File

@@ -6,13 +6,13 @@
# include <fstream>
# include <string>
namespace wpi {
namespace wpi::util {
bool is_debugger_present() noexcept
{
return false;
}
} // namespace wpi
} // namespace wpi::util
#endif

View File

@@ -7,7 +7,7 @@
# include <fstream>
# include <string>
namespace wpi {
namespace wpi::util {
bool is_debugger_present() noexcept
{
@@ -20,6 +20,6 @@ bool is_debugger_present() noexcept
return buffer[index + 11] != '0';
}
} // namespace wpi
} // namespace wpi::util
#endif

View File

@@ -11,7 +11,7 @@
template <class T>
auto exc = std::array<T, EXC_TYPES_COUNT> { {} };
namespace wpi {
namespace wpi::util {
bool is_debugger_present() noexcept
{
@@ -31,6 +31,6 @@ bool is_debugger_present() noexcept
return end != std::find_if(begin, end, valid);
}
} // namespace wpi
} // namespace wpi::util
#endif

View File

@@ -6,13 +6,13 @@
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
namespace wpi {
namespace wpi::util {
bool is_debugger_present() noexcept
{
return ::IsDebuggerPresent();
}
} // namespace wpi
} // namespace wpi::util
#endif

View File

@@ -25,30 +25,30 @@ struct adl_serializer
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
noexcept(::wpi::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::wpi::from_json(std::forward<BasicJsonType>(j), val), void())
noexcept(::wpi::util::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::wpi::util::from_json(std::forward<BasicJsonType>(j), val), void())
{
::wpi::from_json(std::forward<BasicJsonType>(j), val);
::wpi::util::from_json(std::forward<BasicJsonType>(j), val);
}
/// @brief convert a JSON value to any value type
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j) noexcept(
noexcept(::wpi::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
-> decltype(::wpi::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
noexcept(::wpi::util::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
-> decltype(::wpi::util::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
{
return ::wpi::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
return ::wpi::util::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
}
/// @brief convert any value type to a JSON value
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::wpi::to_json(j, std::forward<TargetType>(val))))
-> decltype(::wpi::to_json(j, std::forward<TargetType>(val)), void())
noexcept(::wpi::util::to_json(j, std::forward<TargetType>(val))))
-> decltype(::wpi::util::to_json(j, std::forward<TargetType>(val)), void())
{
::wpi::to_json(j, std::forward<TargetType>(val));
::wpi::util::to_json(j, std::forward<TargetType>(val));
}
};

View File

@@ -44,18 +44,18 @@
#ifndef WPI_JSON_NAMESPACE
#define WPI_JSON_NAMESPACE \
wpi::WPI_JSON_NAMESPACE_CONCAT( \
wpi::util::WPI_JSON_NAMESPACE_CONCAT( \
WPI_JSON_ABI_TAGS, \
WPI_JSON_NAMESPACE_VERSION)
#endif
#ifndef WPI_JSON_NAMESPACE_BEGIN
#define WPI_JSON_NAMESPACE_BEGIN \
namespace wpi \
namespace wpi::util \
{
#endif
#ifndef WPI_JSON_NAMESPACE_END
#define WPI_JSON_NAMESPACE_END \
} // namespace wpi
} // namespace wpi::util
#endif

View File

@@ -22,7 +22,7 @@ WPI_JSON_NAMESPACE_BEGIN
/*!
@brief SAX interface
This class describes the SAX interface used by @ref wpi::json::sax_parse.
This class describes the SAX interface used by @ref wpi::util::json::sax_parse.
Each function is called in different situations while the input is parsed. The
boolean return value informs the parser whether to continue processing the
input.

View File

@@ -190,7 +190,7 @@ template<typename IteratorType> class iteration_proxy
// For further reference see https://blog.tartanllama.xyz/structured-bindings/
// And see https://github.com/nlohmann/json/pull/1391
template<std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>
auto get(const wpi::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
auto get(const wpi::util::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
{
return i.key();
}
@@ -198,7 +198,7 @@ auto get(const wpi::detail::iteration_proxy_value<IteratorType>& i) -> decltype(
// For further reference see https://blog.tartanllama.xyz/structured-bindings/
// And see https://github.com/nlohmann/json/pull/1391
template<std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>
auto get(const wpi::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
auto get(const wpi::util::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
{
return i.value();
}
@@ -219,16 +219,16 @@ namespace std
#pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
template<typename IteratorType>
class tuple_size<::wpi::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
class tuple_size<::wpi::util::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
: public std::integral_constant<std::size_t, 2> {};
template<std::size_t N, typename IteratorType>
class tuple_element<N, ::wpi::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp)
class tuple_element<N, ::wpi::util::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp)
{
public:
using type = decltype(
get<N>(std::declval <
::wpi::detail::iteration_proxy_value<IteratorType >> ()));
::wpi::util::detail::iteration_proxy_value<IteratorType >> ()));
};
#if defined(__clang__)
#pragma clang diagnostic pop
@@ -238,5 +238,5 @@ class tuple_element<N, ::wpi::detail::iteration_proxy_value<IteratorType >> // N
#if JSON_HAS_RANGES
template <typename IteratorType>
inline constexpr bool ::std::ranges::enable_borrowed_range<::wpi::detail::iteration_proxy<IteratorType>> = true;
inline constexpr bool ::std::ranges::enable_borrowed_range<::wpi::util::detail::iteration_proxy<IteratorType>> = true;
#endif

View File

@@ -399,15 +399,15 @@
@since version 3.9.0
*/
#define WPI_DEFINE_TYPE_INTRUSIVE(Type, ...) \
friend void to_json(wpi::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const wpi::json& nlohmann_json_j, Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM, __VA_ARGS__)) }
friend void to_json(wpi::util::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const wpi::util::json& nlohmann_json_j, Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM, __VA_ARGS__)) }
#define WPI_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
friend void to_json(wpi::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const wpi::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
friend void to_json(wpi::util::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const wpi::util::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
#define WPI_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
friend void to_json(wpi::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) }
friend void to_json(wpi::util::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) }
/*!
@brief macro
@@ -415,15 +415,15 @@
@since version 3.9.0
*/
#define WPI_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
inline void to_json(wpi::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const wpi::json& nlohmann_json_j, Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM, __VA_ARGS__)) }
inline void to_json(wpi::util::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const wpi::util::json& nlohmann_json_j, Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM, __VA_ARGS__)) }
#define WPI_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
inline void to_json(wpi::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) }
inline void to_json(wpi::util::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) }
#define WPI_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
inline void to_json(wpi::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const wpi::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
inline void to_json(wpi::util::json& nlohmann_json_j, const Type& nlohmann_json_t) { WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const wpi::util::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; WPI_JSON_EXPAND(WPI_JSON_PASTE(WPI_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
// inspired from https://stackoverflow.com/a/26745591
// allows to call any std function as if (e.g. with begin):
@@ -453,7 +453,7 @@
template<typename... T> \
struct would_call_std_##std_name \
{ \
static constexpr auto const value = ::wpi::detail:: \
static constexpr auto const value = ::wpi::util::detail:: \
is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
}; \
} /* namespace detail2 */ \

View File

@@ -557,7 +557,7 @@ template<template <typename...> class Primary, typename... Args>
struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {};
template<typename T>
using is_json_pointer = is_specialization_of<::wpi::json_pointer, uncvref_t<T>>;
using is_json_pointer = is_specialization_of<::wpi::util::json_pointer, uncvref_t<T>>;
// checks if A and B are comparable using Compare functor
template<typename Compare, typename A, typename B, typename = void>

View File

@@ -828,7 +828,7 @@ class serializer
void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/)
{
auto* begin = number_buffer.data();
auto* end = ::wpi::detail::to_chars(begin, begin + number_buffer.size(), x);
auto* end = ::wpi::util::detail::to_chars(begin, begin + number_buffer.size(), x);
o->write_characters(begin, static_cast<size_t>(end - begin));
}

View File

@@ -95,74 +95,74 @@ The invariants are checked by member function assert_invariant().
*/
WPI_BASIC_JSON_TPL_DECLARATION
class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
: public ::wpi::detail::json_base_class<CustomBaseClass>
: public ::wpi::util::detail::json_base_class<CustomBaseClass>
{
private:
template<detail::value_t> friend struct detail::external_constructor;
template<typename>
friend class ::wpi::json_pointer;
friend class ::wpi::util::json_pointer;
// can be restored when json_pointer backwards compatibility is removed
// friend ::wpi::json_pointer<StringType>;
// friend ::wpi::util::json_pointer<StringType>;
template<typename BasicJsonType, typename InputType>
friend class ::wpi::detail::parser;
friend ::wpi::detail::serializer<basic_json>;
friend class ::wpi::util::detail::parser;
friend ::wpi::util::detail::serializer<basic_json>;
template<typename BasicJsonType>
friend class ::wpi::detail::iter_impl;
friend class ::wpi::util::detail::iter_impl;
template<typename BasicJsonType, typename CharType>
friend class ::wpi::detail::binary_writer;
friend class ::wpi::util::detail::binary_writer;
template<typename BasicJsonType, typename InputType, typename SAX>
friend class ::wpi::detail::binary_reader;
friend class ::wpi::util::detail::binary_reader;
template<typename BasicJsonType>
friend class ::wpi::detail::json_sax_dom_parser;
friend class ::wpi::util::detail::json_sax_dom_parser;
template<typename BasicJsonType>
friend class ::wpi::detail::json_sax_dom_callback_parser;
friend class ::wpi::detail::exception;
friend class ::wpi::util::detail::json_sax_dom_callback_parser;
friend class ::wpi::util::detail::exception;
/// workaround type for MSVC
using basic_json_t = WPI_BASIC_JSON_TPL;
using json_base_class_t = ::wpi::detail::json_base_class<CustomBaseClass>;
using json_base_class_t = ::wpi::util::detail::json_base_class<CustomBaseClass>;
JSON_PRIVATE_UNLESS_TESTED:
// convenience aliases for types residing in namespace detail;
using lexer = ::wpi::detail::lexer_base<basic_json>;
using lexer = ::wpi::util::detail::lexer_base<basic_json>;
template<typename InputAdapterType>
static ::wpi::detail::parser<basic_json, InputAdapterType> parser(
static ::wpi::util::detail::parser<basic_json, InputAdapterType> parser(
InputAdapterType adapter,
detail::parser_callback_t<basic_json>cb = nullptr,
const bool allow_exceptions = true,
const bool ignore_comments = false
)
{
return ::wpi::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
return ::wpi::util::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
std::move(cb), allow_exceptions, ignore_comments);
}
private:
using primitive_iterator_t = ::wpi::detail::primitive_iterator_t;
using primitive_iterator_t = ::wpi::util::detail::primitive_iterator_t;
template<typename BasicJsonType>
using internal_iterator = ::wpi::detail::internal_iterator<BasicJsonType>;
using internal_iterator = ::wpi::util::detail::internal_iterator<BasicJsonType>;
template<typename BasicJsonType>
using iter_impl = ::wpi::detail::iter_impl<BasicJsonType>;
using iter_impl = ::wpi::util::detail::iter_impl<BasicJsonType>;
template<typename Iterator>
using iteration_proxy = ::wpi::detail::iteration_proxy<Iterator>;
template<typename Base> using json_reverse_iterator = ::wpi::detail::json_reverse_iterator<Base>;
using iteration_proxy = ::wpi::util::detail::iteration_proxy<Iterator>;
template<typename Base> using json_reverse_iterator = ::wpi::util::detail::json_reverse_iterator<Base>;
template<typename CharType>
using output_adapter_t = ::wpi::detail::output_adapter_t<CharType>;
using output_adapter_t = ::wpi::util::detail::output_adapter_t<CharType>;
template<typename InputType>
using binary_reader = ::wpi::detail::binary_reader<basic_json, InputType>;
template<typename CharType> using binary_writer = ::wpi::detail::binary_writer<basic_json, CharType>;
using binary_reader = ::wpi::util::detail::binary_reader<basic_json, InputType>;
template<typename CharType> using binary_writer = ::wpi::util::detail::binary_writer<basic_json, CharType>;
public:
using serializer = ::wpi::detail::serializer<basic_json>;
using serializer = ::wpi::util::detail::serializer<basic_json>;
using value_t = detail::value_t;
/// JSON Pointer, see @ref json_pointer
using json_pointer = ::wpi::json_pointer<StringType>;
using json_pointer = ::wpi::util::json_pointer<StringType>;
template<typename T, typename SFINAE>
using json_serializer = JSONSerializer<T, SFINAE>;
/// how to treat decoding errors
@@ -173,7 +173,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>;
using input_format_t = detail::input_format_t;
/// SAX interface type, see wpi::json_sax
/// SAX interface type, see wpi::util::json_sax
using json_sax_t = json_sax<basic_json>;
////////////////
@@ -361,7 +361,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief a type for a packed binary type
/// @sa https://json.nlohmann.me/api/basic_json/binary_t/
using binary_t = wpi::byte_container_with_subtype<BinaryType>;
using binary_t = wpi::util::byte_container_with_subtype<BinaryType>;
/// @brief object key comparator type
/// @sa https://json.nlohmann.me/api/basic_json/object_comparator_t/
@@ -2370,8 +2370,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
detail::is_basic_json<BasicJsonType>::value
&& detail::is_getable<basic_json_t, ValueType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
ValueType value(const ::wpi::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::util::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
ValueType value(const ::wpi::util::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const
{
return value(ptr.convert(), default_value);
}
@@ -2381,8 +2381,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
detail::is_basic_json<BasicJsonType>::value
&& detail::is_getable<basic_json_t, ReturnType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
ReturnType value(const ::wpi::json_pointer<BasicJsonType>& ptr, ValueType && default_value) const
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::util::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
ReturnType value(const ::wpi::util::json_pointer<BasicJsonType>& ptr, ValueType && default_value) const
{
return value(ptr.convert(), std::forward<ValueType>(default_value));
}
@@ -2746,8 +2746,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
bool contains(const typename ::wpi::json_pointer<BasicJsonType>& ptr) const
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::util::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
bool contains(const typename ::wpi::util::json_pointer<BasicJsonType>& ptr) const
{
return ptr.contains(this);
}
@@ -4625,8 +4625,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
reference operator[](const ::wpi::json_pointer<BasicJsonType>& ptr)
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::util::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
reference operator[](const ::wpi::util::json_pointer<BasicJsonType>& ptr)
{
return ptr.get_unchecked(this);
}
@@ -4639,8 +4639,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
const_reference operator[](const ::wpi::json_pointer<BasicJsonType>& ptr) const
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::util::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
const_reference operator[](const ::wpi::util::json_pointer<BasicJsonType>& ptr) const
{
return ptr.get_unchecked(this);
}
@@ -4653,8 +4653,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
reference at(const ::wpi::json_pointer<BasicJsonType>& ptr)
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::util::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
reference at(const ::wpi::util::json_pointer<BasicJsonType>& ptr)
{
return ptr.get_checked(this);
}
@@ -4667,8 +4667,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
const_reference at(const ::wpi::json_pointer<BasicJsonType>& ptr) const
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or wpi::util::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
const_reference at(const ::wpi::util::json_pointer<BasicJsonType>& ptr) const
{
return ptr.get_checked(this);
}
@@ -5169,24 +5169,24 @@ inline namespace json_literals
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/
JSON_HEDLEY_NON_NULL(1)
#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
inline wpi::json operator ""_json(const char* s, std::size_t n)
inline wpi::util::json operator ""_json(const char* s, std::size_t n)
#else
inline wpi::json operator "" _json(const char* s, std::size_t n)
inline wpi::util::json operator "" _json(const char* s, std::size_t n)
#endif
{
return wpi::json::parse(s, s + n);
return wpi::util::json::parse(s, s + n);
}
/// @brief user-defined string literal for JSON pointer
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/
JSON_HEDLEY_NON_NULL(1)
#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
inline wpi::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n)
inline wpi::util::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n)
#else
inline wpi::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
inline wpi::util::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
#endif
{
return wpi::json::json_pointer(std::string(s, n));
return wpi::util::json::json_pointer(std::string(s, n));
}
} // namespace json_literals
@@ -5203,29 +5203,29 @@ namespace std // NOLINT(cert-dcl58-cpp)
/// @brief hash value for JSON objects
/// @sa https://json.nlohmann.me/api/basic_json/std_hash/
WPI_BASIC_JSON_TPL_DECLARATION
struct hash<wpi::WPI_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp)
struct hash<wpi::util::WPI_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp)
{
std::size_t operator()(const wpi::WPI_BASIC_JSON_TPL& j) const
std::size_t operator()(const wpi::util::WPI_BASIC_JSON_TPL& j) const
{
return wpi::detail::hash(j);
return wpi::util::detail::hash(j);
}
};
// specialization for std::less<value_t>
template<>
struct less< ::wpi::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679
struct less< ::wpi::util::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679
{
/*!
@brief compare two value_t enum values
@since version 3.0.0
*/
bool operator()(::wpi::detail::value_t lhs,
::wpi::detail::value_t rhs) const noexcept
bool operator()(::wpi::util::detail::value_t lhs,
::wpi::util::detail::value_t rhs) const noexcept
{
#if JSON_HAS_THREE_WAY_COMPARISON
return std::is_lt(lhs <=> rhs); // *NOPAD*
#else
return ::wpi::detail::operator<(lhs, rhs);
return ::wpi::util::detail::operator<(lhs, rhs);
#endif
}
};
@@ -5236,9 +5236,9 @@ struct less< ::wpi::detail::value_t> // do not remove the space after '<', see h
/// @brief exchanges the values of two JSON objects
/// @sa https://json.nlohmann.me/api/basic_json/std_swap/
WPI_BASIC_JSON_TPL_DECLARATION
inline void swap(wpi::WPI_BASIC_JSON_TPL& j1, wpi::WPI_BASIC_JSON_TPL& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp)
is_nothrow_move_constructible<wpi::WPI_BASIC_JSON_TPL>::value&& // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
is_nothrow_move_assignable<wpi::WPI_BASIC_JSON_TPL>::value)
inline void swap(wpi::util::WPI_BASIC_JSON_TPL& j1, wpi::util::WPI_BASIC_JSON_TPL& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp)
is_nothrow_move_constructible<wpi::util::WPI_BASIC_JSON_TPL>::value&& // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
is_nothrow_move_assignable<wpi::util::WPI_BASIC_JSON_TPL>::value)
{
j1.swap(j2);
}
@@ -5249,11 +5249,11 @@ inline void swap(wpi::WPI_BASIC_JSON_TPL& j1, wpi::WPI_BASIC_JSON_TPL& j2) noexc
#if JSON_USE_GLOBAL_UDLS
#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
using wpi::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using wpi::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using wpi::util::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using wpi::util::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
#else
using wpi::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using wpi::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using wpi::util::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using wpi::util::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
#endif
#endif

View File

@@ -68,7 +68,7 @@ struct ordered_map;
/// @brief specialization that maintains the insertion order of object keys
/// @sa https://json.nlohmann.me/api/ordered_json/
using ordered_json = basic_json<wpi::ordered_map>;
using ordered_json = basic_json<wpi::util::ordered_map>;
WPI_JSON_NAMESPACE_END

View File

@@ -23,7 +23,7 @@
WPI_JSON_NAMESPACE_BEGIN
/// ordered_map: a minimal map-like container that preserves insertion order
/// for use within wpi::basic_json<ordered_map>
/// for use within wpi::util::basic_json<ordered_map>
template <class Key, class T, class IgnoredLess = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>>
struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>

View File

@@ -100,7 +100,7 @@
ConvertUTF_DISABLE_WARNINGS
namespace wpi {
namespace wpi::util {
static const int halfShift = 10; /* used for shifting by 10 bits */
@@ -770,7 +770,7 @@ namespace sys {
namespace windows {
std::error_code CodePageToUTF16(unsigned codepage,
std::string_view original,
wpi::SmallVectorImpl<wchar_t> &utf16) {
wpi::util::SmallVectorImpl<wchar_t> &utf16) {
if (!original.empty()) {
int len = ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.data(),
original.size(), utf16.begin(), 0);
@@ -798,19 +798,19 @@ std::error_code CodePageToUTF16(unsigned codepage,
}
std::error_code UTF8ToUTF16(std::string_view utf8,
wpi::SmallVectorImpl<wchar_t> &utf16) {
wpi::util::SmallVectorImpl<wchar_t> &utf16) {
return CodePageToUTF16(CP_UTF8, utf8, utf16);
}
std::error_code CurCPToUTF16(std::string_view curcp,
wpi::SmallVectorImpl<wchar_t> &utf16) {
wpi::util::SmallVectorImpl<wchar_t> &utf16) {
return CodePageToUTF16(CP_ACP, curcp, utf16);
}
static
std::error_code UTF16ToCodePage(unsigned codepage, const wchar_t *utf16,
size_t utf16_len,
wpi::SmallVectorImpl<char> &converted) {
wpi::util::SmallVectorImpl<char> &converted) {
if (utf16_len) {
// Get length.
int len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, converted.begin(),
@@ -840,12 +840,12 @@ std::error_code UTF16ToCodePage(unsigned codepage, const wchar_t *utf16,
}
std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len,
wpi::SmallVectorImpl<char> &utf8) {
wpi::util::SmallVectorImpl<char> &utf8) {
return UTF16ToCodePage(CP_UTF8, utf16, utf16_len, utf8);
}
std::error_code UTF16ToCurCP(const wchar_t *utf16, size_t utf16_len,
wpi::SmallVectorImpl<char> &curcp) {
wpi::util::SmallVectorImpl<char> &curcp) {
return UTF16ToCodePage(CP_ACP, utf16, utf16_len, curcp);
}
@@ -854,6 +854,6 @@ std::error_code UTF16ToCurCP(const wchar_t *utf16, size_t utf16_len,
#endif // _WIN32
} // namespace wpi
} // namespace wpi::util
ConvertUTF_RESTORE_WARNINGS

View File

@@ -15,7 +15,7 @@
#include <string_view>
#include <vector>
namespace wpi {
namespace wpi::util {
bool ConvertUTF8toWide(unsigned WideCharWidth, std::string_view Source,
char *&ResultPtr, const UTF8 *&ErrorPtr) {
@@ -103,7 +103,7 @@ bool convertUTF16ToUTF8String(std::span<const char> SrcBytes, SmallVectorImpl<ch
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
for (UTF16 &I : ByteSwapped)
I = wpi::byteswap<uint16_t>(I);
I = wpi::util::byteswap<uint16_t>(I);
Src = &ByteSwapped[0];
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
}
@@ -161,7 +161,7 @@ bool convertUTF32ToUTF8String(std::span<const char> SrcBytes, std::string &Out)
if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_SWAPPED) {
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
for (UTF32 &I : ByteSwapped)
I = wpi::byteswap<uint32_t>(I);
I = wpi::util::byteswap<uint32_t>(I);
Src = &ByteSwapped[0];
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
}
@@ -305,5 +305,5 @@ bool convertWideToUTF8(const std::wstring &Source, SmallVectorImpl<char> &Result
}
}
} // end namespace wpi
} // end namespace wpi::util

View File

@@ -28,7 +28,7 @@
#include <io.h>
#endif
using namespace wpi;
using namespace wpi::util;
static fatal_error_handler_t ErrorHandler = nullptr;
static void *ErrorHandlerUserData = nullptr;
@@ -50,7 +50,7 @@ static void *BadAllocErrorHandlerUserData = nullptr;
static std::mutex ErrorHandlerMutex;
static std::mutex BadAllocErrorHandlerMutex;
void wpi::install_fatal_error_handler(fatal_error_handler_t handler,
void wpi::util::install_fatal_error_handler(fatal_error_handler_t handler,
void *user_data) {
std::scoped_lock Lock(ErrorHandlerMutex);
assert(!ErrorHandler && "Error handler already registered!\n");
@@ -58,22 +58,22 @@ void wpi::install_fatal_error_handler(fatal_error_handler_t handler,
ErrorHandlerUserData = user_data;
}
void wpi::remove_fatal_error_handler() {
void wpi::util::remove_fatal_error_handler() {
std::scoped_lock Lock(ErrorHandlerMutex);
ErrorHandler = nullptr;
ErrorHandlerUserData = nullptr;
}
void wpi::report_fatal_error(const char *Reason, bool GenCrashDiag) {
void wpi::util::report_fatal_error(const char *Reason, bool GenCrashDiag) {
report_fatal_error(std::string_view(Reason), GenCrashDiag);
}
void wpi::report_fatal_error(const std::string &Reason, bool GenCrashDiag) {
void wpi::util::report_fatal_error(const std::string &Reason, bool GenCrashDiag) {
report_fatal_error(std::string_view(Reason), GenCrashDiag);
}
void wpi::report_fatal_error(std::string_view Reason, bool GenCrashDiag) {
wpi::fatal_error_handler_t handler = nullptr;
void wpi::util::report_fatal_error(std::string_view Reason, bool GenCrashDiag) {
wpi::util::fatal_error_handler_t handler = nullptr;
void* handlerData = nullptr;
{
// Only acquire the mutex while reading the handler, so as not to invoke a
@@ -86,13 +86,13 @@ void wpi::report_fatal_error(std::string_view Reason, bool GenCrashDiag) {
if (handler) {
handler(handlerData, std::string{Reason}.c_str(), GenCrashDiag);
} else {
wpi::print(stderr, "LLVM ERROR: {}\n", Reason);
wpi::util::print(stderr, "LLVM ERROR: {}\n", Reason);
}
exit(1);
}
void wpi::install_bad_alloc_error_handler(fatal_error_handler_t handler,
void wpi::util::install_bad_alloc_error_handler(fatal_error_handler_t handler,
void *user_data) {
std::scoped_lock Lock(BadAllocErrorHandlerMutex);
assert(!BadAllocErrorHandler &&
@@ -101,13 +101,13 @@ void wpi::install_bad_alloc_error_handler(fatal_error_handler_t handler,
BadAllocErrorHandlerUserData = user_data;
}
void wpi::remove_bad_alloc_error_handler() {
void wpi::util::remove_bad_alloc_error_handler() {
std::scoped_lock Lock(BadAllocErrorHandlerMutex);
BadAllocErrorHandler = nullptr;
BadAllocErrorHandlerUserData = nullptr;
}
void wpi::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) {
void wpi::util::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) {
fatal_error_handler_t Handler = nullptr;
void *HandlerData = nullptr;
{
@@ -142,29 +142,29 @@ void wpi::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) {
// Causes crash on allocation failure. It is called prior to the handler set by
// 'install_bad_alloc_error_handler'.
static void out_of_memory_new_handler() {
wpi::report_bad_alloc_error("Allocation failed");
wpi::util::report_bad_alloc_error("Allocation failed");
}
// Installs new handler that causes crash on allocation failure. It is called by
// InitLLVM.
void wpi::install_out_of_memory_new_handler() {
void wpi::util::install_out_of_memory_new_handler() {
std::new_handler old = std::set_new_handler(out_of_memory_new_handler);
(void)old;
assert((old == nullptr || old == out_of_memory_new_handler) &&
"new-handler already installed");
}
void wpi::wpi_unreachable_internal(const char *msg, const char *file,
void wpi::util::wpi_unreachable_internal(const char *msg, const char *file,
unsigned line) {
// This code intentionally doesn't call the ErrorHandler callback, because
// wpi_unreachable is intended to be used to indicate "impossible"
// situations, and not legitimate runtime errors.
if (msg)
wpi::print(stderr, "{}\n", msg);
wpi::util::print(stderr, "{}\n", msg);
std::fputs("UNREACHABLE executed", stderr);
if (file)
wpi::print(stderr, " at {}:{}", file, line);
wpi::print(stderr, "!\n");
wpi::util::print(stderr, " at {}:{}", file, line);
wpi::util::print(stderr, "!\n");
abort();
#ifdef LLVM_BUILTIN_UNREACHABLE
// Windows systems and possibly others don't declare abort() to be noreturn,
@@ -184,7 +184,7 @@ void wpi::wpi_unreachable_internal(const char *msg, const char *file,
// This function obtains the last error code and maps it. It may call
// RtlGetLastNtStatus, which is a lower level API that can return a
// more specific error code than GetLastError.
std::error_code wpi::mapLastWindowsError() {
std::error_code wpi::util::mapLastWindowsError() {
unsigned EV = ::GetLastError();
return mapWindowsError(EV);
}
@@ -194,7 +194,7 @@ std::error_code wpi::mapLastWindowsError() {
case x: \
return std::make_error_code(std::errc::y)
std::error_code wpi::mapWindowsError(unsigned EV) {
std::error_code wpi::util::mapWindowsError(unsigned EV) {
switch (EV) {
MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied);
MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists);

View File

@@ -12,7 +12,7 @@
// These are out of line to have __cpp_aligned_new not affect ABI.
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
wpi::allocate_buffer(size_t Size, size_t Alignment) {
wpi::util::allocate_buffer(size_t Size, size_t Alignment) {
void *Result = ::operator new(Size,
#ifdef __cpp_aligned_new
std::align_val_t(Alignment),
@@ -24,7 +24,7 @@ wpi::allocate_buffer(size_t Size, size_t Alignment) {
return Result;
}
void wpi::deallocate_buffer(void *Ptr, size_t Size, size_t Alignment) {
void wpi::util::deallocate_buffer(void *Ptr, size_t Size, size_t Alignment) {
::operator delete(Ptr
#ifdef __cpp_sized_deallocation
,

View File

@@ -58,7 +58,7 @@
#include "wpi/util/WindowsError.hpp"
#endif
using namespace wpi;
using namespace wpi::util;
//===----------------------------------------------------------------------===//
// MemoryBuffer implementation itself.
@@ -259,12 +259,12 @@ static std::unique_ptr<WritableMemoryBuffer> GetMemoryBufferForStream(
return GetMemBufferCopyImpl(buffer, bufferName, ec);
}
wpi::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
wpi::util::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
MemoryBuffer::GetFile(std::string_view filename, int64_t fileSize) {
std::error_code ec;
auto ret = GetFileAux<MemoryBuffer>(filename, ec, fileSize, fileSize, 0);
if (ec) {
return wpi::unexpected{ec};
return wpi::util::unexpected{ec};
}
return ret;
}
@@ -362,7 +362,7 @@ static std::unique_ptr<WriteThroughMemoryBuffer> GetReadWriteFile(
LARGE_INTEGER fileSizeWin;
if (!GetFileSizeEx(f, &fileSizeWin)) {
ec = wpi::mapWindowsError(GetLastError());
ec = wpi::util::mapWindowsError(GetLastError());
return nullptr;
}
fileSize = fileSizeWin.QuadPart;

View File

@@ -19,7 +19,7 @@
#include <cassert>
#include <cstdlib>
using namespace wpi;
using namespace wpi::util;
void SmallPtrSetImplBase::shrink_and_clear() {
assert(!isSmall() && "Can't shrink a small set!");

View File

@@ -16,7 +16,7 @@
#ifdef LLVM_ENABLE_EXCEPTIONS
#include <stdexcept>
#endif
using namespace wpi;
using namespace wpi::util;
// Check that no bytes are wasted and everything is well-aligned.
namespace {
@@ -114,7 +114,7 @@ static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) {
/// situation does occur.
static void *replaceAllocation(void *NewElts, size_t TSize, size_t NewCapacity,
size_t VSize = 0) {
void *NewEltsReplace = wpi::safe_malloc(NewCapacity * TSize);
void *NewEltsReplace = wpi::util::safe_malloc(NewCapacity * TSize);
if (VSize)
memcpy(NewEltsReplace, NewElts, VSize * TSize);
free(NewElts);
@@ -128,7 +128,7 @@ void *SmallVectorBase::mallocForGrow(void *FirstEl, size_t MinSize,
NewCapacity = getNewCapacity(MinSize, TSize, this->capacity());
// Even if capacity is not 0 now, if the vector was originally created with
// capacity 0, it's possible for the malloc to return FirstEl.
void *NewElts = wpi::safe_malloc(NewCapacity * TSize);
void *NewElts = wpi::util::safe_malloc(NewCapacity * TSize);
if (NewElts == FirstEl)
NewElts = replaceAllocation(NewElts, TSize, NewCapacity);
return NewElts;
@@ -140,7 +140,7 @@ void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSize,
size_t NewCapacity = getNewCapacity(MinSize, TSize, this->capacity());
void *NewElts;
if (BeginX == FirstEl) {
NewElts = wpi::safe_malloc(NewCapacity * TSize);
NewElts = wpi::util::safe_malloc(NewCapacity * TSize);
if (NewElts == FirstEl)
NewElts = replaceAllocation(NewElts, TSize, NewCapacity);
@@ -148,7 +148,7 @@ void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSize,
memcpy(NewElts, this->BeginX, size() * TSize);
} else {
// If this wasn't grown from the inline copy, grow the allocated space.
NewElts = wpi::safe_realloc(this->BeginX, NewCapacity * TSize);
NewElts = wpi::util::safe_realloc(this->BeginX, NewCapacity * TSize);
if (NewElts == FirstEl)
NewElts = replaceAllocation(NewElts, TSize, NewCapacity, size());
}

View File

@@ -28,8 +28,8 @@
static int ascii_strncasecmp(const char* lhs, const char* rhs,
size_t length) noexcept {
for (size_t i = 0; i < length; ++i) {
unsigned char lhc = wpi::toLower(lhs[i]);
unsigned char rhc = wpi::toLower(rhs[i]);
unsigned char lhc = wpi::util::toLower(lhs[i]);
unsigned char rhc = wpi::util::toLower(rhs[i]);
if (lhc != rhc) {
return lhc < rhc ? -1 : 1;
}
@@ -37,7 +37,7 @@ static int ascii_strncasecmp(const char* lhs, const char* rhs,
return 0;
}
int wpi::compare_lower(std::string_view lhs, std::string_view rhs) noexcept {
int wpi::util::compare_lower(std::string_view lhs, std::string_view rhs) noexcept {
if (int Res = ascii_strncasecmp(lhs.data(), rhs.data(),
(std::min)(lhs.size(), rhs.size()))) {
return Res;
@@ -48,7 +48,7 @@ int wpi::compare_lower(std::string_view lhs, std::string_view rhs) noexcept {
return lhs.size() < rhs.size() ? -1 : 1;
}
std::string_view::size_type wpi::find_lower(
std::string_view::size_type wpi::util::find_lower(
std::string_view str, char ch, std::string_view::size_type from) noexcept {
char lch = toLower(ch);
auto s = drop_front(str, from);
@@ -61,7 +61,7 @@ std::string_view::size_type wpi::find_lower(
return std::string_view::npos;
}
std::string_view::size_type wpi::find_lower(
std::string_view::size_type wpi::util::find_lower(
std::string_view str, std::string_view other,
std::string_view::size_type from) noexcept {
auto s = substr(str, from);
@@ -75,7 +75,7 @@ std::string_view::size_type wpi::find_lower(
return std::string_view::npos;
}
std::string_view::size_type wpi::rfind_lower(
std::string_view::size_type wpi::util::rfind_lower(
std::string_view str, char ch, std::string_view::size_type from) noexcept {
from = (std::min)(from, str.size());
auto data = str.data();
@@ -89,7 +89,7 @@ std::string_view::size_type wpi::rfind_lower(
return std::string_view::npos;
}
std::string_view::size_type wpi::rfind_lower(std::string_view str,
std::string_view::size_type wpi::util::rfind_lower(std::string_view str,
std::string_view other) noexcept {
std::string_view::size_type n = other.size();
if (n > str.size()) {
@@ -104,13 +104,13 @@ std::string_view::size_type wpi::rfind_lower(std::string_view str,
return std::string_view::npos;
}
bool wpi::starts_with_lower(std::string_view str,
bool wpi::util::starts_with_lower(std::string_view str,
std::string_view prefix) noexcept {
return str.size() >= prefix.size() &&
ascii_strncasecmp(str.data(), prefix.data(), prefix.size()) == 0;
}
bool wpi::ends_with_lower(std::string_view str,
bool wpi::util::ends_with_lower(std::string_view str,
std::string_view suffix) noexcept {
return str.size() >= suffix.size() &&
ascii_strncasecmp(str.data() + str.size() - suffix.size(),
@@ -122,22 +122,22 @@ static unsigned GetAutoSenseRadix(std::string_view& str) noexcept {
return 10;
}
if (wpi::starts_with(str, "0x") || wpi::starts_with(str, "0X")) {
if (wpi::util::starts_with(str, "0x") || wpi::util::starts_with(str, "0X")) {
str.remove_prefix(2);
return 16;
}
if (wpi::starts_with(str, "0b") || wpi::starts_with(str, "0B")) {
if (wpi::util::starts_with(str, "0b") || wpi::util::starts_with(str, "0B")) {
str.remove_prefix(2);
return 2;
}
if (wpi::starts_with(str, "0o")) {
if (wpi::util::starts_with(str, "0o")) {
str.remove_prefix(2);
return 8;
}
if (str[0] == '0' && str.size() > 1 && wpi::isDigit(str[1])) {
if (str[0] == '0' && str.size() > 1 && wpi::util::isDigit(str[1])) {
str.remove_prefix(1);
return 8;
}
@@ -145,7 +145,7 @@ static unsigned GetAutoSenseRadix(std::string_view& str) noexcept {
return 10;
}
bool wpi::detail::ConsumeUnsignedInteger(
bool wpi::util::detail::ConsumeUnsignedInteger(
std::string_view& str, unsigned radix,
unsigned long long& result) noexcept { // NOLINT(runtime/int)
// Autosense radix if not specified.
@@ -201,14 +201,14 @@ bool wpi::detail::ConsumeUnsignedInteger(
return false;
}
bool wpi::detail::ConsumeSignedInteger(
bool wpi::util::detail::ConsumeSignedInteger(
std::string_view& str, unsigned radix,
long long& result) noexcept { // NOLINT(runtime/int)
unsigned long long ullVal; // NOLINT(runtime/int)
// Handle positive strings first.
if (str.empty() || str.front() != '-') {
if (wpi::detail::ConsumeUnsignedInteger(str, radix, ullVal) ||
if (wpi::util::detail::ConsumeUnsignedInteger(str, radix, ullVal) ||
// Check for value so large it overflows a signed value.
static_cast<long long>(ullVal) < 0) { // NOLINT(runtime/int)
return true;
@@ -218,8 +218,8 @@ bool wpi::detail::ConsumeSignedInteger(
}
// Get the positive part of the value.
std::string_view str2 = wpi::drop_front(str);
if (wpi::detail::ConsumeUnsignedInteger(str2, radix, ullVal) ||
std::string_view str2 = wpi::util::drop_front(str);
if (wpi::util::detail::ConsumeUnsignedInteger(str2, radix, ullVal) ||
// Reject values so large they'd overflow as negative signed, but allow
// "-0". This negates the unsigned so that the negative isn't undefined
// on signed overflow.
@@ -232,10 +232,10 @@ bool wpi::detail::ConsumeSignedInteger(
return false;
}
bool wpi::detail::GetAsUnsignedInteger(
bool wpi::util::detail::GetAsUnsignedInteger(
std::string_view str, unsigned radix,
unsigned long long& result) noexcept { // NOLINT(runtime/int)
if (wpi::detail::ConsumeUnsignedInteger(str, radix, result)) {
if (wpi::util::detail::ConsumeUnsignedInteger(str, radix, result)) {
return true;
}
@@ -244,10 +244,10 @@ bool wpi::detail::GetAsUnsignedInteger(
return !str.empty();
}
bool wpi::detail::GetAsSignedInteger(
bool wpi::util::detail::GetAsSignedInteger(
std::string_view str, unsigned radix,
long long& result) noexcept { // NOLINT(runtime/int)
if (wpi::detail::ConsumeSignedInteger(str, radix, result)) {
if (wpi::util::detail::ConsumeSignedInteger(str, radix, result)) {
return true;
}
@@ -257,11 +257,11 @@ bool wpi::detail::GetAsSignedInteger(
}
template <>
std::optional<float> wpi::parse_float<float>(std::string_view str) noexcept {
std::optional<float> wpi::util::parse_float<float>(std::string_view str) noexcept {
if (str.empty()) {
return std::nullopt;
}
wpi::SmallString<32> storage{str};
wpi::util::SmallString<32> storage{str};
char* end;
float val = std::strtof(storage.c_str(), &end);
if (*end != '\0') {
@@ -271,11 +271,11 @@ std::optional<float> wpi::parse_float<float>(std::string_view str) noexcept {
}
template <>
std::optional<double> wpi::parse_float<double>(std::string_view str) noexcept {
std::optional<double> wpi::util::parse_float<double>(std::string_view str) noexcept {
if (str.empty()) {
return std::nullopt;
}
wpi::SmallString<32> storage{str};
wpi::util::SmallString<32> storage{str};
char* end;
double val = std::strtod(storage.c_str(), &end);
if (*end != '\0') {
@@ -285,12 +285,12 @@ std::optional<double> wpi::parse_float<double>(std::string_view str) noexcept {
}
template <>
std::optional<long double> wpi::parse_float<long double>(
std::optional<long double> wpi::util::parse_float<long double>(
std::string_view str) noexcept {
if (str.empty()) {
return std::nullopt;
}
wpi::SmallString<32> storage{str};
wpi::util::SmallString<32> storage{str};
char* end;
long double val = std::strtold(storage.c_str(), &end);
if (*end != '\0') {
@@ -299,8 +299,8 @@ std::optional<long double> wpi::parse_float<long double>(
return val;
}
std::pair<std::string_view, std::string_view> wpi::UnescapeCString(
std::string_view str, wpi::SmallVectorImpl<char>& buf) {
std::pair<std::string_view, std::string_view> wpi::util::UnescapeCString(
std::string_view str, wpi::util::SmallVectorImpl<char>& buf) {
buf.clear();
buf.reserve(str.size());
const char* s = str.data();
@@ -338,10 +338,10 @@ std::pair<std::string_view, std::string_view> wpi::UnescapeCString(
buf.push_back('x'); // treat it like a unknown escape
break;
}
unsigned int ch = wpi::hexDigitValue(*++s);
unsigned int ch = wpi::util::hexDigitValue(*++s);
if ((s + 1) < end && std::isxdigit(*(s + 1))) {
ch <<= 4;
ch |= wpi::hexDigitValue(*++s);
ch |= wpi::util::hexDigitValue(*++s);
}
buf.push_back(static_cast<char>(ch));
break;
@@ -358,11 +358,11 @@ std::pair<std::string_view, std::string_view> wpi::UnescapeCString(
case '9': {
// octal escape
unsigned int ch = *s - '0';
if ((s + 1) < end && wpi::isDigit(*(s + 1))) {
if ((s + 1) < end && wpi::util::isDigit(*(s + 1))) {
ch <<= 3;
ch |= *++s - '0';
}
if ((s + 1) < end && wpi::isDigit(*(s + 1))) {
if ((s + 1) < end && wpi::util::isDigit(*(s + 1))) {
ch <<= 3;
ch |= *++s - '0';
}

View File

@@ -49,13 +49,13 @@
// Must be included after windows.h
#include <wincrypt.h>
namespace wpi {
namespace wpi::util {
/// Returns the Windows version as Major.Minor.0.BuildNumber. Uses
/// RtlGetVersion or GetVersionEx under the hood depending on what is available.
/// GetVersionEx is deprecated, but this API exposes the build number which can
/// be useful for working around certain kernel bugs.
inline wpi::VersionTuple GetWindowsOSVersion() {
inline wpi::util::VersionTuple GetWindowsOSVersion() {
typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
if (hMod) {
@@ -64,12 +64,12 @@ inline wpi::VersionTuple GetWindowsOSVersion() {
RTL_OSVERSIONINFOEXW info{};
info.dwOSVersionInfoSize = sizeof(info);
if (getVer((PRTL_OSVERSIONINFOW)&info) == ((NTSTATUS)0x00000000L)) {
return wpi::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0,
return wpi::util::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0,
info.dwBuildNumber);
}
}
}
return wpi::VersionTuple(0, 0, 0, 0);
return wpi::util::VersionTuple(0, 0, 0, 0);
}
/// Determines if the program is running on Windows 8 or newer. This
@@ -78,7 +78,7 @@ inline wpi::VersionTuple GetWindowsOSVersion() {
/// yet have VersionHelpers.h, so we have our own helper.
inline bool RunningWindows8OrGreater() {
// Windows 8 is version 6.2, service pack 0.
return GetWindowsOSVersion() >= wpi::VersionTuple(6, 2, 0, 0);
return GetWindowsOSVersion() >= wpi::util::VersionTuple(6, 2, 0, 0);
}
/// Determines if the program is running on Windows 11 or Windows Server 2022.
@@ -88,7 +88,7 @@ bool RunningWindows11OrGreater();
/// RtlGetVersion or GetVersionEx under the hood depending on what is available.
/// GetVersionEx is deprecated, but this API exposes the build number which can
/// be useful for working around certain kernel bugs.
wpi::VersionTuple GetWindowsOSVersion();
wpi::util::VersionTuple GetWindowsOSVersion();
bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix);
@@ -96,7 +96,7 @@ bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix);
[[noreturn]] inline void ReportLastErrorFatal(const char *Msg) {
std::string ErrMsg;
MakeErrMsg(&ErrMsg, Msg);
wpi::report_fatal_error(ErrMsg);
wpi::util::report_fatal_error(ErrMsg);
}
template <typename HandleTraits>
@@ -256,6 +256,6 @@ inline FILETIME toFILETIME(TimePoint<> TP) {
}
} // end namespace sys
} // end namespace wpi.
} // end namespace wpi::util.
#endif

View File

@@ -12,7 +12,7 @@
#include "wpi/util/raw_os_ostream.hpp"
#include <ostream>
using namespace wpi;
using namespace wpi::util;
//===----------------------------------------------------------------------===//
// raw_os_ostream

View File

@@ -57,7 +57,7 @@
#include "Windows/WindowsSupport.hpp"
#endif
using namespace wpi;
using namespace wpi::util;
constexpr raw_ostream::Colors raw_ostream::BLACK;
constexpr raw_ostream::Colors raw_ostream::RED;
@@ -593,7 +593,7 @@ void raw_fd_ostream::anchor() {}
// outs(), errs(), nulls()
//===----------------------------------------------------------------------===//
raw_fd_ostream &wpi::outs() {
raw_fd_ostream &wpi::util::outs() {
// Set buffer settings to model stdout behavior.
std::error_code EC;
static raw_fd_ostream* S = new raw_fd_ostream("-", EC, fs::OF_None);
@@ -601,14 +601,14 @@ raw_fd_ostream &wpi::outs() {
return *S;
}
raw_fd_ostream &wpi::errs() {
raw_fd_ostream &wpi::util::errs() {
// Set standard error to be unbuffered and tied to outs() by default.
static raw_fd_ostream* S = new raw_fd_ostream(STDERR_FILENO, false, true);
return *S;
}
/// nulls() - This returns a reference to a raw_ostream which discards output.
raw_ostream &wpi::nulls() {
raw_ostream &wpi::util::nulls() {
static raw_null_ostream S;
return S;
}

View File

@@ -13,7 +13,7 @@
#include <iterator>
#include <utility>
namespace wpi {
namespace wpi::util {
// Only used by compiler if both template types are the same. Useful when
// using SFINAE to test for the existence of member functions.
@@ -130,6 +130,6 @@ using ValueOfRange =
std::remove_reference_t<decltype(*adl_begin(std::declval<RangeT &>()))>;
} // namespace detail
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_ADL_H

View File

@@ -16,7 +16,7 @@
#include <algorithm>
#include <cstddef>
namespace wpi {
namespace wpi::util {
/// A suitably aligned and sized character array member which can hold elements
/// of any type.
@@ -25,6 +25,6 @@ template <typename... Ts> struct AlignedCharArrayUnion {
std::byte buffer[(std::max)({static_cast<size_t>(1), sizeof(Ts)...})];
};
} // end namespace wpi
} // end namespace wpi::util
#endif // WPIUTIL_WPI_ALIGNOF_H

View File

@@ -29,7 +29,7 @@
#include "wpi/util/MemAlloc.hpp"
#include <type_traits>
namespace wpi {
namespace wpi::util {
/// CRTP base class providing obvious overloads for the core \c
/// Allocate() methods of LLVM-style allocators.
@@ -127,6 +127,6 @@ public:
} // namespace detail
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_ALLOCATORBASE_H

View File

@@ -21,7 +21,7 @@
#include <optional>
#include <type_traits>
namespace wpi {
namespace wpi::util {
//===----------------------------------------------------------------------===//
// simplify_type
@@ -806,7 +806,7 @@ template <class X, class Y>
//===----------------------------------------------------------------------===//
/// These are wrappers over isa* function that allow them to be used in generic
/// algorithms such as `wpi:all_of`, `wpi::none_of`, etc. This is accomplished
/// algorithms such as `wpi:all_of`, `wpi::util::none_of`, etc. This is accomplished
/// by exposing the isa* functions through function objects with a generic
/// function call operator.
@@ -824,29 +824,29 @@ template <typename... Types> struct IsaAndPresentCheckPredicate {
};
} // namespace detail
/// Function object wrapper for the `wpi::isa` type check. The function call
/// Function object wrapper for the `wpi::util::isa` type check. The function call
/// operator returns true when the value can be cast to any type in `Types`.
/// Example:
/// ```
/// SmallVector<Type> myTypes = ...;
/// if (wpi::all_of(myTypes, wpi::IsaPred<VectorType>))
/// if (wpi::util::all_of(myTypes, wpi::util::IsaPred<VectorType>))
/// ...
/// ```
template <typename... Types>
inline constexpr detail::IsaCheckPredicate<Types...> IsaPred{};
/// Function object wrapper for the `wpi::isa_and_present` type check. The
/// Function object wrapper for the `wpi::util::isa_and_present` type check. The
/// function call operator returns true when the value can be cast to any type
/// in `Types`, or if the value is not present (e.g., nullptr). Example:
/// ```
/// SmallVector<Type> myTypes = ...;
/// if (wpi::all_of(myTypes, wpi::IsaAndPresentPred<VectorType>))
/// if (wpi::util::all_of(myTypes, wpi::util::IsaAndPresentPred<VectorType>))
/// ...
/// ```
template <typename... Types>
inline constexpr detail::IsaAndPresentCheckPredicate<Types...>
IsaAndPresentPred{};
} // end namespace wpi
} // end namespace wpi::util
#endif // WPIUTIL_WPI_CASTING_H

View File

@@ -15,7 +15,7 @@
#include <ctime>
#include <ratio>
namespace wpi {
namespace wpi::util {
class raw_ostream;
@@ -79,6 +79,6 @@ toTimePoint(std::time_t T, uint32_t nsec) {
raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP);
raw_ostream &operator<<(raw_ostream &OS, sys::UtcTime<> TP);
} // namespace wpi
} // namespace wpi::util
#endif // WPIUTIL_WPI_CHRONO_H

View File

@@ -111,10 +111,10 @@
#include <string_view>
#include <system_error>
// Wrap everything in namespace wpi so that programs can link with llvm and
// Wrap everything in namespace wpi::util so that programs can link with llvm and
// their own version of the unicode libraries.
namespace wpi {
namespace wpi::util {
/* ---------------------------------------------------------------------
The following 4 definitions are compiler-specific.
@@ -340,6 +340,6 @@ std::error_code UTF16ToCurCP(const wchar_t *utf16, size_t utf16_len,
} // namespace sys
#endif
} /* end namespace wpi */
} /* end namespace wpi::util */
#endif

View File

@@ -33,7 +33,7 @@
#include <type_traits>
#include <utility>
namespace wpi {
namespace wpi::util {
namespace detail {
@@ -53,7 +53,7 @@ struct DenseMapPair : public std::pair<KeyT, ValueT> {
template <typename KeyT, typename ValueT,
typename KeyInfoT = DenseMapInfo<KeyT>,
typename Bucket = wpi::detail::DenseMapPair<KeyT, ValueT>,
typename Bucket = wpi::util::detail::DenseMapPair<KeyT, ValueT>,
bool IsConst = false>
class DenseMapIterator;
@@ -723,7 +723,7 @@ bool operator!=(
template <typename KeyT, typename ValueT,
typename KeyInfoT = DenseMapInfo<KeyT>,
typename BucketT = wpi::detail::DenseMapPair<KeyT, ValueT>>
typename BucketT = wpi::util::detail::DenseMapPair<KeyT, ValueT>>
class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
KeyT, ValueT, KeyInfoT, BucketT> {
friend class DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
@@ -877,7 +877,7 @@ private:
template <typename KeyT, typename ValueT, unsigned InlineBuckets = 4,
typename KeyInfoT = DenseMapInfo<KeyT>,
typename BucketT = wpi::detail::DenseMapPair<KeyT, ValueT>>
typename BucketT = wpi::util::detail::DenseMapPair<KeyT, ValueT>>
class SmallDenseMap
: public DenseMapBase<
SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
@@ -1303,6 +1303,6 @@ inline size_t capacity_in_bytes(const DenseMap<KeyT, ValueT, KeyInfoT> &X) {
return X.getMemorySize();
}
} // end namespace wpi
} // end namespace wpi::util
#endif // WPIUTIL_WPI_DENSEMAP_H

View File

@@ -21,7 +21,7 @@
#include <type_traits>
#include <utility>
namespace wpi {
namespace wpi::util {
namespace densemap::detail {
// A bit mixer with very low latency using one multiplications and one
@@ -320,6 +320,6 @@ struct DenseMapInfo<Enum, std::enable_if_t<std::is_enum_v<Enum>>> {
static bool isEqual(const Enum &LHS, const Enum &RHS) { return LHS == RHS; }
};
} // end namespace wpi
} // end namespace wpi::util
#endif // WPIUTIL_WPI_DENSEMAPINFO_H

View File

@@ -18,7 +18,7 @@
#include <utility>
#include <variant>
namespace wpi {
namespace wpi::util {
// Provide DenseMapInfo for variants whose all alternatives have DenseMapInfo.
template <typename... Ts> struct DenseMapInfo<std::variant<Ts...>> {
@@ -66,6 +66,6 @@ template <typename... Ts> struct DenseMapInfo<std::variant<Ts...>> {
}
};
} // end namespace wpi
} // end namespace wpi::util
#endif // WPIUTIL_WPI_DENSEMAPINFOVARIANT_H

Some files were not shown because too many files have changed in this diff Show More