[ox/preloader] Cleanup
This commit is contained in:
parent
1767821161
commit
317e714373
@ -15,7 +15,7 @@ namespace ox {
|
||||
|
||||
template<typename PlatSpec, typename T>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t alignOf(const T &t) noexcept;
|
||||
constexpr std::size_t alignOf(const T &v) noexcept;
|
||||
|
||||
template<typename PlatSpec, typename T>
|
||||
[[nodiscard]]
|
||||
@ -36,7 +36,7 @@ struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>> {
|
||||
|
||||
template<typename T>
|
||||
constexpr ox::Error field(CRStringView, const T *val) noexcept {
|
||||
if constexpr(ox::is_integer_v<T>) {
|
||||
if constexpr(ox::is_pointer_v<T> || ox::is_integer_v<T>) {
|
||||
biggestAlignment = ox::max(biggestAlignment, PlatSpec::alignOf(*val));
|
||||
} else {
|
||||
biggestAlignment = ox::max(biggestAlignment, alignOf<PlatSpec>(*val));
|
||||
|
21
deps/ox/src/ox/preloader/platspecs.hpp
vendored
21
deps/ox/src/ox/preloader/platspecs.hpp
vendored
@ -21,11 +21,12 @@ struct NativePlatSpec {
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]]
|
||||
static constexpr auto alignOf(const T &v) noexcept {
|
||||
static constexpr std::size_t alignOf(const T &v) noexcept {
|
||||
if constexpr(ox::is_integral_v<T>) {
|
||||
return alignof(T);
|
||||
} else if constexpr(ox::is_pointer_v<T>) {
|
||||
return PtrAlign;
|
||||
PtrType p = 0;
|
||||
return alignOf(p);
|
||||
} else {
|
||||
AlignmentCatcher<NativePlatSpec> c;
|
||||
oxAssert(model(c.interface(), &v), "Could not get alignment for type");
|
||||
@ -41,11 +42,17 @@ struct NativePlatSpec {
|
||||
|
||||
template<typename PlatSpec, typename T>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t alignOf(const T &t) noexcept {
|
||||
return PlatSpec::alignOf(t);
|
||||
constexpr std::size_t alignOf(const T &v) noexcept {
|
||||
if constexpr(ox::is_integral_v<T>) {
|
||||
return alignof(T);
|
||||
} else if constexpr(ox::is_pointer_v<T>) {
|
||||
typename PlatSpec::PtrType p = 0;
|
||||
return PlatSpec::alignOf(p);
|
||||
} else {
|
||||
AlignmentCatcher<NativePlatSpec> c;
|
||||
oxAssert(model(c.interface(), &v), "Could not get alignment for type");
|
||||
return c.biggestAlignment;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename PlatSpec, typename T>
|
||||
constexpr auto alignOf_v = alignOf<PlatSpec>(static_cast<T*>(nullptr));
|
||||
|
||||
}
|
||||
|
4
deps/ox/src/ox/preloader/preloader.hpp
vendored
4
deps/ox/src/ox/preloader/preloader.hpp
vendored
@ -33,6 +33,7 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>> {
|
||||
|
||||
private:
|
||||
using PtrType = typename PlatSpec::PtrType;
|
||||
static constexpr auto PtrSize = sizeof(PtrType);
|
||||
class UnionIdxTracker {
|
||||
private:
|
||||
int m_unionIdx = -1;
|
||||
@ -165,6 +166,7 @@ constexpr ox::Error Preloader<PlatSpec>::field(CRStringView name, const T *val)
|
||||
}
|
||||
oxReturnError(pad(val));
|
||||
if constexpr(ox::is_integral_v<T>) {
|
||||
//oxDebugf("Preloader::field(name, val): {}", name);
|
||||
return ox::serialize(&m_writer, PlatSpec::correctEndianness(*val));
|
||||
} else if constexpr(ox::is_pointer_v<T>) {
|
||||
const PtrType a = startAlloc(sizeOf<PlatSpec>(*val), m_writer.tellp()) + PlatSpec::RomStart;
|
||||
@ -336,7 +338,7 @@ constexpr ox::Error Preloader<PlatSpec>::fieldVector(CRStringView, const auto *v
|
||||
}
|
||||
// serialize the Vector
|
||||
oxReturnError(serialize(&m_writer, vecVal));
|
||||
m_ptrs.emplace_back(m_writer.tellp() - PlatSpec::PtrSize, vecVal.items);
|
||||
m_ptrs.emplace_back(m_writer.tellp() - PtrSize, vecVal.items);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user