From 438c3818cc90639899b808b7234926b001069b11 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Sat, 20 Mar 2021 21:59:06 +0100
Subject: [PATCH] [BL/IO] Provide read only access to data.

---
 Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp | 2 +-
 BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp           | 5 +++++
 BaseLib/IO/XmlIO/Qt/XMLQtInterface.h             | 9 +++++++--
 GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp           | 2 +-
 GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp           | 2 +-
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp
index 1265069a32d..88b82638c43 100644
--- a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp
+++ b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp
@@ -54,7 +54,7 @@ int XmlPrjInterface::readFile(const QString& fileName)
     QDomNode param_root = QDomNode();
     QDomNode pvar_root = QDomNode();
     QDomDocument doc("OGS-PROJECT-DOM");
-    doc.setContent(_fileData);
+    doc.setContent(getContent());
     QDomElement docElement = doc.documentElement();  // OpenGeoSysProject
     if (docElement.nodeName().compare("OpenGeoSysProject"))
     {
diff --git a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp
index 7ba8d894b8c..f413563fc09 100644
--- a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp
+++ b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp
@@ -129,5 +129,10 @@ bool XMLQtInterface::checkHash() const
     }
     return true;
 }
+
+QByteArray const& XMLQtInterface::getContent() const
+{
+    return _fileData;
+}
 }  // namespace IO
 }  // namespace BaseLib
diff --git a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h
index bc705948405..a6363a7bcea 100644
--- a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h
+++ b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h
@@ -41,8 +41,9 @@ protected:
     /// If no hash file exists, the xml-file is validated and a hash file is written if the xml-file was valid.
     bool checkHash() const;
 
-    /// Caches the actual file contents when reading.
-    QByteArray _fileData;
+    /// Read access to the content of the read file. Must be used after readFile
+    /// has been called.
+    QByteArray const& getContent() const;
 
 private:
     /// Check if the given xml-file is valid considering the schema-file used in
@@ -52,7 +53,11 @@ private:
 private:
     /// The actual file name when reading.
     QString _fileName;
+
     QString _schemaFile;
+
+    /// Caches the actual file contents when reading.
+    QByteArray _fileData;
 };
 
 } // end namespace IO
diff --git a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
index 292582cc8a3..b0274052f6d 100644
--- a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
+++ b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
@@ -71,7 +71,7 @@ int XmlGmlInterface::readFile(const QString &fileName)
     }
 
     QDomDocument doc("OGS-GLI-DOM");
-    doc.setContent(_fileData);
+    doc.setContent(getContent());
     QDomElement docElement = doc.documentElement(); //OpenGeoSysGLI
     if (docElement.nodeName().compare("OpenGeoSysGLI"))
     {
diff --git a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp
index 1b8283806f6..59e15aa4e11 100644
--- a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp
+++ b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp
@@ -44,7 +44,7 @@ int XmlStnInterface::readFile(const QString &fileName)
     }
 
     QDomDocument doc("OGS-STN-DOM");
-    doc.setContent(_fileData);
+    doc.setContent(getContent());
     QDomElement docElement = doc.documentElement(); //root element, used for identifying file-type
     if (docElement.nodeName().compare("OpenGeoSysSTN"))
     {
-- 
GitLab