|
|
|
@@ -51,27 +51,27 @@ constexpr T &wrapCast(Wrap &ptr) noexcept {
|
|
|
|
|
|
|
|
|
|
class BaseConverter {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~BaseConverter() noexcept = default;
|
|
|
|
|
constexpr virtual ~BaseConverter() noexcept = default;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
virtual ox::StringView srcTypeName() const noexcept = 0;
|
|
|
|
|
constexpr virtual ox::StringView srcTypeName() const noexcept = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
virtual int srcTypeVersion() const noexcept = 0;
|
|
|
|
|
constexpr virtual int srcTypeVersion() const noexcept = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
virtual bool srcMatches(ox::CRStringView pSrcTypeName, int pSrcTypeVersion) const noexcept = 0;
|
|
|
|
|
constexpr virtual bool srcMatches(ox::CRStringView pSrcTypeName, int pSrcTypeVersion) const noexcept = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0;
|
|
|
|
|
constexpr virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0;
|
|
|
|
|
|
|
|
|
|
virtual ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0;
|
|
|
|
|
|
|
|
|
|
virtual ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
|
|
|
|
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept = 0;
|
|
|
|
|
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
inline bool matches(
|
|
|
|
|
constexpr bool matches(
|
|
|
|
|
ox::CRStringView srcTypeName, int srcTypeVersion,
|
|
|
|
|
ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept {
|
|
|
|
|
return srcMatches(srcTypeName, srcTypeVersion)
|
|
|
|
@@ -84,17 +84,17 @@ template<typename SrcType, typename DstType>
|
|
|
|
|
class Converter: public BaseConverter {
|
|
|
|
|
public:
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
ox::StringView srcTypeName() const noexcept final {
|
|
|
|
|
constexpr ox::StringView srcTypeName() const noexcept final {
|
|
|
|
|
return ox::ModelTypeName_v<SrcType>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
int srcTypeVersion() const noexcept final {
|
|
|
|
|
constexpr int srcTypeVersion() const noexcept final {
|
|
|
|
|
return ox::ModelTypeVersion_v<SrcType>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
bool srcMatches(ox::CRStringView pSrcTypeName, int pSrcTypeVersion) const noexcept final {
|
|
|
|
|
constexpr bool srcMatches(ox::CRStringView pSrcTypeName, int pSrcTypeVersion) const noexcept final {
|
|
|
|
|
constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
|
|
|
|
|
constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
|
|
|
|
|
return pSrcTypeName == SrcTypeName
|
|
|
|
@@ -102,8 +102,8 @@ class Converter: public BaseConverter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept final {
|
|
|
|
|
constexpr auto DstTypeName = ox::StringView(ox::requireModelTypeName<DstType>());
|
|
|
|
|
constexpr bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept final {
|
|
|
|
|
constexpr auto DstTypeName = ox::StringView{ox::requireModelTypeName<DstType>()};
|
|
|
|
|
constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
|
|
|
|
return dstTypeName == DstTypeName
|
|
|
|
|
&& dstTypeVersion == DstTypeVersion;
|
|
|
|
@@ -117,8 +117,9 @@ class Converter: public BaseConverter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
|
|
|
|
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept final {
|
|
|
|
|
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
|
|
|
|
|
oxRequireM(src, readAsset<SrcType>(srcBuff));
|
|
|
|
|
oxReturnError(ensureValid(src));
|
|
|
|
|
auto dst = makeWrap<DstType>();
|
|
|
|
|
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
|
|
|
|
|
return {std::move(dst)};
|
|
|
|
@@ -131,12 +132,12 @@ class Converter: public BaseConverter {
|
|
|
|
|
|
|
|
|
|
ox::Result<ox::UPtr<Wrap>> convert(
|
|
|
|
|
keel::Context &ctx,
|
|
|
|
|
ox::Buffer const&srcBuffer,
|
|
|
|
|
ox::BufferView const&srcBuffer,
|
|
|
|
|
ox::CRStringView dstTypeName,
|
|
|
|
|
int dstTypeVersion) noexcept;
|
|
|
|
|
|
|
|
|
|
template<typename DstType>
|
|
|
|
|
ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noexcept {
|
|
|
|
|
ox::Result<DstType> convert(keel::Context &ctx, ox::BufferView const&srcBuffer) noexcept {
|
|
|
|
|
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
|
|
|
|
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
|
|
|
|
oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
|
|
|
@@ -144,7 +145,7 @@ ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename DstType>
|
|
|
|
|
ox::Error convert(keel::Context &ctx, ox::Buffer const&buff, DstType *outObj) noexcept {
|
|
|
|
|
ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType *outObj) noexcept {
|
|
|
|
|
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
|
|
|
|
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
|
|
|
|
oxRequire(outPtr, convert(ctx, buff, DstTypeName, DstTypeVersion));
|
|
|
|
@@ -154,7 +155,7 @@ ox::Error convert(keel::Context &ctx, ox::Buffer const&buff, DstType *outObj) no
|
|
|
|
|
|
|
|
|
|
template<typename DstType>
|
|
|
|
|
ox::Result<ox::Buffer> convertBuffToBuff(
|
|
|
|
|
keel::Context &ctx, ox::Buffer const&srcBuffer, ox::ClawFormat fmt) noexcept {
|
|
|
|
|
keel::Context &ctx, ox::BufferView const&srcBuffer, ox::ClawFormat fmt) noexcept {
|
|
|
|
|
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
|
|
|
|
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
|
|
|
|
oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
|
|
|
|