[ox/std] Remove oxRequireT and oxRequireMT
This commit is contained in:
parent
abf7548ab5
commit
ab5bc1adb6
10
deps/ox/ox-docs.md
vendored
10
deps/ox/ox-docs.md
vendored
@ -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``` also has variants for throwing the error and for making to value non-const:
|
||||
|
||||
* ```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.
|
||||
```oxRequire``` by default creates a const, but there is also an ```oxRequireM``` (oxRequire Mutable)
|
||||
variant for creating a non-const value.
|
||||
|
||||
### Logging and Output
|
||||
|
||||
|
28
deps/ox/src/ox/logconn/logconn.cpp
vendored
28
deps/ox/src/ox/logconn/logconn.cpp
vendored
@ -9,8 +9,8 @@
|
||||
#ifdef OX_USE_STDLIB
|
||||
#include <cstdio>
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifndef _WIN32
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
@ -25,15 +25,22 @@
|
||||
|
||||
#include "logconn.hpp"
|
||||
|
||||
#include <ox/std/bit.hpp>
|
||||
|
||||
namespace ox {
|
||||
|
||||
#ifdef _WIN32
|
||||
using Socket = SOCKET;
|
||||
using LenType = int;
|
||||
#else
|
||||
using Socket = int;
|
||||
using LenType = size_t;
|
||||
#endif
|
||||
|
||||
using namespace trace;
|
||||
|
||||
void closeSock(auto s) noexcept {
|
||||
static void closeSock(auto s) noexcept {
|
||||
#ifdef _WIN32
|
||||
closesocket(s);
|
||||
closesocket(static_cast<Socket>(s));
|
||||
#else
|
||||
close(s);
|
||||
#endif
|
||||
@ -56,8 +63,8 @@ ox::Error LoggerConn::initConn(ox::StringViewCR appName) noexcept {
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
addr.sin_port = htons(5590);
|
||||
m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
oxReturnError(OxError(static_cast<ox::ErrorCode>(connect(m_socket, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))));
|
||||
m_socket = static_cast<int>(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
|
||||
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)});
|
||||
}
|
||||
|
||||
@ -65,9 +72,9 @@ ox::Error LoggerConn::send(const char *buff, std::size_t len) const noexcept {
|
||||
std::size_t totalSent = 0;
|
||||
while (totalSent < len) {
|
||||
//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) {
|
||||
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");
|
||||
}
|
||||
totalSent += static_cast<std::size_t>(sent);
|
||||
@ -90,13 +97,14 @@ void LoggerConn::msgSend() noexcept {
|
||||
if (!m_running) {
|
||||
break;
|
||||
}
|
||||
std::lock_guard buffLk(m_buffMut);
|
||||
std::lock_guard const buffLk(m_buffMut);
|
||||
while (true) {
|
||||
ox::Array<char, ox::units::KB> tmp;
|
||||
Array<char, units::KB> tmp;
|
||||
const auto read = m_buff.read(tmp.data(), tmp.size());
|
||||
if (!read) {
|
||||
break;
|
||||
}
|
||||
oxAssert(read <= tmp.size(), "logger trying to read too much data");
|
||||
//std::printf("LoggerConn: sending %lu bytes\n", read);
|
||||
std::ignore = send(tmp.data(), read);
|
||||
}
|
||||
|
4
deps/ox/src/ox/std/def.hpp
vendored
4
deps/ox/src/ox/std/def.hpp
vendored
@ -44,10 +44,6 @@
|
||||
// oxRequire Mutable
|
||||
#define oxRequireM(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__))
|
||||
#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
|
||||
|
24
deps/ox/src/ox/std/trace.cpp
vendored
24
deps/ox/src/ox/std/trace.cpp
vendored
@ -10,6 +10,17 @@
|
||||
|
||||
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() {
|
||||
oxTraceInitHook();
|
||||
}
|
||||
@ -19,19 +30,6 @@ void init(Logger *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 {
|
||||
trace::logger = logger;
|
||||
}
|
||||
|
4
deps/ox/src/ox/std/uuid.hpp
vendored
4
deps/ox/src/ox/std/uuid.hpp
vendored
@ -107,12 +107,12 @@ class UUID {
|
||||
static ox::Result<UUID> generate() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto const&value() const noexcept {
|
||||
constexpr ox::Array<uint8_t, 16> const&value() const noexcept {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto isNull() const noexcept {
|
||||
constexpr bool isNull() const noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
if (ox::all_of(m_value.begin(), m_value.end(), [](auto v) { return v == 0; })) {
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user