From 4c16856787b344e91498b62d3b80f5c9b2a74f99 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Wed, 10 May 2023 22:01:52 +0200
Subject: [PATCH] mv fcts to local ns

---
 Device/IO/DataFormatUtil.cpp          | 33 ----------------------
 Device/IO/DataFormatUtil.h            | 11 --------
 Device/IO/IOFactory.cpp               | 40 +++++++++++++++++++++++----
 Device/IO/IOFactory.h                 |  1 +
 GUI/View/Import/ImportDataUtil.cpp    |  6 ++--
 auto/Wrap/libBornAgainDevice.py       |  4 +++
 auto/Wrap/libBornAgainDevice_wrap.cpp | 31 +++++++++++++++++++++
 7 files changed, 73 insertions(+), 53 deletions(-)

diff --git a/Device/IO/DataFormatUtil.cpp b/Device/IO/DataFormatUtil.cpp
index ea382ba5eb0..fd0278293d9 100644
--- a/Device/IO/DataFormatUtil.cpp
+++ b/Device/IO/DataFormatUtil.cpp
@@ -24,13 +24,6 @@
 
 namespace {
 
-const std::string GzipExtension = ".gz";
-const std::string BzipExtension = ".bz2";
-const std::string IntExtension = ".int";
-const std::string NicosExtension = ".001";
-const std::string TiffExtension = ".tif";
-const std::string TiffExtension2 = ".tiff";
-
 std::istringstream getAxisStringRepresentation(std::istream& input_stream)
 {
     std::string line;
@@ -49,32 +42,6 @@ void readLineOfDoubles(std::vector<double>& buffer, std::istringstream& iss)
 
 } // namespace
 
-std::string DataUtil::Format::uncompressedFilename(const std::string& name)
-{
-    if (DataUtil::Format::isGZipped(name))
-        return name.substr(0, name.size() - GzipExtension.size());
-    if (DataUtil::Format::isBZipped(name))
-        return name.substr(0, name.size() - BzipExtension.size());
-    return name;
-}
-
-bool DataUtil::Format::isCompressed(const std::string& name)
-{
-    return isGZipped(name) || isBZipped(name);
-}
-
-//! Does name contain *.gz extension?
-
-bool DataUtil::Format::isGZipped(const std::string& name)
-{
-    return Util::Path::hasExtension(name, GzipExtension);
-}
-
-bool DataUtil::Format::isBZipped(const std::string& name)
-{
-    return Util::Path::hasExtension(name, BzipExtension);
-}
-
 //! Creates axis of certain type from input stream
 Scale* DataUtil::Format::parseScale(std::istream& input_stream)
 {
diff --git a/Device/IO/DataFormatUtil.h b/Device/IO/DataFormatUtil.h
index eaa236b9578..5b7375bbed1 100644
--- a/Device/IO/DataFormatUtil.h
+++ b/Device/IO/DataFormatUtil.h
@@ -28,17 +28,6 @@ class Datafield;
 
 namespace DataUtil::Format {
 
-std::string uncompressedFilename(const std::string& name);
-
-//! Returns true if name contains *.gz extension
-bool isCompressed(const std::string& name);
-
-//! Returns true if name contains *.gz extension
-bool isGZipped(const std::string& name);
-
-//! Returns true if name contains *.bz2 extension
-bool isBZipped(const std::string& name);
-
 Scale* parseScale(std::istream& input_stream);
 
 void fillDatafield(Datafield* data, std::istream& input_stream);
diff --git a/Device/IO/IOFactory.cpp b/Device/IO/IOFactory.cpp
index 6a1284dcace..1114906eb88 100644
--- a/Device/IO/IOFactory.cpp
+++ b/Device/IO/IOFactory.cpp
@@ -44,10 +44,32 @@
 
 namespace {
 
+const std::string GzipExtension = ".gz";
+const std::string BzipExtension = ".bz2";
+
+bool isGZipped(const std::string& name)
+{
+    return Util::Path::hasExtension(name, GzipExtension);
+}
+
+bool isBZipped(const std::string& name)
+{
+    return Util::Path::hasExtension(name, BzipExtension);
+}
+
+std::string uncompressedFilename(const std::string& name)
+{
+    if (isGZipped(name))
+        return name.substr(0, name.size() - GzipExtension.size());
+    if (isBZipped(name))
+        return name.substr(0, name.size() - BzipExtension.size());
+    return name;
+}
+
 bool is_binary(const std::string& file_name)
 {
     const IO::Filetype ftype = IO::filename2type(file_name);
-    return ftype == IO::tiff || DataUtil::Format::isCompressed(file_name);
+    return ftype == IO::tiff || IO::isCompressed(file_name);
 }
 
 std::stringstream file2stream(const std::string& file_name)
@@ -73,9 +95,9 @@ std::stringstream file2stream(const std::string& file_name)
         throw std::runtime_error("File is not good, probably it is a directory:" + file_name);
 
     boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered;
-    if (DataUtil::Format::isGZipped(file_name))
+    if (::isGZipped(file_name))
         input_filtered.push(boost::iostreams::gzip_decompressor());
-    else if (DataUtil::Format::isBZipped(file_name))
+    else if (::isBZipped(file_name))
         input_filtered.push(boost::iostreams::bzip2_decompressor());
     input_filtered.push(input_stream);
     // we use stringstream since it provides random access which is important for tiff files
@@ -106,9 +128,9 @@ void stream2file(const std::string& file_name, std::stringstream& s)
         throw std::runtime_error("File is not good, probably it is a directory: " + file_name);
 
     boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered;
-    if (DataUtil::Format::isGZipped(file_name))
+    if (::isGZipped(file_name))
         input_filtered.push(boost::iostreams::gzip_compressor());
-    else if (DataUtil::Format::isBZipped(file_name))
+    else if (::isBZipped(file_name))
         input_filtered.push(boost::iostreams::bzip2_compressor());
     input_filtered.push(s);
 
@@ -119,9 +141,15 @@ void stream2file(const std::string& file_name, std::stringstream& s)
 
 } // namespace
 
+bool IO::isCompressed(const std::string& name)
+{
+    return isGZipped(name) || isBZipped(name);
+}
+
+
 IO::Filetype IO::filename2type(const std::string& filename)
 {
-    std::string s = DataUtil::Format::uncompressedFilename(filename);
+    std::string s = ::uncompressedFilename(filename);
     s = Util::Path::extension(s);
     s = BaseUtil::String::to_lower(s);
 
diff --git a/Device/IO/IOFactory.h b/Device/IO/IOFactory.h
index b68cc18ead7..d02bd4f88dc 100644
--- a/Device/IO/IOFactory.h
+++ b/Device/IO/IOFactory.h
@@ -23,6 +23,7 @@ namespace IO {
 
 enum Filetype { nil, bornagain, tiff, nicos, mft };
 
+bool isCompressed(const std::string& name);
 Filetype filename2type(const std::string& filename);
 
 //! Reads 1D data file and returns newly created Datafield object.
diff --git a/GUI/View/Import/ImportDataUtil.cpp b/GUI/View/Import/ImportDataUtil.cpp
index 4ab30bc1380..9af1cef7d2e 100644
--- a/GUI/View/Import/ImportDataUtil.cpp
+++ b/GUI/View/Import/ImportDataUtil.cpp
@@ -64,7 +64,7 @@ QString GUI::View::ImportDataUtil::Import1dData(RealItem* realItem,
 
     if (selectedLoader == nullptr) {
         IO::Filetype filetype = IO::filename2type(fileNameStdString);
-        if (DataUtil::Format::isCompressed(fileNameStdString) || filetype == IO::bornagain
+        if (IO::isCompressed(fileNameStdString) || filetype == IO::bornagain
             || filetype == IO::tiff) {
             try {
                 ImportDataInfo info(ImportKnownData(fileName), Coords::QSPACE);
@@ -74,7 +74,7 @@ QString GUI::View::ImportDataUtil::Import1dData(RealItem* realItem,
                 }
             } catch (std::exception& ex) {
                 // Try with CSV import ? TODO check the logic, simplify
-                if (filetype != IO::bornagain || DataUtil::Format::isCompressed(fileNameStdString))
+                if (filetype != IO::bornagain || IO::isCompressed(fileNameStdString))
                     // import is not possible
                     return QString::fromLatin1(ex.what());
             }
@@ -94,7 +94,7 @@ QString GUI::View::ImportDataUtil::Import1dData(RealItem* realItem,
     if (fileContent.isEmpty())
         return "The imported file is empty.";
 
-    if (DataUtil::Format::isCompressed(fileNameStdString)) {
+    if (IO::isCompressed(fileNameStdString)) {
         // #baimport implement decompress
     }
 
diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py
index 8c86db8914a..26864d5ff40 100644
--- a/auto/Wrap/libBornAgainDevice.py
+++ b/auto/Wrap/libBornAgainDevice.py
@@ -3000,6 +3000,10 @@ nicos = _libBornAgainDevice.nicos
 mft = _libBornAgainDevice.mft
 
 
+def isCompressed(name):
+    r"""isCompressed(std::string const & name) -> bool"""
+    return _libBornAgainDevice.isCompressed(name)
+
 def filename2type(filename):
     r"""filename2type(std::string const & filename) -> IO::Filetype"""
     return _libBornAgainDevice.filename2type(filename)
diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp
index 3176f9e55aa..1db2a529513 100644
--- a/auto/Wrap/libBornAgainDevice_wrap.cpp
+++ b/auto/Wrap/libBornAgainDevice_wrap.cpp
@@ -36182,6 +36182,36 @@ SWIGINTERN PyObject *SphericalDetector_swiginit(PyObject *SWIGUNUSEDPARM(self),
   return SWIG_Python_InitShadowInstance(args);
 }
 
+SWIGINTERN PyObject *_wrap_isCompressed(PyObject *self, PyObject *args) {
+  PyObject *resultobj = 0;
+  std::string *arg1 = 0 ;
+  int res1 = SWIG_OLDOBJ ;
+  PyObject *swig_obj[1] ;
+  bool result;
+  
+  if (!args) SWIG_fail;
+  swig_obj[0] = args;
+  {
+    std::string *ptr = (std::string *)0;
+    res1 = SWIG_AsPtr_std_string(swig_obj[0], &ptr);
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "isCompressed" "', argument " "1"" of type '" "std::string const &""'"); 
+    }
+    if (!ptr) {
+      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "isCompressed" "', argument " "1"" of type '" "std::string const &""'"); 
+    }
+    arg1 = ptr;
+  }
+  result = (bool)IO::isCompressed((std::string const &)*arg1);
+  resultobj = SWIG_From_bool(static_cast< bool >(result));
+  if (SWIG_IsNewObj(res1)) delete arg1;
+  return resultobj;
+fail:
+  if (SWIG_IsNewObj(res1)) delete arg1;
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_filename2type(PyObject *self, PyObject *args) {
   PyObject *resultobj = 0;
   std::string *arg1 = 0 ;
@@ -38292,6 +38322,7 @@ static PyMethodDef SwigMethods[] = {
 	 { "SphericalDetector_indexOfSpecular", _wrap_SphericalDetector_indexOfSpecular, METH_VARARGS, "SphericalDetector_indexOfSpecular(SphericalDetector self, Beam beam) -> size_t"},
 	 { "SphericalDetector_swigregister", SphericalDetector_swigregister, METH_O, NULL},
 	 { "SphericalDetector_swiginit", SphericalDetector_swiginit, METH_VARARGS, NULL},
+	 { "isCompressed", _wrap_isCompressed, METH_O, "isCompressed(std::string const & name) -> bool"},
 	 { "filename2type", _wrap_filename2type, METH_O, "filename2type(std::string const & filename) -> IO::Filetype"},
 	 { "readData1D", _wrap_readData1D, METH_VARARGS, "readData1D(std::string const & file_name, IO::Filetype selector=nil) -> Datafield"},
 	 { "readData2D", _wrap_readData2D, METH_VARARGS, "readData2D(std::string const & file_name, IO::Filetype selector=nil) -> Datafield"},
-- 
GitLab