From d74cecf1ece2db7426675b3ae6955cb9900d5f57 Mon Sep 17 00:00:00 2001 From: Sindre Nistad Date: Wed, 24 Jan 2024 10:10:19 +0100 Subject: [PATCH] refactor: Add check to see if boost is available --- src/nrlib/iotools/boost-filesystem.hpp | 15 +++++++++++++++ src/nrlib/iotools/fileio.cpp | 6 +++++- src/nrlib/iotools/stringtools.cpp | 7 +------ 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/nrlib/iotools/boost-filesystem.hpp diff --git a/src/nrlib/iotools/boost-filesystem.hpp b/src/nrlib/iotools/boost-filesystem.hpp new file mode 100644 index 000000000..3507bf3b0 --- /dev/null +++ b/src/nrlib/iotools/boost-filesystem.hpp @@ -0,0 +1,15 @@ +// +// Created by Sindre Nistad on 23/01/2024. +// + +#ifndef BOOST_FILESYSTEM_HPP +#define BOOST_FILESYSTEM_HPP + +#if __has_include() +// The helper methods that depend on boost::filesystem, is not used by the main +// gaussianfft library, but som of the debug functionallity use them +#include +#define HAS_BOOST_FILESYSTEM 1 +#endif + +#endif //BOOST_FILESYSTEM_HPP diff --git a/src/nrlib/iotools/fileio.cpp b/src/nrlib/iotools/fileio.cpp index fb623af4b..f751ff51a 100644 --- a/src/nrlib/iotools/fileio.cpp +++ b/src/nrlib/iotools/fileio.cpp @@ -24,7 +24,7 @@ #include "../exception/exception.hpp" #include "stringtools.hpp" -#include +#include "boost-filesystem.hpp" #include #include @@ -42,6 +42,7 @@ const std::string format_desc[5] = {"storm_petro_binary", "NORSAR"}; +#ifdef HAS_BOOST_FILESYSTEM void NRLib::OpenRead(std::ifstream& stream, const std::string& filename, std::ios_base::openmode mode) @@ -201,6 +202,7 @@ void NRLib::CreateDirIfNotExists(const std::string & filename) create_directories(dir); } } +#endif std::istream& NRLib::ReadNextToken(std::istream & stream, std::string & s, @@ -324,6 +326,7 @@ bool NRLib::CheckEndOfFile(std::istream& stream) } +#ifdef HAS_BOOST_FILESYSTEM unsigned long long NRLib::FindFileSize(const std::string& filename) { @@ -334,6 +337,7 @@ NRLib::FindFileSize(const std::string& filename) return static_cast(boost::filesystem::file_size(filename)); } +#endif int NRLib::FindGridFileType(const std::string& filename ) { diff --git a/src/nrlib/iotools/stringtools.cpp b/src/nrlib/iotools/stringtools.cpp index 1ba141217..e810b22ee 100644 --- a/src/nrlib/iotools/stringtools.cpp +++ b/src/nrlib/iotools/stringtools.cpp @@ -27,12 +27,7 @@ #include #include -#if __has_include() -// The helper methods that depend on boost::filesystem, is not used by the main -// gaussianfft library, but som of the debug functionallity use them -#include -#define HAS_BOOST_FILESYSTEM 1 -#endif +#include "boost-filesystem.hpp" using namespace NRLib;