#ifndef COMPONENTS_ESM_ESMBRIDGE #define COMPONENTS_ESM_ESMBRIDGE #include #include #include #include #include #include namespace ESM4 { struct Cell; } namespace ESM { struct Cell; class RefId; class CellVariant; template using Substitute = T; template using VisitReturnType = std::enable_if_t<(std::is_base_of_v> && ...), typename std::invoke_result...>::type>; class CellVariant { protected: std::variant mVariant; public: explicit CellVariant(const ESM4::Cell& cell) : mVariant(&cell) { } explicit CellVariant(const ESM::Cell& cell) : mVariant(&cell) { } bool isEsm4() const { return std::holds_alternative(mVariant); } const ESM4::Cell& getEsm4() const; const ESM::Cell& getEsm3() const; template friend VisitReturnType visit(F&& f, T&&... v); }; struct ReferenceVariant { std::variant mVariant; explicit ReferenceVariant(const ESM4::Reference& ref) : mVariant(ref) { } explicit ReferenceVariant(const ESM4::ActorCharacter& ref) : mVariant(ref) { } explicit ReferenceVariant(const ESM::CellRef& ref) : mVariant(ref) { } }; template VisitReturnType visit(F&& f, T&&... v) { return std::visit([&](auto*... ptr) { return std::forward(f)(*ptr...); }, std::forward(v).mVariant...); } template struct VisitOverload : Ts... { using Ts::operator()...; }; template VisitOverload(Ts...) -> VisitOverload; } #endif