Commit 54728d49 by Maarten L. Hekkelman

replacing boost libraries with standard version, where possible

parent 2afddc23
......@@ -64,7 +64,7 @@ LDFLAGS="$OLD_LDFLAGS"
LIBS="$OLD_LIBS"
AX_BOOST_IOSTREAMS
AX_BOOST_FILESYSTEM
dnl AX_BOOST_FILESYSTEM
AX_BOOST_THREAD
AC_ARG_WITH([clipper],
......
......@@ -4,7 +4,6 @@
#include "cif++/Config.h"
#include <boost/filesystem/operations.hpp>
#include <boost/math/quaternion.hpp>
namespace mmcif
......
......@@ -11,7 +11,6 @@
#include <boost/lexical_cast.hpp>
#include <boost/any.hpp>
#include <boost/filesystem/path.hpp>
#include "cif++/CifUtils.h"
......@@ -1441,15 +1440,15 @@ class File
File();
File(std::istream& is, bool validate = false);
File(boost::filesystem::path p, bool validate = false);
File(const std::string& path, bool validate = false);
File(File&& rhs);
File(const File& rhs) = delete;
File& operator=(const File& rhs) = delete;
~File();
void load(boost::filesystem::path p);
void save(boost::filesystem::path p);
void load(const std::string& p);
void save(const std::string& p);
void load(std::istream& is);
void save(std::ostream& os);
......
......@@ -2,8 +2,6 @@
#include "cif++/Cif++.h"
#include <boost/filesystem/path.hpp>
//// the std regex of gcc is crashing....
#include <boost/regex.hpp>
......
......@@ -108,7 +108,7 @@ class Compound
{
public:
Compound(const boost::filesystem::path& file, const std::string& id, const std::string& name,
Compound(const std::string& file, const std::string& id, const std::string& name,
const std::string& group);
// factory method, create a Compound based on the three letter code
......
#pragma once
#include <clipper/clipper.h>
#include <boost/filesystem/path.hpp>
#include "cif++/Structure.h"
......@@ -29,11 +28,11 @@ class Map
const Xmap& get() const { return mMap; }
// These routines work with CCP4 map files
void read(const boost::filesystem::path& f);
void write(const boost::filesystem::path& f);
void read(const std::string& f);
void write(const std::string& f);
void write_masked(std::ostream& os, clipper::Grid_range range);
void write_masked(const boost::filesystem::path& f,
void write_masked(const std::string& f,
clipper::Grid_range range);
clipper::Spacegroup spacegroup() const { return mMap.spacegroup(); }
......@@ -59,7 +58,7 @@ using clipper::Grid_sampling;
// --------------------------------------------------------------------
bool IsMTZFile(const boost::filesystem::path& p);
bool IsMTZFile(const std::string& p);
// --------------------------------------------------------------------
......@@ -80,7 +79,7 @@ class MapMaker
MapMaker(const MapMaker&) = delete;
MapMaker& operator=(const MapMaker&) = delete;
void loadMTZ(const boost::filesystem::path& mtzFile,
void loadMTZ(const std::string& mtzFile,
float samplingRate,
std::initializer_list<std::string> fbLabels = { "FWT", "PHWT" },
std::initializer_list<std::string> fdLabels = { "DELFWT", "PHDELWT" },
......@@ -89,12 +88,12 @@ class MapMaker
std::initializer_list<std::string> faLabels = { "FAN", "PHAN" });
void loadMaps(
const boost::filesystem::path& fbMapFile,
const boost::filesystem::path& fdMapFile,
const std::string& fbMapFile,
const std::string& fdMapFile,
float reshi, float reslo);
// following works on both mtz files and structure factor files in CIF format
void calculate(const boost::filesystem::path& hklin,
void calculate(const std::string& hklin,
const Structure& structure,
bool noBulk, AnisoScalingFlag anisoScaling,
float samplingRate, bool electronScattering = false,
......@@ -107,7 +106,7 @@ class MapMaker
void printStats();
void writeMTZ(const boost::filesystem::path& file,
void writeMTZ(const std::string& file,
const std::string& project, const std::string& crystal);
MapType& fb() { return mFb; }
......@@ -127,8 +126,8 @@ class MapMaker
private:
void loadFoFreeFromReflectionsFile(const boost::filesystem::path& hklin);
void loadFoFreeFromMTZFile(const boost::filesystem::path& hklin,
void loadFoFreeFromReflectionsFile(const std::string& hklin);
void loadFoFreeFromMTZFile(const std::string& hklin,
std::initializer_list<std::string> foLabels,
std::initializer_list<std::string> freeLabels);
......
......@@ -4,7 +4,6 @@
#include "cif++/Config.h"
#include <boost/filesystem/operations.hpp>
#include <boost/math/quaternion.hpp>
#include "clipper/core/coords.h"
......
......@@ -4,7 +4,6 @@
#include <numeric>
#include <boost/filesystem/operations.hpp>
#include <boost/math/quaternion.hpp>
#include <boost/any.hpp>
......@@ -330,14 +329,14 @@ class File : public std::enable_shared_from_this<File>
{
public:
File();
File(boost::filesystem::path p);
File(const std::string& path);
~File();
File(const File&) = delete;
File& operator=(const File&) = delete;
void load(boost::filesystem::path p);
void save(boost::filesystem::path p);
void load(const std::string& path);
void save(const std::string& path);
Structure* model(size_t nr = 1);
......
......@@ -8,10 +8,17 @@
#include <set>
#include <unordered_map>
#include <numeric>
#include <fstream>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#endif
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filter/gzip.hpp>
......@@ -26,7 +33,6 @@
using namespace std;
namespace ba = boost::algorithm;
namespace fs = boost::filesystem;
namespace io = boost::iostreams;
namespace cif
......@@ -2789,16 +2795,16 @@ File::File(istream& is, bool validate)
load(is);
}
File::File(boost::filesystem::path p, bool validate)
File::File(const std::string& path, bool validate)
: File()
{
try
{
load(p);
load(path);
}
catch (const exception& ex)
{
cerr << "Error while loading file " << p << endl;
cerr << "Error while loading file " << path << endl;
throw;
}
}
......@@ -2841,24 +2847,26 @@ void File::append(Datablock* e)
}
}
void File::load(fs::path p)
void File::load(const std::string& p)
{
fs::ifstream inFile(p, ios_base::in | ios_base::binary);
fs::path path(p);
std::ifstream inFile(p, ios_base::in | ios_base::binary);
if (not inFile.is_open())
throw runtime_error("Could not open file: " + p.string());
throw runtime_error("Could not open file: " + path.string());
io::filtering_stream<io::input> in;
string ext;
std::string ext;
if (p.extension() == ".bz2")
if (path.extension() == ".bz2")
{
in.push(io::bzip2_decompressor());
ext = p.stem().extension().string();
ext = path.stem().extension().string();
}
else if (p.extension() == ".gz")
else if (path.extension() == ".gz")
{
in.push(io::gzip_decompressor());
ext = p.stem().extension().string();
ext = path.stem().extension().string();
}
in.push(inFile);
......@@ -2869,25 +2877,27 @@ void File::load(fs::path p)
}
catch (const exception& ex)
{
cerr << "Error loading file " << p << endl;
cerr << "Error loading file " << path << endl;
throw;
}
}
void File::save(fs::path p)
void File::save(const std::string& p)
{
fs::ofstream outFile(p, ios_base::out | ios_base::binary);
fs::path path(p);
std::ofstream outFile(p, ios_base::out | ios_base::binary);
io::filtering_stream<io::output> out;
if (p.extension() == ".gz")
if (path.extension() == ".gz")
{
out.push(io::gzip_compressor());
p = p.stem();
path = path.stem();
}
else if (p.extension() == ".bz2")
else if (path.extension() == ".bz2")
{
out.push(io::bzip2_compressor());
p = p.stem();
path = path.stem();
}
out.push(outFile);
......@@ -2985,13 +2995,13 @@ void File::loadDictionary(const char* dict)
{
for (;;)
{
string name(dict);
fs::path name(dict);
try
{
if (fs::exists(name))
{
fs::ifstream is(name);
std::ifstream is(name);
loadDictionary(is);
break;
}
......@@ -3004,7 +3014,7 @@ void File::loadDictionary(const char* dict)
{
if (fs::exists(dictFile))
{
fs::ifstream is(dictFile);
std::ifstream is(dictFile);
loadDictionary(is);
break;
}
......@@ -3029,7 +3039,7 @@ void File::loadDictionary(const char* dict)
break;
}
throw runtime_error("Dictionary not found or defined (" + name + ")");
throw runtime_error("Dictionary not found or defined (" + name.string() + ")");
}
}
......
......@@ -6,6 +6,8 @@
#include <iostream>
#include <cstdio>
#include <atomic>
#include <mutex>
#include <thread>
#if defined(_MSC_VER)
#define TERM_WIDTH 80
......@@ -15,7 +17,6 @@
#endif
#include <boost/algorithm/string.hpp>
#include <boost/thread.hpp>
#if BOOST_VERSION >= 104800
#include <boost/timer/timer.hpp>
#endif
......@@ -436,7 +437,7 @@ struct ProgressImpl
{
ProgressImpl(int64_t inMax, const string& inAction)
: mMax(inMax), mConsumed(0), mAction(inAction), mMessage(inAction)
, mThread(boost::bind(&ProgressImpl::Run, this)) {}
, mThread(std::bind(&ProgressImpl::Run, this)) {}
void Run();
......@@ -448,8 +449,8 @@ struct ProgressImpl
int64_t mLastConsumed = 0;
int mSpinnerIndex = 0;
string mAction, mMessage;
boost::mutex mMutex;
boost::thread mThread;
std::mutex mMutex;
std::thread mThread;
boost::timer::cpu_timer
mTimer;
};
......@@ -460,11 +461,11 @@ void ProgressImpl::Run()
try
{
boost::this_thread::sleep(boost::posix_time::seconds(5));
std::this_thread::sleep_for(std::chrono::seconds(5));
for (;;)
{
boost::mutex::scoped_lock lock(mMutex);
std::unique_lock lock(mMutex);
if (mConsumed == mMax)
break;
......@@ -472,7 +473,7 @@ void ProgressImpl::Run()
PrintProgress();
printedAny = true;
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
catch (...) {}
......@@ -591,7 +592,7 @@ Progress::~Progress()
{
if (mImpl != nullptr and mImpl->mThread.joinable())
{
mImpl->mThread.interrupt();
// mImpl->mThread.interrupt();
mImpl->mThread.join();
}
......@@ -604,7 +605,7 @@ void Progress::consumed(int64_t inConsumed)
(mImpl->mConsumed += inConsumed) >= mImpl->mMax and
mImpl->mThread.joinable())
{
mImpl->mThread.interrupt();
// mImpl->mThread.interrupt();
mImpl->mThread.join();
}
}
......@@ -615,7 +616,7 @@ void Progress::progress(int64_t inProgress)
(mImpl->mConsumed = inProgress) >= mImpl->mMax and
mImpl->mThread.joinable())
{
mImpl->mThread.interrupt();
// mImpl->mThread.interrupt();
mImpl->mThread.join();
}
}
......@@ -624,7 +625,7 @@ void Progress::message(const std::string& inMessage)
{
if (mImpl != nullptr)
{
boost::mutex::scoped_lock lock(mImpl->mMutex);
std::unique_lock lock(mImpl->mMutex);
mImpl->mMessage = inMessage;
}
}
......
......@@ -4,11 +4,17 @@
#include <map>
#include <numeric>
#include <shared_mutex>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/thread.hpp>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#endif
#include "cif++/Cif++.h"
#include "cif++/Point.h"
......@@ -19,7 +25,6 @@
using namespace std;
namespace ba = boost::algorithm;
namespace fs = boost::filesystem;
namespace mmcif
{
......@@ -310,7 +315,7 @@ bool StructuresAreIsomeric(vector<CompoundAtom> atomsA, const vector<CompoundBon
// --------------------------------------------------------------------
// Compound
Compound::Compound(const fs::path& file, const std::string& id,
Compound::Compound(const std::string& file, const std::string& id,
const std::string& name, const std::string& group)
: mId(id), mName(name), mGroup(group)
{
......@@ -1018,7 +1023,7 @@ const map<string,char> kBaseMap{
class CompoundFactoryImpl
{
public:
CompoundFactoryImpl(fs::path file, CompoundFactoryImpl* next);
CompoundFactoryImpl(const std::string& file, CompoundFactoryImpl* next);
~CompoundFactoryImpl()
{
......@@ -1074,9 +1079,9 @@ class CompoundFactoryImpl
}
private:
boost::shared_mutex mMutex;
std::shared_timed_mutex mMutex;
fs::path mPath;
std::string mPath;
vector<Compound*> mCompounds;
vector<const Link*> mLinks;
/*unordered_*/set<string> mKnownPeptides;
......@@ -1089,7 +1094,7 @@ class CompoundFactoryImpl
// --------------------------------------------------------------------
CompoundFactoryImpl::CompoundFactoryImpl(fs::path file, CompoundFactoryImpl* next)
CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactoryImpl* next)
: mPath(file), mFile(file), mChemComp(mFile.firstDatablock()["chem_comp"]), mNext(next)
{
const std::regex peptideRx("(?:[lmp]-)?peptide", std::regex::icase);
......@@ -1185,7 +1190,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(fs::path file, CompoundFactoryImpl* nex
Compound* CompoundFactoryImpl::get(string id)
{
boost::shared_lock<boost::shared_mutex> lock(mMutex);
std::shared_lock lock(mMutex);
ba::to_upper(id);
......@@ -1213,7 +1218,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
Compound* result = get(id);
if (result == nullptr and mMissing.count(id) == 0)
{
boost::upgrade_lock<boost::shared_mutex> lock(mMutex);
std::unique_lock lock(mMutex);
auto rs = mChemComp.find(cif::Key("three_letter_code") == id);
......@@ -1262,7 +1267,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
const Link* CompoundFactoryImpl::getLink(string id)
{
boost::shared_lock<boost::shared_mutex> lock(mMutex);
std::shared_lock lock(mMutex);
ba::to_upper(id);
......@@ -1291,7 +1296,7 @@ const Link* CompoundFactoryImpl::createLink(std::string id)
if (result == nullptr)
{
boost::upgrade_lock<boost::shared_mutex> lock(mMutex);
std::unique_lock lock(mMutex);
auto db = mFile.get("link_" + id);
if (db != nullptr)
......
......@@ -5,8 +5,6 @@
#include <atomic>
#include <mutex>
#include <boost/thread.hpp>
#include "cif++/DistanceMap.h"
#include "cif++/CifUtils.h"
......
#include "cif++/Config.h"
#include <iomanip>
#include <fstream>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#endif
#include <boost/format.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
......@@ -18,7 +26,6 @@
#include "cif++/ResolutionCalculator.h"
using namespace std;
namespace fs = boost::filesystem;
namespace io = boost::iostreams;
namespace ba = boost::algorithm;
......@@ -249,11 +256,11 @@ void writeCCP4MapFile(ostream& os, clipper::Xmap<FTYPE>& xmap, clipper::Grid_ran
// --------------------------------------------------------------------
bool IsMTZFile(const fs::path& p)
bool IsMTZFile(const std::string& p)
{
bool result = false;
fs::ifstream f(p);
std::ifstream f(p);
if (f.is_open())
{
char sig[5] = {};
......@@ -307,8 +314,9 @@ void Map<FTYPE>::calculateStats()
}
template<typename FTYPE>
void Map<FTYPE>::read(const fs::path& mapFile)
void Map<FTYPE>::read(const std::string& f)
{
fs::path mapFile(f);
fs::path dataFile = mapFile;
if (cif::VERBOSE)
......@@ -323,7 +331,7 @@ void Map<FTYPE>::read(const fs::path& mapFile)
io::filtering_stream<io::input> in;
fs::ifstream fi(mapFile);
std::ifstream fi(mapFile);
if (mapFile.extension() == ".gz")
in.push(io::gzip_decompressor());
......@@ -337,7 +345,7 @@ void Map<FTYPE>::read(const fs::path& mapFile)
throw runtime_error(string("Could not create temp file for map: ") + strerror(errno));
dataFile = fs::path(tmpFileName);
fs::ofstream out(dataFile);
std::ofstream out(dataFile);
io::copy(in, out);
}
......@@ -358,7 +366,7 @@ void Map<FTYPE>::read(const fs::path& mapFile)
}
template<typename FTYPE>
void Map<FTYPE>::write(const fs::path& f)
void Map<FTYPE>::write(const std::string& f)
{
write_masked(f, mMap.grid_asu());
}
......@@ -370,11 +378,11 @@ void Map<FTYPE>::write_masked(ostream& os, clipper::Grid_range r)
}
template<typename FTYPE>
void Map<FTYPE>::write_masked(const fs::path& f, clipper::Grid_range r)
void Map<FTYPE>::write_masked(const std::string& f, clipper::Grid_range r)
{
fs::ofstream file(f, ios_base::binary);
std::ofstream file(f, ios_base::binary);
if (not file.is_open())
throw runtime_error("Could not open map file for writing: " + f.string());
throw runtime_error("Could not open map file for writing: " + f);
write_masked(file, r);
}
......@@ -395,11 +403,13 @@ MapMaker<FTYPE>::~MapMaker()
}
template<typename FTYPE>
void MapMaker<FTYPE>::loadMTZ(const fs::path& hklin, float samplingRate,
void MapMaker<FTYPE>::loadMTZ(const std::string& f, float samplingRate,
initializer_list<string> fbLabels, initializer_list<string> fdLabels,
initializer_list<string> foLabels, initializer_list<string> fcLabels,
initializer_list<string> faLabels)
{
fs::path hklin(f);
if (cif::VERBOSE)
cerr << "Reading map from " << hklin << endl
<< " with labels: FB: " << ba::join(fbLabels, ",") << endl
......@@ -419,7 +429,7 @@ void MapMaker<FTYPE>::loadMTZ(const fs::path& hklin, float samplingRate,
io::filtering_stream<io::input> in;
fs::ifstream fi(hklin);
std::ifstream fi(hklin);
if (hklin.extension() == ".gz")
in.push(io::gzip_decompressor());
......@@ -433,7 +443,7 @@ void MapMaker<FTYPE>::loadMTZ(const fs::path& hklin, float samplingRate,
throw runtime_error(string("Could not create temp file for mtz: ") + strerror(errno));
dataFile = fs::path(tmpFileName);
fs::ofstream out(dataFile);
std::ofstream out(dataFile);
io::copy(in, out);
}
......@@ -542,7 +552,7 @@ void MapMaker<FTYPE>::loadMTZ(const fs::path& hklin, float samplingRate,
template<typename FTYPE>
void MapMaker<FTYPE>::loadMaps(
const fs::path& fbMapFile, const fs::path& fdMapFile, float reshi, float reslo)
const std::string& fbMapFile, const std::string& fdMapFile, float reshi, float reslo)
{
mResHigh = reshi;
mResLow = reslo;
......@@ -568,7 +578,7 @@ ostream& operator<<(ostream& os, const clipper::HKL& hkl)
// --------------------------------------------------------------------
template<typename FTYPE>
void MapMaker<FTYPE>::calculate(const fs::path& hklin,
void MapMaker<FTYPE>::calculate(const std::string& hklin,
const Structure& structure, bool noBulk, AnisoScalingFlag anisoScaling,
float samplingRate, bool electronScattering,
initializer_list<std::string> foLabels, initializer_list<std::string> freeLabels)
......@@ -584,7 +594,7 @@ void MapMaker<FTYPE>::calculate(const fs::path& hklin,
// --------------------------------------------------------------------
template<typename FTYPE>
void MapMaker<FTYPE>::loadFoFreeFromReflectionsFile(const fs::path& hklin)
void MapMaker<FTYPE>::loadFoFreeFromReflectionsFile(const std::string& hklin)
{
using clipper::HKL;
......@@ -701,7 +711,7 @@ void MapMaker<FTYPE>::loadFoFreeFromReflectionsFile(const fs::path& hklin)
// --------------------------------------------------------------------
template<typename FTYPE>
void MapMaker<FTYPE>::loadFoFreeFromMTZFile(const fs::path& hklin,
void MapMaker<FTYPE>::loadFoFreeFromMTZFile(const std::string& hklin,
initializer_list<std::string> foLabels, initializer_list<std::string> freeLabels)
{
if (cif::VERBOSE)
......@@ -712,7 +722,7 @@ void MapMaker<FTYPE>::loadFoFreeFromMTZFile(const fs::path& hklin,
using clipper::CCP4MTZfile;
CCP4MTZfile mtzin;
mtzin.open_read(hklin.string());
mtzin.open_read(hklin);
mtzin.import_hkl_info(mHKLInfo);
mtzin.import_hkl_data(mFoData,
......@@ -1082,7 +1092,7 @@ void MapMaker<FTYPE>::printStats()
}
template<typename FTYPE>
void MapMaker<FTYPE>::writeMTZ(const fs::path& file, const string& pname, const string& cname)
void MapMaker<FTYPE>::writeMTZ(const std::string& file, const string& pname, const string& cname)
{
if (mHKLInfo.is_null())
throw runtime_error("HKL info not initialized");
......@@ -1093,7 +1103,7 @@ void MapMaker<FTYPE>::writeMTZ(const fs::path& file, const string& pname, const
const string col = "/" + pname + "/" + cname + "/";
mtz.open_write(file.string());
mtz.open_write(file);
mtz.export_hkl_info(mHKLInfo);
mtz.export_crystal(crystal, col);
mtz.export_dataset(dataset, col);
......
......@@ -2,7 +2,7 @@
#include <map>
#include <set>
#include <boost/regex.hpp>
#include <system_error>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/algorithm/string.hpp>
......@@ -40,11 +40,11 @@ namespace error
namespace detail
{
class pdbCategory : public boost::system::error_category
class pdbCategory : public std::error_category
{
public:
const char* name() const BOOST_SYSTEM_NOEXCEPT
const char* name() const noexcept
{
return "pdb";
}
......@@ -66,20 +66,20 @@ namespace error
};
}
boost::system::error_category& pdbCategory()
std::error_category& pdbCategory()
{
static detail::pdbCategory impl;
return impl;
}
inline boost::system::error_code make_error_code(pdbErrors e)
inline std::error_code make_error_code(pdbErrors e)
{
return boost::system::error_code(static_cast<int>(e), pdbCategory());
return std::error_code(static_cast<int>(e), pdbCategory());
}
}
namespace boost {
namespace system {
namespace std
{
template<> struct is_error_code_enum<error::pdbErrors>
{
......@@ -87,7 +87,6 @@ template<> struct is_error_code_enum<error::pdbErrors>
};
}
}
// --------------------------------------------------------------------
......@@ -636,7 +635,7 @@ class PDBFileParser
}
}
tuple<string,int,bool> MapResidue(char chainID, int resSeq, char iCode, boost::system::error_code& ec) const
tuple<string,int,bool> MapResidue(char chainID, int resSeq, char iCode, std::error_code& ec) const
{
auto key = make_tuple(chainID, resSeq, iCode);
......@@ -697,7 +696,7 @@ class PDBFileParser
vector<string> SplitCSV(const string& value);
string pdb2cifDate(string s, boost::system::error_code& ec)
string pdb2cifDate(string s, std::error_code& ec)
{
smatch m;
const regex
......@@ -750,7 +749,7 @@ class PDBFileParser
string pdb2cifDate(string s)
{
boost::system::error_code ec;
std::error_code ec;
return pdb2cifDate(s, ec);
}
......@@ -2701,7 +2700,7 @@ void PDBFileParser::ParseRemark200()
});
string collectionDate;
boost::system::error_code ec;
std::error_code ec;
collectionDate = pdb2cifDate(rm200("DATE OF DATA COLLECTION", diffrnNr), ec);
if (ec)
{
......@@ -3807,7 +3806,7 @@ void PDBFileParser::ConstructEntities()
string asym, seqNum;
int labelSeq = -1;
boost::system::error_code ec;
std::error_code ec;
tie(asym, labelSeq, ignore) = MapResidue(seqadv.chainID, seqadv.seqNum, seqadv.iCode, ec);
if (ec)
......@@ -4128,7 +4127,7 @@ void PDBFileParser::ConstructEntities()
string asymId;
int seq;
boost::system::error_code ec;
std::error_code ec;
tie(asymId, seq, ignore) = MapResidue(chainID, seqNum, iCode, ec);
if (ec) // no need to write a modres if it could not be found
......@@ -4221,7 +4220,7 @@ void PDBFileParser::ConstructEntities()
bool isPolymer = false;
string asymId, compId = unobs.res;
int seqNr = 0;
boost::system::error_code ec;
std::error_code ec;
tie(asymId, seqNr, isPolymer) = MapResidue(unobs.chain, unobs.seq, unobs.iCode, ec);
if (ec)
......@@ -4300,7 +4299,7 @@ void PDBFileParser::ParseSecondaryStructure()
string begAsymId, endAsymId;
int begSeq, endSeq;
boost::system::error_code ec;
std::error_code ec;
tie(begAsymId, begSeq, ignore) = MapResidue(vC(20), vI(22, 25), vC(26), ec);
if (not ec)
......@@ -4421,7 +4420,7 @@ void PDBFileParser::ParseSecondaryStructure()
string begAsymId, endAsymId;
int begSeq, endSeq;
boost::system::error_code ec;
std::error_code ec;
tie(begAsymId, begSeq, ignore) = MapResidue(vC(22), vI(23, 26), vC(27), ec);
if (not ec)
......@@ -4458,7 +4457,7 @@ void PDBFileParser::ParseSecondaryStructure()
{
string r1AsymId, r2AsymId;
int r1Seq, r2Seq;
boost::system::error_code ec;
std::error_code ec;
tie(r1AsymId, r1Seq, ignore) = MapResidue(vC(65), vI(66, 69), vC(70), ec);
if (not ec)
......@@ -4556,7 +4555,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
string p1Asym, p2Asym;
int p1Seq, p2Seq;
boost::system::error_code ec;
std::error_code ec;
tie(p1Asym, p1Seq, ignore) = MapResidue(vC(16), vI(18, 21), vC(22), ec);
if (not ec)
......@@ -4674,7 +4673,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
string p1Asym, p2Asym;
int p1Seq, p2Seq;
bool isResseq1, isResseq2;
boost::system::error_code ec;
std::error_code ec;
tie(p1Asym, p1Seq, isResseq1) = MapResidue(vC(22), vI(23, 26), vC(27), ec);
if (not ec)
......@@ -4778,7 +4777,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
string lAsym1, lAsym2;
int lResSeq1, lResSeq2;
boost::system::error_code ec;
std::error_code ec;
tie(lAsym1, lResSeq1, ignore) = MapResidue(chainID1, seqNum1, iCode1, ec);
if (not ec)
......@@ -4848,7 +4847,7 @@ void PDBFileParser::ParseMiscellaneousFeatures()
int labelSeq;
string asym;
bool isResseq;
boost::system::error_code ec;
std::error_code ec;
tie(asym, labelSeq, isResseq) = MapResidue(chainID, seq, iCode, ec);
......
......@@ -3,9 +3,17 @@
#include "cif++/Structure.h"
#include <numeric>
#include <fstream>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#endif
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filter/gzip.hpp>
......@@ -19,7 +27,6 @@
using namespace std;
namespace ba = boost::algorithm;
namespace fs = boost::filesystem;
namespace io = boost::iostreams;
extern int cif::VERBOSE;
......@@ -35,28 +42,30 @@ struct FileImpl
cif::File mData;
cif::Datablock* mDb = nullptr;
void load(fs::path p);
void save(fs::path p);
void load(const std::string& p);
void save(const std::string& p);
};
void FileImpl::load(fs::path p)
void FileImpl::load(const std::string& p)
{
fs::ifstream inFile(p, ios_base::in | ios_base::binary);
fs::path path(p);
std::ifstream inFile(path, ios_base::in | ios_base::binary);
if (not inFile.is_open())
throw runtime_error("No such file: " + p.string());
throw runtime_error("No such file: " + path.string());
io::filtering_stream<io::input> in;
string ext = p.extension().string();
string ext = path.extension().string();
if (p.extension() == ".bz2")
if (path.extension() == ".bz2")
{
in.push(io::bzip2_decompressor());
ext = p.stem().extension().string();
ext = path.stem().extension().string();
}
else if (p.extension() == ".gz")
else if (path.extension() == ".gz")
{
in.push(io::gzip_decompressor());
ext = p.stem().extension().string();
ext = path.stem().extension().string();
}
in.push(inFile);
......@@ -88,11 +97,11 @@ void FileImpl::load(fs::path p)
if (inFile.is_open())
inFile.seekg(0);
else
inFile.open(p, ios_base::in | ios::binary);
inFile.open(path, ios_base::in | ios::binary);
if (p.extension() == ".bz2")
if (path.extension() == ".bz2")
in.push(io::bzip2_decompressor());
else if (p.extension() == ".gz")
else if (path.extension() == ".gz")
in.push(io::gzip_decompressor());
in.push(inFile);
......@@ -103,7 +112,7 @@ void FileImpl::load(fs::path p)
}
catch (const exception& ex)
{
cerr << "Error trying to load file " << p << endl;
cerr << "Error trying to load file " << path << endl;
throw;
}
......@@ -117,25 +126,27 @@ void FileImpl::load(fs::path p)
cerr << "Invalid mmCIF file" << (cif::VERBOSE ? "." : " use --verbose option to see errors") << endl;
}
void FileImpl::save(fs::path p)
void FileImpl::save(const std::string& p)
{
fs::ofstream outFile(p, ios_base::out | ios_base::binary);
fs::path path(p);
std::ofstream outFile(p, ios_base::out | ios_base::binary);
io::filtering_stream<io::output> out;
if (p.extension() == ".gz")
if (path.extension() == ".gz")
{
out.push(io::gzip_compressor());
p = p.stem();
path = path.stem();
}
else if (p.extension() == ".bz2")
else if (path.extension() == ".bz2")
{
out.push(io::bzip2_compressor());
p = p.stem();
path = path.stem();
}
out.push(outFile);
if (p.extension() == ".pdb")
if (path.extension() == ".pdb")
WritePDBFile(out, mData);
else
mData.save(out);
......@@ -1318,7 +1329,7 @@ File::File()
{
}
File::File(fs::path File)
File::File(const std::string& File)
: mImpl(new FileImpl)
{
load(File);
......@@ -1329,7 +1340,7 @@ File::~File()
delete mImpl;
}
void File::load(fs::path p)
void File::load(const std::string& p)
{
mImpl->load(p);
......@@ -1385,9 +1396,9 @@ void File::load(fs::path p)
}
void File::save(boost::filesystem::path File)
void File::save(const std::string& file)
{
mImpl->save(File);
mImpl->save(file);
}
cif::Datablock& File::data()
......
......@@ -5,8 +5,6 @@
#include <atomic>
#include <mutex>
#include <boost/thread.hpp>
#include "cif++/Symmetry.h"
#include "cif++/CifUtils.h"
......
......@@ -34,7 +34,6 @@
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/path.hpp>
#include "cif++/CifUtils.h"
#include "cif++/Structure.h"
......@@ -43,7 +42,6 @@
using namespace std;
namespace po = boost::program_options;
namespace ba = boost::algorithm;
namespace fs = boost::filesystem;
namespace c = mmcif;
namespace cif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment