#ifndef NETGEN_REGISTER_ARCHIVE_HPP #define NETGEN_REGISTER_ARCHIVE_HPP #ifdef NETGEN_PYTHON #include #include #endif // NETGEN_PYTHON #include "archive.hpp" namespace ngcore { template class RegisterClassForArchive { public: RegisterClassForArchive() { static_assert(detail::all_of_tmpl::value...>, "Variadic template arguments must be base classes of T"); detail::ClassArchiveInfo info {}; info.creator = [](const std::type_info& ti) -> void* { return typeid(T) == ti ? detail::constructIfPossible() : Archive::Caster::tryUpcast(ti, detail::constructIfPossible()); }; info.upcaster = [/*this*/](const std::type_info& ti, void* p) -> void* { return typeid(T) == ti ? p : Archive::Caster::tryUpcast(ti, static_cast(p)); }; info.downcaster = [/*this*/](const std::type_info& ti, void* p) -> void* { return typeid(T) == ti ? p : Archive::Caster::tryDowncast(ti, p); }; #ifdef NETGEN_PYTHON info.anyToPyCaster = [](const std::any& a) { const T* val = std::any_cast(&a); return pybind11::cast(val); }; #endif // NETGEN_PYTHON Archive::SetArchiveRegister(std::string(Demangle(typeid(T).name())),info); } }; } // namespace ngcore #endif // NETGEN_REGISTER_ARCHIVE_HPP