[ox/std] Remove oxRequireT and oxRequireMT

This commit is contained in:
Gary Talent 2024-10-06 06:16:14 -05:00
parent abf7548ab5
commit ab5bc1adb6
5 changed files with 33 additions and 37 deletions

10
deps/ox/ox-docs.md vendored
View File

@ -176,14 +176,8 @@ ox::Result<int> f2() noexcept {
``` ```
```oxRequire``` is not quite as versatile, but it should still cleanup a lot of otherwise less ideal code. ```oxRequire``` is not quite as versatile, but it should still cleanup a lot of otherwise less ideal code.
```oxRequire``` also has variants for throwing the error and for making to value non-const: ```oxRequire``` by default creates a const, but there is also an ```oxRequireM``` (oxRequire Mutable)
variant for creating a non-const value.
* ```oxRequireM``` - oxRequire Mutable
* ```oxRequireT``` - oxRequire Throw
* ```oxRequireMT``` - oxRequire Mutable Throw
The throw variants of ```oxRequire``` are generally legacy code.
```ox::Result::unwrapThrow``` is generally preferred now.
### Logging and Output ### Logging and Output

View File

@ -9,8 +9,8 @@
#ifdef OX_USE_STDLIB #ifdef OX_USE_STDLIB
#include <cstdio> #include <cstdio>
#include <sys/types.h>
#ifndef _WIN32 #ifndef _WIN32
#include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -25,15 +25,22 @@
#include "logconn.hpp" #include "logconn.hpp"
#include <ox/std/bit.hpp>
namespace ox { namespace ox {
#ifdef _WIN32
using Socket = SOCKET;
using LenType = int;
#else
using Socket = int;
using LenType = size_t;
#endif
using namespace trace; using namespace trace;
void closeSock(auto s) noexcept { static void closeSock(auto s) noexcept {
#ifdef _WIN32 #ifdef _WIN32
closesocket(s); closesocket(static_cast<Socket>(s));
#else #else
close(s); close(s);
#endif #endif
@ -56,8 +63,8 @@ ox::Error LoggerConn::initConn(ox::StringViewCR appName) noexcept {
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(5590); addr.sin_port = htons(5590);
m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); m_socket = static_cast<int>(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
oxReturnError(OxError(static_cast<ox::ErrorCode>(connect(m_socket, reinterpret_cast<sockaddr*>(&addr), sizeof(addr))))); oxReturnError(OxError(static_cast<ox::ErrorCode>(connect(static_cast<Socket>(m_socket), reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))));
return sendInit({.appName = ox::BasicString<128>(appName)}); return sendInit({.appName = ox::BasicString<128>(appName)});
} }
@ -65,9 +72,9 @@ ox::Error LoggerConn::send(const char *buff, std::size_t len) const noexcept {
std::size_t totalSent = 0; std::size_t totalSent = 0;
while (totalSent < len) { while (totalSent < len) {
//std::fprintf(stdout, "Sending %lu/%lu bytes on socket %d\n", len, totalSent, m_socket); //std::fprintf(stdout, "Sending %lu/%lu bytes on socket %d\n", len, totalSent, m_socket);
const auto sent = ::send(m_socket, buff, len, 0); const auto sent = ::send(static_cast<Socket>(m_socket), buff, static_cast<LenType>(len), 0);
if (sent < 0) { if (sent < 0) {
std::fprintf(stderr, "Could not send msg\n"); std::ignore = std::fprintf(stderr, "Could not send msg\n");
return OxError(1, "Could not send msg"); return OxError(1, "Could not send msg");
} }
totalSent += static_cast<std::size_t>(sent); totalSent += static_cast<std::size_t>(sent);
@ -90,13 +97,14 @@ void LoggerConn::msgSend() noexcept {
if (!m_running) { if (!m_running) {
break; break;
} }
std::lock_guard buffLk(m_buffMut); std::lock_guard const buffLk(m_buffMut);
while (true) { while (true) {
ox::Array<char, ox::units::KB> tmp; Array<char, units::KB> tmp;
const auto read = m_buff.read(tmp.data(), tmp.size()); const auto read = m_buff.read(tmp.data(), tmp.size());
if (!read) { if (!read) {
break; break;
} }
oxAssert(read <= tmp.size(), "logger trying to read too much data");
//std::printf("LoggerConn: sending %lu bytes\n", read); //std::printf("LoggerConn: sending %lu bytes\n", read);
std::ignore = send(tmp.data(), read); std::ignore = send(tmp.data(), read);
} }

View File

@ -44,10 +44,6 @@
// oxRequire Mutable // oxRequire Mutable
#define oxRequireM(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__)) #define oxRequireM(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__))
#define oxRequire(out, x) const oxRequireM(out, x) #define oxRequire(out, x) const oxRequireM(out, x)
// oxRequire Mutable Throw
#define oxRequireMT(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxThrowError(oxConcat(oxRequire_err_, __LINE__))
// oxRequire Throw
#define oxRequireT(out, x) const oxRequireMT(out, x)
// Asserts // Asserts

View File

@ -10,6 +10,17 @@
namespace ox::trace { namespace ox::trace {
static class: public Logger {
public:
ox::Error send(const TraceMsg&) noexcept final {
return {};
}
ox::Error sendInit(const InitTraceMsg&) noexcept final {
return {};
}
} defaultLogger;
static Logger *logger = &defaultLogger;
void init() { void init() {
oxTraceInitHook(); oxTraceInitHook();
} }
@ -19,19 +30,6 @@ void init(Logger *logger) {
setLogger(logger); setLogger(logger);
} }
class NullLogger: public Logger {
public:
ox::Error send(const TraceMsg&) noexcept final {
return {};
}
ox::Error sendInit(const InitTraceMsg&) noexcept final {
return {};
}
};
static NullLogger defaultLogger;
static Logger *logger = &defaultLogger;
void setLogger(Logger *logger) noexcept { void setLogger(Logger *logger) noexcept {
trace::logger = logger; trace::logger = logger;
} }

View File

@ -107,12 +107,12 @@ class UUID {
static ox::Result<UUID> generate() noexcept; static ox::Result<UUID> generate() noexcept;
[[nodiscard]] [[nodiscard]]
constexpr auto const&value() const noexcept { constexpr ox::Array<uint8_t, 16> const&value() const noexcept {
return m_value; return m_value;
} }
[[nodiscard]] [[nodiscard]]
constexpr auto isNull() const noexcept { constexpr bool isNull() const noexcept {
if (std::is_constant_evaluated()) { if (std::is_constant_evaluated()) {
if (ox::all_of(m_value.begin(), m_value.end(), [](auto v) { return v == 0; })) { if (ox::all_of(m_value.begin(), m_value.end(), [](auto v) { return v == 0; })) {
return true; return true;