From cc76ca399f1782d94583512ca7d7a0199ca83457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Wed, 13 Jul 2022 15:58:16 +0200 Subject: [PATCH] Include filesystem from experimental for GCC 7 --- libsrc/core/CMakeLists.txt | 3 +++ libsrc/core/archive.hpp | 16 +++++++++++----- libsrc/core/utils.cpp | 12 +++++------- libsrc/core/utils.hpp | 21 +++++++++++---------- libsrc/general/gzstream.cpp | 6 +++--- libsrc/general/gzstream.h | 22 +++++++++++++++------- libsrc/general/mystring.hpp | 5 +++++ libsrc/interface/writeuser.hpp | 10 +++++++--- libsrc/meshing/meshclass.hpp | 7 ++++++- ng/ngpkg.cpp | 4 ++-- 10 files changed, 68 insertions(+), 38 deletions(-) diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index 39d7fd6..a85a414 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -46,6 +46,9 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(ngcore PUBLIC "-fabi-version=${cxx_abi_version}") endif() endif(USE_PYTHON) + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8) + target_link_libraries(ngcore PRIVATE stdc++fs) + endif() endif() if(USE_PYTHON) diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 8a3d7a3..be5ea23 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -6,7 +6,13 @@ #include // for array #include // for complex #include // for size_t, strlen -#include // for path +#if defined(__GNUC__) && (__GNUC__ < 8) +#include +namespace filesystem = std::experimental::filesystem; +#else +#include // for filesystem::path +namespace filesystem = std::filesystem; +#endif #include // for ifstream, ofstream #include // for function #include // for map @@ -862,7 +868,7 @@ namespace ngcore BinaryOutArchive(std::shared_ptr&& astream) : Archive(true), stream(std::move(astream)) { } - BinaryOutArchive(const std::filesystem::path& filename) + BinaryOutArchive(const filesystem::path& filename) : BinaryOutArchive(std::make_shared(filename)) {} ~BinaryOutArchive () override { FlushBuffer(); } @@ -958,7 +964,7 @@ namespace ngcore BinaryInArchive (std::shared_ptr&& astream) : Archive(false), stream(std::move(astream)) { } - BinaryInArchive (const std::filesystem::path& filename) + BinaryInArchive (const filesystem::path& filename) : BinaryInArchive(std::make_shared(filename)) { ; } using Archive::operator&; @@ -1058,7 +1064,7 @@ namespace ngcore TextOutArchive (std::shared_ptr&& astream) : Archive(true), stream(std::move(astream)) { } - TextOutArchive (const std::filesystem::path& filename) : + TextOutArchive (const filesystem::path& filename) : TextOutArchive(std::make_shared(filename)) { } using Archive::operator&; @@ -1113,7 +1119,7 @@ namespace ngcore TextInArchive (std::shared_ptr&& astream) : Archive(false), stream(std::move(astream)) { } - TextInArchive (const std::filesystem::path& filename) + TextInArchive (const filesystem::path& filename) : TextInArchive(std::make_shared(filename)) {} using Archive::operator&; diff --git a/libsrc/core/utils.cpp b/libsrc/core/utils.cpp index 4ab08f3..ba454f6 100644 --- a/libsrc/core/utils.cpp +++ b/libsrc/core/utils.cpp @@ -13,8 +13,6 @@ #endif //WIN32 // #include -#include -#include #include #include #include @@ -135,16 +133,16 @@ namespace ngcore #endif } - NGCORE_API std::filesystem::path GetTempFilename() + NGCORE_API filesystem::path GetTempFilename() { static int counter = 0; - auto path = std::filesystem::temp_directory_path(); + auto path = filesystem::temp_directory_path(); path += ".temp_netgen_file_"+ToString(counter++)+"_"+ToString(GetTimeCounter()); return path; } - SharedLibrary :: SharedLibrary(const std::filesystem::path & lib_name_, std::optional directory_to_delete_, bool global ) + SharedLibrary :: SharedLibrary(const filesystem::path & lib_name_, std::optional directory_to_delete_, bool global ) : lib_name(lib_name_),directory_to_delete(directory_to_delete_) { Load(lib_name, global); @@ -160,7 +158,7 @@ namespace ngcore // wait for it to finish (up to a second) try { - std::filesystem::remove_all(*directory_to_delete); + filesystem::remove_all(*directory_to_delete); directory_to_delete = std::nullopt; break; } @@ -173,7 +171,7 @@ namespace ngcore std::cerr << "Could not delete " << directory_to_delete->string() << std::endl; } - void SharedLibrary :: Load( const std::filesystem::path & lib_name_, bool global ) + void SharedLibrary :: Load( const filesystem::path & lib_name_, bool global ) { Unload(); lib_name = lib_name_; diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index a503d53..a7a8f51 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -3,7 +3,13 @@ #include #include +#if defined(__GNUC__) && (__GNUC__ < 8) +#include +namespace filesystem = std::experimental::filesystem; +#else #include +namespace filesystem = std::filesystem; +#endif #include #include #include @@ -99,11 +105,6 @@ namespace ngcore return res; } - inline std::string ToLower( const std::filesystem::path & p ) - { - return ToLower(p.string()); - } - template @@ -346,7 +347,7 @@ namespace ngcore NGCORE_API int GetCompiledSIMDSize(); NGCORE_API bool IsRangeCheckEnabled(); - NGCORE_API std::filesystem::path GetTempFilename(); + NGCORE_API filesystem::path GetTempFilename(); NGCORE_API void* GetRawSymbol( std::string func_name ); @@ -359,13 +360,13 @@ namespace ngcore // Class to handle/load shared libraries class NGCORE_API SharedLibrary { - std::filesystem::path lib_name; - std::optional directory_to_delete = std::nullopt; + filesystem::path lib_name; + std::optional directory_to_delete = std::nullopt; void *lib = nullptr; public: SharedLibrary() = default; - SharedLibrary(const std::filesystem::path & lib_name_, std::optional directory_to_delete_ = std::nullopt, bool global = false ); + SharedLibrary(const filesystem::path & lib_name_, std::optional directory_to_delete_ = std::nullopt, bool global = false ); SharedLibrary(const SharedLibrary &) = delete; SharedLibrary & operator =(const SharedLibrary &) = delete; @@ -378,7 +379,7 @@ namespace ngcore return reinterpret_cast(GetRawSymbol(func_name)); } - void Load( const std::filesystem::path & lib_name_, bool global = true); + void Load( const filesystem::path & lib_name_, bool global = true); void Unload(); void* GetRawSymbol( std::string func_name ); }; diff --git a/libsrc/general/gzstream.cpp b/libsrc/general/gzstream.cpp index 968c07f..78a67a3 100644 --- a/libsrc/general/gzstream.cpp +++ b/libsrc/general/gzstream.cpp @@ -44,7 +44,7 @@ namespace GZSTREAM_NAMESPACE { // class gzstreambuf: // -------------------------------------- - gzstreambuf* gzstreambuf::open( const std::filesystem::path & name, int open_mode) { + gzstreambuf* gzstreambuf::open( const filesystem::path & name, int open_mode) { if ( is_open()) return (gzstreambuf*)0; mode = open_mode; @@ -143,7 +143,7 @@ int gzstreambuf::sync() { // class gzstreambase: // -------------------------------------- - gzstreambase::gzstreambase( const std::filesystem::path & name, int mode) { + gzstreambase::gzstreambase( const filesystem::path & name, int mode) { init( &buf); open( name.c_str(), mode); } @@ -152,7 +152,7 @@ gzstreambase::~gzstreambase() { buf.close(); } - void gzstreambase::open( const std::filesystem::path & name, int open_mode) { + void gzstreambase::open( const filesystem::path & name, int open_mode) { if ( ! buf.open( name.c_str(), open_mode)) clear( rdstate() | std::ios::badbit); } diff --git a/libsrc/general/gzstream.h b/libsrc/general/gzstream.h index 20a7779..d05826a 100644 --- a/libsrc/general/gzstream.h +++ b/libsrc/general/gzstream.h @@ -34,6 +34,14 @@ #include #include +#if defined(__GNUC__) && (__GNUC__ < 8) +#include +namespace filesystem = std::experimental::filesystem; +#else +#include // for filesystem::path +namespace filesystem = std::filesystem; +#endif + #ifdef GZSTREAM_NAMESPACE namespace GZSTREAM_NAMESPACE { #endif @@ -62,7 +70,7 @@ public: // ASSERT: both input & output capabilities will not be used together } int is_open() { return opened; } - gzstreambuf* open( const std::filesystem::path & name, int open_mode); + gzstreambuf* open( const filesystem::path & name, int open_mode); gzstreambuf* close(); ~gzstreambuf() { close(); } @@ -76,9 +84,9 @@ protected: gzstreambuf buf; public: gzstreambase() { init(&buf); } - gzstreambase( const std::filesystem::path & name, int open_mode); + gzstreambase( const filesystem::path & name, int open_mode); ~gzstreambase(); - void open( const std::filesystem::path & name, int open_mode); + void open( const filesystem::path & name, int open_mode); void close(); gzstreambuf* rdbuf() { return &buf; } }; @@ -92,10 +100,10 @@ public: class DLL_HEADER igzstream : public gzstreambase, public std::istream { public: igzstream() : std::istream( &buf) {} - igzstream( const std::filesystem::path & name, int open_mode = std::ios::in) + igzstream( const filesystem::path & name, int open_mode = std::ios::in) : gzstreambase( name, open_mode), std::istream( &buf) {} gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } - void open( const std::filesystem::path & name, int open_mode = std::ios::in) { + void open( const filesystem::path & name, int open_mode = std::ios::in) { gzstreambase::open( name, open_mode); } }; @@ -103,10 +111,10 @@ public: class DLL_HEADER ogzstream : public gzstreambase, public std::ostream { public: ogzstream() : std::ostream( &buf) {} - ogzstream( const std::filesystem::path & name, int mode = std::ios::out) + ogzstream( const filesystem::path & name, int mode = std::ios::out) : gzstreambase( name, mode), std::ostream( &buf) {} gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } - void open( const std::filesystem::path & name, int open_mode = std::ios::out) { + void open( const filesystem::path & name, int open_mode = std::ios::out) { gzstreambase::open( name, open_mode); } }; diff --git a/libsrc/general/mystring.hpp b/libsrc/general/mystring.hpp index 4f2167e..edb2b9b 100644 --- a/libsrc/general/mystring.hpp +++ b/libsrc/general/mystring.hpp @@ -19,7 +19,12 @@ #ifndef MYSTRING__H #define MYSTRING__H +#if defined(__GNUC__) && (__GNUC__ < 8) +#include +namespace filesystem = std::experimental::filesystem; +#else #include +#endif namespace netgen { diff --git a/libsrc/interface/writeuser.hpp b/libsrc/interface/writeuser.hpp index 99dc21e..1835707 100644 --- a/libsrc/interface/writeuser.hpp +++ b/libsrc/interface/writeuser.hpp @@ -7,7 +7,13 @@ /* Date: 10. Dec. 97 */ /**************************************************************************/ -#include +#if defined(__GNUC__) && (__GNUC__ < 8) +#include +namespace filesystem = std::experimental::filesystem; +#else +#include // for filesystem::path +namespace filesystem = std::filesystem; +#endif #include #include @@ -15,8 +21,6 @@ namespace netgen { -using namespace std::filesystem; - typedef std::function FWrite; typedef std::function FRead; typedef std::function FTest; diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 4be51c8..9635863 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -11,7 +11,12 @@ The mesh class */ -#include +#if defined(__GNUC__) && (__GNUC__ < 8) +#include +namespace filesystem = std::experimental::filesystem; +#else +#include +#endif #include #include diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 8b6a245..fe728cd 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -2132,7 +2132,7 @@ namespace netgen #endif // JPEGLIB { string command; - std::filesystem::path filepath(filename); + filesystem::path filepath(filename); bool need_conversion = filepath.extension() != ".ppm"; if (need_conversion) @@ -2163,7 +2163,7 @@ namespace netgen return TCL_ERROR; } - std::filesystem::remove(filepath); + filesystem::remove(filepath); } return TCL_OK; -- 2.48.1