parent
89ae226b1d
commit
ee63a4a1e4
src/olympic/keel
@ -197,22 +197,17 @@ class ConverterFunc final: public BaseConverter {
|
||||
class Converter {
|
||||
private:
|
||||
ox::AllocAlias<BaseConverter> m_buff{};
|
||||
BaseConverter *m_conv{};
|
||||
public:
|
||||
template<auto Func>
|
||||
static Converter make() noexcept {
|
||||
Converter out;
|
||||
static_assert(sizeof(ConverterFunc<Func>) <= sizeof(out.m_buff));
|
||||
out.m_conv = new (out.m_buff.data()) ConverterFunc<Func>{};
|
||||
new (out.m_buff.data()) ConverterFunc<Func>{};
|
||||
return out;
|
||||
}
|
||||
constexpr Converter() {}
|
||||
Converter(Converter const &other) noexcept:
|
||||
m_buff{other.m_buff},
|
||||
m_conv{m_buff.data()} {}
|
||||
[[nodiscard]]
|
||||
BaseConverter const *converter() const noexcept {
|
||||
return m_conv;
|
||||
BaseConverter const &converter() const noexcept {
|
||||
return *m_buff.data();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -15,8 +15,8 @@ static ox::Result<BaseConverter const*> findConverter(
|
||||
ox::StringViewCR dstTypeName,
|
||||
int const dstTypeVersion) noexcept {
|
||||
for (auto const&c : converters) {
|
||||
if (c.converter()->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||
return c.converter();
|
||||
if (c.converter().matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||
return &c.converter();
|
||||
}
|
||||
}
|
||||
return ox::Error{1, "Could not find converter"};
|
||||
@ -46,14 +46,14 @@ static ox::Result<ox::UPtr<Wrap>> convert(
|
||||
}
|
||||
// try to chain multiple converters
|
||||
for (auto const&subConverter : converters) {
|
||||
if (!subConverter.converter()->dstMatches(dstTypeName, dstTypeVersion)) {
|
||||
if (!subConverter.converter().dstMatches(dstTypeName, dstTypeVersion)) {
|
||||
continue;
|
||||
}
|
||||
const auto [intermediate, chainErr] =
|
||||
convert(ctx, converters, src, srcTypeName, srcTypeVersion,
|
||||
subConverter.converter()->srcTypeName(), subConverter.converter()->srcTypeVersion());
|
||||
subConverter.converter().srcTypeName(), subConverter.converter().srcTypeVersion());
|
||||
if (!chainErr) {
|
||||
return subConverter.converter()->convertPtrToPtr(ctx, *intermediate);
|
||||
return subConverter.converter().convertPtrToPtr(ctx, *intermediate);
|
||||
}
|
||||
}
|
||||
return ox::Error{1, "Could not convert between types"};
|
||||
|
Loading…
x
Reference in New Issue
Block a user