function-pointer instead of std::function, no unique-ptr around type_register

This commit is contained in:
Joachim Schoeberl 2024-01-09 10:01:11 +01:00
parent 8362349bb8
commit fda7cfa2bc
2 changed files with 12 additions and 11 deletions

View File

@ -10,24 +10,24 @@
namespace ngcore
{
// clang-tidy should ignore this static object
static std::unique_ptr<std::map<std::string, detail::ClassArchiveInfo>> type_register; // NOLINT
static std::map<std::string, detail::ClassArchiveInfo> type_register; // NOLINT
const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return (*type_register)[classname];
// if(type_register == nullptr) type_register =
// std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return (type_register)[classname];
}
void Archive :: SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
(*type_register)[classname] = info;
// if(type_register == nullptr) type_register =
// std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
(type_register)[classname] = info;
}
bool Archive :: IsRegistered(const std::string& classname)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return type_register->count(classname) != 0;
// if(type_register == nullptr) type_register =
// std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return type_register.count(classname) != 0;
}
#ifdef NETGEN_PYTHON

View File

@ -150,7 +150,8 @@ namespace ngcore
void* (*downcaster)(const std::type_info&, void*);
// Archive constructor arguments
std::function<void(Archive&, void*)> cargs_archiver;
// std::function<void(Archive&, void*)> cargs_archiver;
void (*cargs_archiver)(Archive&, void*);
#ifdef NETGEN_PYTHON
// std::function<pybind11::object(const std::any&)> anyToPyCaster;