2018-12-08 20:10:29 +05:00
|
|
|
|
|
|
|
#include "archive.hpp"
|
2021-09-29 01:34:11 +05:00
|
|
|
#include "register_archive.hpp"
|
2020-07-23 22:04:21 +05:00
|
|
|
#include "version.hpp"
|
2018-12-08 20:10:29 +05:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <cxxabi.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace ngcore
|
|
|
|
{
|
|
|
|
// clang-tidy should ignore this static object
|
2024-01-09 14:21:06 +05:00
|
|
|
// static std::map<std::string, detail::ClassArchiveInfo> type_register; // NOLINT
|
|
|
|
|
|
|
|
auto& GetTypeRegister()
|
|
|
|
{
|
|
|
|
static std::map<std::string, detail::ClassArchiveInfo> type_register;
|
|
|
|
return type_register;
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:05:17 +05:00
|
|
|
const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname)
|
2018-12-08 20:10:29 +05:00
|
|
|
{
|
2024-01-09 14:01:11 +05:00
|
|
|
// if(type_register == nullptr) type_register =
|
|
|
|
// std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
|
2024-01-09 14:21:06 +05:00
|
|
|
return GetTypeRegister()[classname];
|
2018-12-08 20:10:29 +05:00
|
|
|
}
|
2018-12-12 15:05:17 +05:00
|
|
|
void Archive :: SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info)
|
2018-12-08 20:10:29 +05:00
|
|
|
{
|
2024-01-09 14:01:11 +05:00
|
|
|
// if(type_register == nullptr) type_register =
|
|
|
|
// std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
|
2024-01-09 14:21:06 +05:00
|
|
|
GetTypeRegister()[classname] = info;
|
2018-12-08 20:10:29 +05:00
|
|
|
}
|
|
|
|
bool Archive :: IsRegistered(const std::string& classname)
|
|
|
|
{
|
2024-01-09 14:01:11 +05:00
|
|
|
// if(type_register == nullptr) type_register =
|
|
|
|
// std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
|
2024-01-09 14:21:06 +05:00
|
|
|
return GetTypeRegister().count(classname) != 0;
|
2018-12-08 20:10:29 +05:00
|
|
|
}
|
2021-09-29 01:34:11 +05:00
|
|
|
|
|
|
|
#ifdef NETGEN_PYTHON
|
|
|
|
pybind11::object CastAnyToPy(const std::any& a)
|
|
|
|
{
|
|
|
|
auto info = Archive::GetArchiveRegister(Demangle(a.type().name()));
|
|
|
|
return info.anyToPyCaster(a);
|
|
|
|
}
|
|
|
|
#endif // NETGEN_PYTHON
|
|
|
|
|
2018-12-08 20:10:29 +05:00
|
|
|
} // namespace ngcore
|