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