/* * Copyright 2015 - 2025 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include #include #include #include "optype.hpp" namespace ox { namespace detail { template class FieldCounter { public: std::size_t fields = 0; template constexpr ox::Error setTypeInfo(StringViewCR = "", int = 0, const Vector& = {}, std::size_t = 0) { return {}; } template constexpr ox::Error field(StringViewCR, U) noexcept { ++fields; return {}; } template constexpr ox::Error field(StringViewCR, U, std::size_t) noexcept { ++fields; return {}; } template constexpr Error field(StringViewCR, Handler) { ++fields; return {}; } template constexpr Error fieldCString(Args&&...) noexcept { ++fields; return {}; } static constexpr auto opType() noexcept { return OpType::Reflect; } }; } namespace detail { template [[nodiscard]] consteval auto modelFieldCount() noexcept { auto a = std::allocator(); auto t = a.allocate(1); detail::FieldCounter c; const auto err = model(&c, t); oxAssert(err, "Count failed"); a.deallocate(t, 1); return c.fields; } } template constexpr auto ModelFieldCount_v = detail::modelFieldCount(); }