#ifndef COMPONENTS_ESM_ESMBRIDGE #define COMPONENTS_ESM_ESMBRIDGE #include #include #include #include #include namespace ESM4 { struct Cell; } namespace ESM { struct Cell; struct CellId; struct RefId; 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 auto visit(F&& f, T&&... v); }; struct ReferenceVariant { std::variant mVariant; explicit ReferenceVariant(const ESM4::Reference& ref) : mVariant(ref) { } explicit ReferenceVariant(const ESM::CellRef& ref) : mVariant(ref) { } bool isESM4() const { return std::holds_alternative(mVariant); } const ESM::CellRef& getEsm3() const { return std::get(mVariant); } const ESM4::Reference& getEsm4() const { return std::get(mVariant); } ESM::CellRef& getEsm3() { return std::get(mVariant); } ESM4::Reference& getEsm4() { return std::get(mVariant); } }; template auto 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