netgen/libsrc/core/archive.cpp
2018-12-08 16:10:29 +01:00

58 lines
2.1 KiB
C++

#include "archive.hpp"
#ifndef WIN32
#include <cxxabi.h>
#endif
namespace ngcore
{
void VersionInfo :: DoArchive(Archive& ar)
{
ar & mayor_ & minor_ & release & patch & git_hash;
}
// clang-tidy should ignore this static object
static std::map<std::string, VersionInfo> library_versions; // NOLINT
std::map<std::string, VersionInfo>& Archive :: GetLibraryVersions()
{
return library_versions;
}
const VersionInfo& GetLibraryVersion(const std::string& library)
{ return library_versions[library]; }
void SetLibraryVersion(const std::string& library, const VersionInfo& version)
{ library_versions[library] = version; }
#ifdef WIN
// windows does demangling in typeid(T).name()
std::string demangle(const char* typeinfo) { return typeinfo; }
#else
std::string demangle(const char* typeinfo) { int status; return abi::__cxa_demangle(typeinfo,
nullptr,
nullptr,
&status); }
#endif
// clang-tidy should ignore this static object
static std::unique_ptr<std::map<std::string, ClassArchiveInfo>> type_register; // NOLINT
const ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, ClassArchiveInfo>>();
return (*type_register)[classname];
}
void Archive :: SetArchiveRegister(const std::string& classname, const ClassArchiveInfo& info)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, 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, ClassArchiveInfo>>();
return type_register->count(classname) != 0;
}
} // namespace ngcore