Compare commits

...

2 Commits

Author SHA1 Message Date
Nik
43afbfa120 includes/type: Made size and float16 types more generic 2022-10-09 17:38:05 +02:00
Nik
f75703fd2b includes/std: Added MagicSearch and Reinterpreter helper type 2022-10-09 17:37:37 +02:00
3 changed files with 34 additions and 10 deletions

View File

@@ -47,4 +47,26 @@ namespace std::mem {
return builtin::std::mem::read_string(address, size);
};
struct MagicSearch<auto Magic, T> {
if ($ < (std::mem::size() - std::string::length(Magic) - 1)) {
char __potentialMagic__[std::string::length(Magic)] [[hidden, no_unique_address]];
if (__potentialMagic__ == Magic) {
T data [[inline]];
} else {
padding[1];
continue;
}
} else {
padding[1];
continue;
}
};
union Reinterpreter<From, To> {
From from;
To to;
};
}

View File

@@ -2,6 +2,7 @@
#include <std/io.pat>
#include <std/math.pat>
#include <std/mem.pat>
namespace type {
@@ -41,10 +42,10 @@ namespace type {
result = (sign << 31) | ((exponent + (0x7F - 15)) << 23) | (mantissa << 13);
}
U32ToFloatConverter converter;
converter.intValue = result;
std::mem::Reinterpreter<u32, float> converter;
converter.from = result;
return std::format("{}", converter.floatValue);
return std::format("{}", converter.to);
};
}

View File

@@ -1,13 +1,14 @@
#pragma once
#include <std/io.pat>
namespace type {
using Size8 = u8 [[format("type::impl::size_formatter")]];
using Size16 = u16 [[format("type::impl::size_formatter")]];
using Size32 = u32 [[format("type::impl::size_formatter")]];
using Size64 = u64 [[format("type::impl::size_formatter")]];
using Size128 = u128 [[format("type::impl::size_formatter")]];
using Size<T> = T [[format("type::impl::size_formatter")]];
using Size8 = Size<u8>;
using Size16 = Size<u16>;
using Size32 = Size<u32>;
using Size64 = Size<u64>;
using Size128 = Size<u128>;
namespace impl {
@@ -45,4 +46,4 @@ namespace type {
}
}
}