Skip to content

Commit

Permalink
Merge branch 'set_version' into 'master'
Browse files Browse the repository at this point in the history
Set Netgen version in Archive and generated Meshes

See merge request jschoeberl/netgen!329
  • Loading branch information
JSchoeberl committed Jul 23, 2020
2 parents 6989bde + 3305d11 commit 9d71c17
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
1 change: 1 addition & 0 deletions libsrc/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_library(ngcore SHARED
table.cpp
taskmanager.cpp
utils.cpp
version.cpp
)

# Pybind11 2.3 Issue https://github.com/pybind/pybind11/issues/1604
Expand Down
20 changes: 1 addition & 19 deletions libsrc/core/archive.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@

#include "archive.hpp"
#include <netgen_version.hpp>
#include "version.hpp"

#ifndef WIN32
#include <cxxabi.h>
#endif

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
static std::unique_ptr<std::map<std::string, detail::ClassArchiveInfo>> type_register; // NOLINT
const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname)
Expand All @@ -45,10 +33,4 @@ namespace ngcore
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return type_register->count(classname) != 0;
}


static bool dummy = [](){
SetLibraryVersion("netgen", NETGEN_VERSION);
return true;
}();
} // namespace ngcore
6 changes: 0 additions & 6 deletions libsrc/core/archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ namespace pybind11

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;

Expand Down Expand Up @@ -570,9 +567,6 @@ namespace ngcore

virtual void FlushBuffer() {}

protected:
static std::map<std::string, VersionInfo>& GetLibraryVersions();

private:
template<typename T, typename ... Bases>
friend class RegisterClassForArchive;
Expand Down
4 changes: 2 additions & 2 deletions libsrc/core/python_ngcore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ namespace ngcore
using ARCHIVE::stream;
using ARCHIVE::version_map;
using ARCHIVE::logger;
using ARCHIVE::GetLibraryVersions;
public:
PyArchive(const pybind11::object& alst = pybind11::none()) :
ARCHIVE(std::make_shared<std::stringstream>()),
Expand Down Expand Up @@ -275,10 +274,11 @@ namespace ngcore

pybind11::list WriteOut()
{
auto version_runtime = GetLibraryVersions();
FlushBuffer();
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
stream = std::make_shared<std::stringstream>();
*this & GetLibraryVersions();
*this & version_runtime;
FlushBuffer();
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
stream = std::make_shared<std::stringstream>();
Expand Down
29 changes: 29 additions & 0 deletions libsrc/core/version.cpp
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions libsrc/core/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ namespace ngcore
return mayor_ == other.mayor_ && minor_ == other.minor_ && release == other.release
&& 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 !((*this) > other); }
bool operator >=(const VersionInfo& other) const { return !((*this) < other); }
Expand All @@ -89,6 +93,10 @@ namespace ngcore
{
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

#endif // NETGEN_CORE_VERSION_HPP
1 change: 1 addition & 0 deletions libsrc/meshing/meshclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ namespace netgen
int inverttets = 0; // globflags.GetDefineFlag ("inverttets");
int invertsurf = 0; // globflags.GetDefineFlag ("invertsurfacemesh");

outfile << "# Generated by NETGEN " << GetLibraryVersion("netgen") << endl << endl;


outfile << "mesh3d" << "\n";
Expand Down

0 comments on commit 9d71c17

Please sign in to comment.