This commit is contained in:
		@@ -115,7 +115,7 @@ class BaseConverter {
 | 
				
			|||||||
		virtual ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) 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(
 | 
							virtual ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
 | 
				
			||||||
				keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0;
 | 
									Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[[nodiscard]]
 | 
							[[nodiscard]]
 | 
				
			||||||
		constexpr bool matches(
 | 
							constexpr bool matches(
 | 
				
			||||||
@@ -129,7 +129,7 @@ class BaseConverter {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<auto Func>
 | 
					template<auto Func>
 | 
				
			||||||
class ConverterFunc: public BaseConverter {
 | 
					class ConverterFunc final: public BaseConverter {
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		template<typename SrcType, typename DstType>
 | 
							template<typename SrcType, typename DstType>
 | 
				
			||||||
		struct ParamPack {
 | 
							struct ParamPack {
 | 
				
			||||||
@@ -137,8 +137,8 @@ class ConverterFunc: public BaseConverter {
 | 
				
			|||||||
			using Dst = DstType;
 | 
								using Dst = DstType;
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		template<typename S, typename D>
 | 
							template<typename Src, typename Dst>
 | 
				
			||||||
		static ParamPack<S, D> extractParams(ox::Error (*)(Context&, S&, D&)) {
 | 
							static ParamPack<Src, Dst> extractParams(ox::Error (*)(Context&, Src&, Dst&)) {
 | 
				
			||||||
			return {};
 | 
								return {};
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -147,17 +147,17 @@ class ConverterFunc: public BaseConverter {
 | 
				
			|||||||
		using DstType = typename decltype(extractParams(Func))::Dst;
 | 
							using DstType = typename decltype(extractParams(Func))::Dst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[[nodiscard]]
 | 
							[[nodiscard]]
 | 
				
			||||||
		constexpr ox::StringView srcTypeName() const noexcept final {
 | 
							constexpr ox::StringView srcTypeName() const noexcept override {
 | 
				
			||||||
			return ox::ModelTypeName_v<SrcType>;
 | 
								return ox::ModelTypeName_v<SrcType>;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[[nodiscard]]
 | 
							[[nodiscard]]
 | 
				
			||||||
		constexpr int srcTypeVersion() const noexcept final {
 | 
							constexpr int srcTypeVersion() const noexcept override {
 | 
				
			||||||
			return ox::ModelTypeVersion_v<SrcType>;
 | 
								return ox::ModelTypeVersion_v<SrcType>;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[[nodiscard]]
 | 
							[[nodiscard]]
 | 
				
			||||||
		constexpr bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept final {
 | 
							constexpr bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept override {
 | 
				
			||||||
			constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
 | 
								constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
 | 
				
			||||||
			constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
 | 
								constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
 | 
				
			||||||
			return pSrcTypeName == SrcTypeName
 | 
								return pSrcTypeName == SrcTypeName
 | 
				
			||||||
@@ -165,7 +165,7 @@ class ConverterFunc: public BaseConverter {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[[nodiscard]]
 | 
							[[nodiscard]]
 | 
				
			||||||
		constexpr bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept final {
 | 
							constexpr bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept override {
 | 
				
			||||||
			constexpr auto DstTypeName = ox::StringView{ox::requireModelTypeName<DstType>()};
 | 
								constexpr auto DstTypeName = ox::StringView{ox::requireModelTypeName<DstType>()};
 | 
				
			||||||
			constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
 | 
								constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
 | 
				
			||||||
			return dstTypeName == DstTypeName
 | 
								return dstTypeName == DstTypeName
 | 
				
			||||||
@@ -173,14 +173,14 @@ class ConverterFunc: public BaseConverter {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
 | 
							ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
 | 
				
			||||||
				keel::Context &ctx, Wrap &src) const noexcept final {
 | 
									Context &ctx, Wrap &src) const noexcept override {
 | 
				
			||||||
			ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
 | 
								ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
 | 
				
			||||||
			OX_RETURN_ERROR(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst.value)));
 | 
								OX_RETURN_ERROR(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst.value)));
 | 
				
			||||||
			return dst;
 | 
								return dst;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
 | 
							ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
 | 
				
			||||||
				keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
 | 
									Context &ctx, ox::BufferView const&srcBuff) const noexcept override {
 | 
				
			||||||
			OX_REQUIRE_M(src, readAsset<SrcType>(srcBuff));
 | 
								OX_REQUIRE_M(src, readAsset<SrcType>(srcBuff));
 | 
				
			||||||
			ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
 | 
								ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
 | 
				
			||||||
			OX_RETURN_ERROR(convert(ctx, src, wrapCast<DstType>(*dst.value)));
 | 
								OX_RETURN_ERROR(convert(ctx, src, wrapCast<DstType>(*dst.value)));
 | 
				
			||||||
@@ -188,7 +188,7 @@ class ConverterFunc: public BaseConverter {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		ox::Error convert(keel::Context &ctx, SrcType &src, DstType &dst) const noexcept {
 | 
							static ox::Error convert(Context &ctx, SrcType &src, DstType &dst) noexcept {
 | 
				
			||||||
			return Func(ctx, src, dst);
 | 
								return Func(ctx, src, dst);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -200,14 +200,14 @@ class Converter {
 | 
				
			|||||||
		BaseConverter *m_conv{};
 | 
							BaseConverter *m_conv{};
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		template<auto Func>
 | 
							template<auto Func>
 | 
				
			||||||
		static Converter make() {
 | 
							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>{};
 | 
								out.m_conv = new (out.m_buff.data()) ConverterFunc<Func>{};
 | 
				
			||||||
			return out;
 | 
								return out;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		constexpr Converter() {}
 | 
							constexpr Converter() {}
 | 
				
			||||||
		Converter(Converter const &other):
 | 
							Converter(Converter const &other) noexcept:
 | 
				
			||||||
			m_buff{other.m_buff},
 | 
								m_buff{other.m_buff},
 | 
				
			||||||
			m_conv{m_buff.data()} {}
 | 
								m_conv{m_buff.data()} {}
 | 
				
			||||||
		[[nodiscard]]
 | 
							[[nodiscard]]
 | 
				
			||||||
@@ -256,20 +256,20 @@ ox::Result<DstType> convertObjToObj(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename DstType>
 | 
					template<typename DstType>
 | 
				
			||||||
ox::Result<DstType> convert(keel::Context &ctx, ox::BufferView const&src) noexcept {
 | 
					ox::Result<DstType> convert(Context &ctx, ox::BufferView const&src) noexcept {
 | 
				
			||||||
	OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
						OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
				
			||||||
	return std::move(wrapCast<DstType>(out));
 | 
						return std::move(wrapCast<DstType>(out));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename DstType>
 | 
					template<typename DstType>
 | 
				
			||||||
ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType &outObj) noexcept {
 | 
					ox::Error convert(Context &ctx, ox::BufferView const&buff, DstType &outObj) noexcept {
 | 
				
			||||||
	OX_REQUIRE(out, convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
						OX_REQUIRE(out, convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
				
			||||||
	outObj = std::move(wrapCast<DstType>(*out));
 | 
						outObj = std::move(wrapCast<DstType>(*out));
 | 
				
			||||||
	return {};
 | 
						return {};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename DstType>
 | 
					template<typename DstType>
 | 
				
			||||||
ox::Error convertObjToObj(keel::Context &ctx, auto &src, DstType &outObj) noexcept {
 | 
					ox::Error convertObjToObj(Context &ctx, auto &src, DstType &outObj) noexcept {
 | 
				
			||||||
	OX_REQUIRE(outPtr, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
						OX_REQUIRE(outPtr, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
				
			||||||
	outObj = std::move(wrapCast<DstType>(*outPtr));
 | 
						outObj = std::move(wrapCast<DstType>(*outPtr));
 | 
				
			||||||
	return {};
 | 
						return {};
 | 
				
			||||||
@@ -277,13 +277,13 @@ ox::Error convertObjToObj(keel::Context &ctx, auto &src, DstType &outObj) noexce
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
template<typename DstType>
 | 
					template<typename DstType>
 | 
				
			||||||
ox::Result<ox::Buffer> convertBuffToBuff(
 | 
					ox::Result<ox::Buffer> convertBuffToBuff(
 | 
				
			||||||
		keel::Context &ctx, ox::BufferView const&src, ox::ClawFormat const fmt) noexcept {
 | 
							Context &ctx, ox::BufferView const&src, ox::ClawFormat const fmt) noexcept {
 | 
				
			||||||
	OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
						OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
 | 
				
			||||||
	return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
 | 
						return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
 | 
					template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
 | 
				
			||||||
ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) noexcept {
 | 
					ox::Result<bool> transformRule(Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) noexcept {
 | 
				
			||||||
	if (typeId == ox::ModelTypeId_v<From>) {
 | 
						if (typeId == ox::ModelTypeId_v<From>) {
 | 
				
			||||||
		OX_RETURN_ERROR(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
 | 
							OX_RETURN_ERROR(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user