Skip to content

Commit

Permalink
refactor: Add check to see if boost is available
Browse files Browse the repository at this point in the history
  • Loading branch information
sindre-nistad committed Jan 24, 2024
1 parent 1f27c96 commit d74cecf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/nrlib/iotools/boost-filesystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by Sindre Nistad on 23/01/2024.
//

#ifndef BOOST_FILESYSTEM_HPP
#define BOOST_FILESYSTEM_HPP

#if __has_include(<boost/filesystem.hpp>)
// 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 <boost/filesystem.hpp>
#define HAS_BOOST_FILESYSTEM 1
#endif

#endif //BOOST_FILESYSTEM_HPP
6 changes: 5 additions & 1 deletion src/nrlib/iotools/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "../exception/exception.hpp"
#include "stringtools.hpp"

#include <boost/filesystem.hpp>
#include "boost-filesystem.hpp"

#include <fstream>
#include <iostream>
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -324,6 +326,7 @@ bool NRLib::CheckEndOfFile(std::istream& stream)
}


#ifdef HAS_BOOST_FILESYSTEM
unsigned long long
NRLib::FindFileSize(const std::string& filename)
{
Expand All @@ -334,6 +337,7 @@ NRLib::FindFileSize(const std::string& filename)
return static_cast<unsigned long long>(boost::filesystem::file_size(filename));
}

#endif

int NRLib::FindGridFileType(const std::string& filename )
{
Expand Down
7 changes: 1 addition & 6 deletions src/nrlib/iotools/stringtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
#include <string>
#include <sstream>

#if __has_include(<boost/filesystem.hpp>)
// 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 <boost/filesystem.hpp>
#define HAS_BOOST_FILESYSTEM 1
#endif
#include "boost-filesystem.hpp"

using namespace NRLib;

Expand Down

0 comments on commit d74cecf

Please sign in to comment.