mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
Set version of Netgen globally (for archives), interface to get version
This commit is contained in:
parent
6989bde831
commit
f73159e35a
@ -11,6 +11,7 @@ add_library(ngcore SHARED
|
|||||||
table.cpp
|
table.cpp
|
||||||
taskmanager.cpp
|
taskmanager.cpp
|
||||||
utils.cpp
|
utils.cpp
|
||||||
|
version.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Pybind11 2.3 Issue https://github.com/pybind/pybind11/issues/1604
|
# Pybind11 2.3 Issue https://github.com/pybind/pybind11/issues/1604
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#include "archive.hpp"
|
#include "archive.hpp"
|
||||||
#include <netgen_version.hpp>
|
#include "version.hpp"
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
@ -8,18 +8,6 @@
|
|||||||
|
|
||||||
namespace ngcore
|
namespace ngcore
|
||||||
{
|
{
|
||||||
// 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; }
|
|
||||||
|
|
||||||
// clang-tidy should ignore this static object
|
// clang-tidy should ignore this static object
|
||||||
static std::unique_ptr<std::map<std::string, detail::ClassArchiveInfo>> type_register; // NOLINT
|
static std::unique_ptr<std::map<std::string, detail::ClassArchiveInfo>> type_register; // NOLINT
|
||||||
const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname)
|
const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname)
|
||||||
@ -45,10 +33,4 @@ namespace ngcore
|
|||||||
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
|
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
|
||||||
return type_register->count(classname) != 0;
|
return type_register->count(classname) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool dummy = [](){
|
|
||||||
SetLibraryVersion("netgen", NETGEN_VERSION);
|
|
||||||
return true;
|
|
||||||
}();
|
|
||||||
} // namespace ngcore
|
} // namespace ngcore
|
||||||
|
@ -30,9 +30,6 @@ namespace pybind11
|
|||||||
|
|
||||||
namespace ngcore
|
namespace ngcore
|
||||||
{
|
{
|
||||||
// Libraries using this archive can store their version here to implement backwards compatibility
|
|
||||||
NGCORE_API const VersionInfo& GetLibraryVersion(const std::string& library);
|
|
||||||
NGCORE_API void SetLibraryVersion(const std::string& library, const VersionInfo& version);
|
|
||||||
|
|
||||||
class NGCORE_API Archive;
|
class NGCORE_API Archive;
|
||||||
|
|
||||||
@ -570,9 +567,6 @@ namespace ngcore
|
|||||||
|
|
||||||
virtual void FlushBuffer() {}
|
virtual void FlushBuffer() {}
|
||||||
|
|
||||||
protected:
|
|
||||||
static std::map<std::string, VersionInfo>& GetLibraryVersions();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T, typename ... Bases>
|
template<typename T, typename ... Bases>
|
||||||
friend class RegisterClassForArchive;
|
friend class RegisterClassForArchive;
|
||||||
|
@ -230,7 +230,6 @@ namespace ngcore
|
|||||||
using ARCHIVE::stream;
|
using ARCHIVE::stream;
|
||||||
using ARCHIVE::version_map;
|
using ARCHIVE::version_map;
|
||||||
using ARCHIVE::logger;
|
using ARCHIVE::logger;
|
||||||
using ARCHIVE::GetLibraryVersions;
|
|
||||||
public:
|
public:
|
||||||
PyArchive(const pybind11::object& alst = pybind11::none()) :
|
PyArchive(const pybind11::object& alst = pybind11::none()) :
|
||||||
ARCHIVE(std::make_shared<std::stringstream>()),
|
ARCHIVE(std::make_shared<std::stringstream>()),
|
||||||
@ -275,10 +274,11 @@ namespace ngcore
|
|||||||
|
|
||||||
pybind11::list WriteOut()
|
pybind11::list WriteOut()
|
||||||
{
|
{
|
||||||
|
auto version_runtime = GetLibraryVersions();
|
||||||
FlushBuffer();
|
FlushBuffer();
|
||||||
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
||||||
stream = std::make_shared<std::stringstream>();
|
stream = std::make_shared<std::stringstream>();
|
||||||
*this & GetLibraryVersions();
|
*this & version_runtime;
|
||||||
FlushBuffer();
|
FlushBuffer();
|
||||||
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
||||||
stream = std::make_shared<std::stringstream>();
|
stream = std::make_shared<std::stringstream>();
|
||||||
|
29
libsrc/core/version.cpp
Normal file
29
libsrc/core/version.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <netgen_version.hpp>
|
||||||
|
#include "exception.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
|
|
||||||
|
namespace ngcore
|
||||||
|
{
|
||||||
|
// clang-tidy should ignore this static object
|
||||||
|
static std::map<std::string, VersionInfo> library_versions; // NOLINT
|
||||||
|
|
||||||
|
const VersionInfo& GetLibraryVersion(const std::string& library)
|
||||||
|
{ return library_versions[library]; }
|
||||||
|
|
||||||
|
const std::map<std::string, VersionInfo>& GetLibraryVersions()
|
||||||
|
{ return library_versions; }
|
||||||
|
|
||||||
|
void SetLibraryVersion(const std::string& library, const VersionInfo& version)
|
||||||
|
{
|
||||||
|
if(library_versions.count(library) && (library_versions[library] != version))
|
||||||
|
throw Exception("Failed to set library version for " + library + " to " + version.to_string() + ": version already set to " + library_versions[library].to_string());
|
||||||
|
library_versions[library] = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool dummy = [](){
|
||||||
|
SetLibraryVersion("netgen", NETGEN_VERSION);
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
} // namespace ngcore
|
@ -80,6 +80,10 @@ namespace ngcore
|
|||||||
return mayor_ == other.mayor_ && minor_ == other.minor_ && release == other.release
|
return mayor_ == other.mayor_ && minor_ == other.minor_ && release == other.release
|
||||||
&& patch == other.patch;
|
&& patch == other.patch;
|
||||||
}
|
}
|
||||||
|
bool operator !=(const VersionInfo& other) const
|
||||||
|
{
|
||||||
|
return !(*this==other);
|
||||||
|
}
|
||||||
bool operator >(const VersionInfo& other) const { return other < (*this); }
|
bool operator >(const VersionInfo& other) const { return other < (*this); }
|
||||||
bool operator <=(const VersionInfo& other) const { return !((*this) > other); }
|
bool operator <=(const VersionInfo& other) const { return !((*this) > other); }
|
||||||
bool operator >=(const VersionInfo& other) const { return !((*this) < other); }
|
bool operator >=(const VersionInfo& other) const { return !((*this) < other); }
|
||||||
@ -89,6 +93,10 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
return ost << version.to_string();
|
return ost << version.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NGCORE_API const VersionInfo& GetLibraryVersion(const std::string& library);
|
||||||
|
NGCORE_API const std::map<std::string, VersionInfo>& GetLibraryVersions();
|
||||||
|
NGCORE_API void SetLibraryVersion(const std::string& library, const VersionInfo& version);
|
||||||
} // namespace ngcore
|
} // namespace ngcore
|
||||||
|
|
||||||
#endif // NETGEN_CORE_VERSION_HPP
|
#endif // NETGEN_CORE_VERSION_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user