From b2bd3b203ec53b3b2eb15fdef96e1a9ee42dd302 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Wed, 10 May 2023 18:23:24 +0200 Subject: [PATCH] functional_write -> stream2file --- Device/IO/IOFactory.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Device/IO/IOFactory.cpp b/Device/IO/IOFactory.cpp index 40d479d939b..9892bb80c33 100644 --- a/Device/IO/IOFactory.cpp +++ b/Device/IO/IOFactory.cpp @@ -76,7 +76,7 @@ std::stringstream file2stream(const std::string& file_name) return str; } -void functional_write(const std::string& file_name, std::function<void(std::ostream&)> writeData) +void stream2file(const std::string& file_name, std::stringstream& s) { using namespace DataUtil::Format; @@ -95,15 +95,13 @@ void functional_write(const std::string& file_name, std::function<void(std::ostr throw std::runtime_error("Cannot open file for writing: " + file_name); if (!fout.good()) throw std::runtime_error("File is not good, probably it is a directory: " + file_name); - std::stringstream ss; - writeData(ss); boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered; if (DataUtil::Format::isGZipped(file_name)) input_filtered.push(boost::iostreams::gzip_compressor()); else if (DataUtil::Format::isBZipped(file_name)) input_filtered.push(boost::iostreams::bzip2_compressor()); - input_filtered.push(ss); + input_filtered.push(s); boost::iostreams::copy(input_filtered, fout); @@ -149,14 +147,19 @@ Datafield* IOFactory::readReflectometryData(const std::string& file_name) void IOFactory::writeDatafield(const Datafield& data, const std::string& file_name) { try { + std::stringstream s; + if (DataUtil::Format::isIntFile(file_name)) - functional_write(file_name, [&](std::ostream& s) { IO::writeBAInt(data, s); }); + IO::writeBAInt(data, s); #ifdef BA_TIFF_SUPPORT else if (DataUtil::Format::isTiffFile(file_name)) - functional_write(file_name, [&](std::ostream& s) { IO::writeTiff(data, s); }); + IO::writeTiff(data, s); #endif else - functional_write(file_name, [&](std::ostream& s) { IO::writeNumpyTxt(data, s); }); + IO::writeNumpyTxt(data, s); + + stream2file(file_name, s); + } catch (const std::exception& ex) { throw std::runtime_error("Failed writing to " + file_name + ": " + ex.what()); } -- GitLab