From 462b8264022c3b2efe4a62e44484f1f8e91bbd7b Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Wed, 10 May 2023 17:29:43 +0200
Subject: [PATCH] read|writeBAInt in ns IO

---
 Device/IO/IOFactory.cpp                  |  6 ++----
 Device/IO/ReadWriteINT.cpp               |  6 +++---
 Device/IO/ReadWriteINT.h                 | 18 +++++++++---------
 GUI/Model/Axis/PointwiseAxisItem.cpp     |  4 ++--
 Tests/Unit/Device/IOReaderWriterTest.cpp |  7 +++----
 5 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/Device/IO/IOFactory.cpp b/Device/IO/IOFactory.cpp
index baae6e36a28..7ff7267e37c 100644
--- a/Device/IO/IOFactory.cpp
+++ b/Device/IO/IOFactory.cpp
@@ -50,8 +50,7 @@ Datafield* IOFactory::readDatafield(const std::string& file_name, LoaderSelector
     Datafield* result = nullptr;
 
     if (readAs(bornagain))
-        result = functional_read(file_name,
-                                 [](std::istream& s) { return ReadWriteINT().readDatafield(s); });
+        result = functional_read(file_name, [](std::istream& s) { return IO::readBAInt(s); });
 
     else if (readAs(nicos))
         result = functional_read(file_name, [](std::istream& s) { return IO::readNicos(s); });
@@ -81,8 +80,7 @@ void IOFactory::writeDatafield(const Datafield& data, const std::string& file_na
 {
     try {
         if (DataUtil::Format::isIntFile(file_name))
-            functional_write(file_name,
-                             [&](std::ostream& s) { ReadWriteINT().writeDatafield(data, s); });
+            functional_write(file_name, [&](std::ostream& 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); });
diff --git a/Device/IO/ReadWriteINT.cpp b/Device/IO/ReadWriteINT.cpp
index d944ffffaf4..88b2cf982cc 100644
--- a/Device/IO/ReadWriteINT.cpp
+++ b/Device/IO/ReadWriteINT.cpp
@@ -3,7 +3,7 @@
 //  BornAgain: simulate and fit reflection and scattering
 //
 //! @file      Device/IO/ReadWriteINT.cpp
-//! @brief     Implements class ReadWriteINT.
+//! @brief     Implements functions read|writeBAInt
 //!
 //! @homepage  http://www.bornagainproject.org
 //! @license   GNU General Public License v3 or higher (see COPYING)
@@ -42,7 +42,7 @@ void writeDatafieldDoubles(const std::vector<double>& dataValues, std::ostream&
     }
 }
 
-Datafield* ReadWriteINT::readDatafield(std::istream& input_stream)
+Datafield* IO::readBAInt(std::istream& input_stream)
 {
     std::string line;
 
@@ -62,7 +62,7 @@ Datafield* ReadWriteINT::readDatafield(std::istream& input_stream)
     return result;
 }
 
-void ReadWriteINT::writeDatafield(const Datafield& data, std::ostream& output_stream)
+void IO::writeBAInt(const Datafield& data, std::ostream& output_stream)
 {
     output_stream << "# BornAgain Intensity Data\n\n";
 
diff --git a/Device/IO/ReadWriteINT.h b/Device/IO/ReadWriteINT.h
index 6e29f8d5fff..1f2403c291e 100644
--- a/Device/IO/ReadWriteINT.h
+++ b/Device/IO/ReadWriteINT.h
@@ -3,7 +3,7 @@
 //  BornAgain: simulate and fit reflection and scattering
 //
 //! @file      Device/IO/ReadWriteINT.h
-//! @brief     Defines ReadWriteINT
+//! @brief     Declares functions read|writeBAInt
 //!
 //! @homepage  http://www.bornagainproject.org
 //! @license   GNU General Public License v3 or higher (see COPYING)
@@ -18,17 +18,17 @@
 #ifndef BORNAGAIN_DEVICE_IO_READWRITEINT_H
 #define BORNAGAIN_DEVICE_IO_READWRITEINT_H
 
-#include <istream>
-#include <vector>
+#include <iostream>
 
 class Datafield;
 
-//! Class for reading and writing BornAgain native IntensityData from ASCII file.
+namespace IO {
 
-class ReadWriteINT {
-public:
-    static Datafield* readDatafield(std::istream& input_stream);
-    static void writeDatafield(const Datafield& data, std::ostream& output_stream);
-};
+//! Write Datafield as BornAgain intensity ASCII file.
+Datafield* readBAInt(std::istream& input_stream);
+//! Read Datafield from BornAgain intensity ASCII file.
+void writeBAInt(const Datafield& data, std::ostream& output_stream);
+
+}; // namespace IO
 
 #endif // BORNAGAIN_DEVICE_IO_READWRITEINT_H
diff --git a/GUI/Model/Axis/PointwiseAxisItem.cpp b/GUI/Model/Axis/PointwiseAxisItem.cpp
index f52622670f9..4fb9fa79146 100644
--- a/GUI/Model/Axis/PointwiseAxisItem.cpp
+++ b/GUI/Model/Axis/PointwiseAxisItem.cpp
@@ -76,7 +76,7 @@ QByteArray PointwiseAxisItem::serializeBinaryData() const
     Datafield axisData({m_axis->clone()});
 
     std::stringstream ss;
-    ReadWriteINT().writeDatafield(axisData, ss);
+    IO::writeBAInt(axisData, ss);
     return QByteArray(ss.str().c_str(), static_cast<int>(ss.str().size()));
 }
 
@@ -86,7 +86,7 @@ void PointwiseAxisItem::deserializeBinaryData(const QByteArray& data)
         return;
 
     std::istringstream str(data.toStdString());
-    std::unique_ptr<Datafield> d(ReadWriteINT().readDatafield(str));
+    std::unique_ptr<Datafield> d(IO::readBAInt(str));
     m_axis = std::unique_ptr<Scale>(d->axis(0).clone());
 }
 
diff --git a/Tests/Unit/Device/IOReaderWriterTest.cpp b/Tests/Unit/Device/IOReaderWriterTest.cpp
index 5ec6931efea..357dae82154 100644
--- a/Tests/Unit/Device/IOReaderWriterTest.cpp
+++ b/Tests/Unit/Device/IOReaderWriterTest.cpp
@@ -21,10 +21,9 @@ protected:
 TEST_F(IOReaderWriterTest, TestRWINT)
 {
     std::stringstream ss;
-    ReadWriteINT write_int;
-    write_int.writeDatafield(m_model_data, ss);
-    ReadWriteINT read_int;
-    auto result = std::unique_ptr<Datafield>(read_int.readDatafield(ss));
+    IO::writeBAInt(m_model_data, ss);
+
+    auto result = std::unique_ptr<Datafield>(IO::readBAInt(ss));
 
     auto compare_axis = [this, &result](size_t index) {
         EXPECT_EQ(m_model_data.axis(index).size(), result->axis(index).size());
-- 
GitLab