From 022593873553afdc47abf9443597e2f4d36bd671 Mon Sep 17 00:00:00 2001 From: Matthew Marine Date: Fri, 19 Apr 2024 07:14:00 -0400 Subject: [PATCH 1/2] Fix HDF5 implicit copy * Delete copy constructors in HDF5 parsing classes. * Fixed DatasetIO move constructor. #fixes 916 --- src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.hpp | 6 ++++++ src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.cpp | 2 +- src/simplnx/Utilities/Parsing/HDF5/IO/FileIO.hpp | 5 +++++ src/simplnx/Utilities/Parsing/HDF5/IO/GroupIO.hpp | 6 ++++++ src/simplnx/Utilities/Parsing/HDF5/IO/ObjectIO.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Readers/AttributeReader.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Readers/DatasetReader.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Readers/FileReader.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Readers/GroupReader.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Readers/ObjectReader.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Writers/AttributeWriter.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp | 2 ++ .../Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Writers/FileWriter.hpp | 9 +++++++++ .../Utilities/Parsing/HDF5/Writers/GroupWriter.hpp | 6 ++++++ .../Utilities/Parsing/HDF5/Writers/ObjectWriter.hpp | 6 ++++++ 16 files changed, 89 insertions(+), 1 deletion(-) diff --git a/src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.hpp b/src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.hpp index 25f65aca87..fd39167246 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.hpp @@ -37,6 +37,9 @@ class SIMPLNX_EXPORT AttributeIO */ AttributeIO(IdType objectId, const std::string& attrName); + AttributeIO(const AttributeIO& other) = delete; + AttributeIO(AttributeIO&& other) noexcept = default; + /** * @brief Releases the wrapped HDF5 attribute. */ @@ -164,6 +167,9 @@ class SIMPLNX_EXPORT AttributeIO template Result<> writeVector(const DimsVector& dims, const std::vector& vector); + AttributeIO& operator=(const AttributeIO& other) = delete; + AttributeIO& operator=(AttributeIO&& other) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. diff --git a/src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.cpp b/src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.cpp index a38bc69b07..82f2b0a16d 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.cpp +++ b/src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.cpp @@ -24,7 +24,7 @@ DatasetIO::DatasetIO(IdType parentId, const std::string& datasetName) } DatasetIO::DatasetIO(DatasetIO&& other) noexcept -: ObjectIO(other) +: ObjectIO(std::move(other)) , m_DatasetName(std::move(other.m_DatasetName)) { } diff --git a/src/simplnx/Utilities/Parsing/HDF5/IO/FileIO.hpp b/src/simplnx/Utilities/Parsing/HDF5/IO/FileIO.hpp index 4d574baa8f..cd8402f6e9 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/IO/FileIO.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/IO/FileIO.hpp @@ -61,6 +61,8 @@ class SIMPLNX_EXPORT FileIO : public GroupIO */ FileIO(IdType fileId); + FileIO(const FileIO& rhs) = delete; + /** * @brief Move constructor. * @param rhs @@ -79,6 +81,9 @@ class SIMPLNX_EXPORT FileIO : public GroupIO */ std::string getName() const override; + FileIO& operator=(const FileIO& rhs) = delete; + FileIO& operator=(FileIO&& rhs) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. diff --git a/src/simplnx/Utilities/Parsing/HDF5/IO/GroupIO.hpp b/src/simplnx/Utilities/Parsing/HDF5/IO/GroupIO.hpp index e98d1efc8d..dfd7e5a581 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/IO/GroupIO.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/IO/GroupIO.hpp @@ -21,6 +21,9 @@ class SIMPLNX_EXPORT GroupIO : public ObjectIO */ GroupIO(IdType parentId, const std::string& groupName); + GroupIO(const GroupIO& other) = delete; + GroupIO(GroupIO&& other) noexcept = default; + /** * @brief Releases the wrapped HDF5 group. */ @@ -135,6 +138,9 @@ class SIMPLNX_EXPORT GroupIO : public ObjectIO */ bool isDataset(const std::string& childName) const; + GroupIO& operator=(const GroupIO& other) = delete; + GroupIO& operator=(GroupIO&& other) noexcept = default; + protected: /** * @brief Constructs a GroupWriter for use in derived classes. This diff --git a/src/simplnx/Utilities/Parsing/HDF5/IO/ObjectIO.hpp b/src/simplnx/Utilities/Parsing/HDF5/IO/ObjectIO.hpp index 5cd1d010f7..713a79e56c 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/IO/ObjectIO.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/IO/ObjectIO.hpp @@ -26,6 +26,9 @@ class SIMPLNX_EXPORT ObjectIO */ ObjectIO(IdType parentId, const std::string& targetName); + ObjectIO(const ObjectIO& other) = delete; + ObjectIO(ObjectIO&& other) noexcept = default; + /** * @brief Releases the wrapped HDF5 object. */ @@ -128,6 +131,9 @@ class SIMPLNX_EXPORT ObjectIO */ AttributeIO createAttribute(const std::string& name); + ObjectIO& operator=(const ObjectIO& other) = delete; + ObjectIO& operator=(ObjectIO&& other) noexcept = default; + protected: /** * @brief Constructs an ObjectIO for use in derived classes. This diff --git a/src/simplnx/Utilities/Parsing/HDF5/Readers/AttributeReader.hpp b/src/simplnx/Utilities/Parsing/HDF5/Readers/AttributeReader.hpp index bb125aa18e..1b16287871 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Readers/AttributeReader.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Readers/AttributeReader.hpp @@ -36,6 +36,9 @@ class SIMPLNX_EXPORT AttributeReader */ AttributeReader(IdType objectId, const std::string& attrName); + AttributeReader(const AttributeReader& other) = delete; + AttributeReader(AttributeReader&& other) noexcept = default; + /** * @brief Releases the wrapped HDF5 attribute. */ @@ -146,6 +149,9 @@ class SIMPLNX_EXPORT AttributeReader */ std::string readAsString() const; + AttributeReader& operator=(const AttributeReader& other) = delete; + AttributeReader& operator=(AttributeReader&& other) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. diff --git a/src/simplnx/Utilities/Parsing/HDF5/Readers/DatasetReader.hpp b/src/simplnx/Utilities/Parsing/HDF5/Readers/DatasetReader.hpp index a813b89d78..53e2e2905b 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Readers/DatasetReader.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Readers/DatasetReader.hpp @@ -27,6 +27,9 @@ class SIMPLNX_EXPORT DatasetReader : public ObjectReader */ DatasetReader(IdType parentId, const std::string& dataName); + DatasetReader(const DatasetReader& other) = delete; + DatasetReader(DatasetReader&& other) noexcept = default; + /** * @brief Releases the HDF5 dataset. */ @@ -122,6 +125,9 @@ class SIMPLNX_EXPORT DatasetReader : public ObjectReader std::string getFilterName() const; + DatasetReader& operator=(const DatasetReader& other) = delete; + DatasetReader& operator=(DatasetReader&& other) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. diff --git a/src/simplnx/Utilities/Parsing/HDF5/Readers/FileReader.hpp b/src/simplnx/Utilities/Parsing/HDF5/Readers/FileReader.hpp index 0c36f497a1..2b2c13b029 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Readers/FileReader.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Readers/FileReader.hpp @@ -26,6 +26,9 @@ class SIMPLNX_EXPORT FileReader : public GroupReader */ FileReader(IdType fileId); + FileReader(const FileReader& other) = delete; + FileReader(FileReader&& other) noexcept = default; + /** * @brief Releases the HDF5 file ID. */ @@ -38,6 +41,9 @@ class SIMPLNX_EXPORT FileReader : public GroupReader */ std::string getName() const override; + FileReader& operator=(const FileReader& other) = delete; + FileReader& operator=(FileReader&& other) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. diff --git a/src/simplnx/Utilities/Parsing/HDF5/Readers/GroupReader.hpp b/src/simplnx/Utilities/Parsing/HDF5/Readers/GroupReader.hpp index ee62309de1..9d1e5e0804 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Readers/GroupReader.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Readers/GroupReader.hpp @@ -19,6 +19,9 @@ class SIMPLNX_EXPORT GroupReader : public ObjectReader */ GroupReader(IdType parentId, const std::string& groupName); + GroupReader(const GroupReader& other) = delete; + GroupReader(GroupReader&& other) noexcept = default; + /** * @brief Releases the wrapped HDF5 group. */ @@ -87,6 +90,9 @@ class SIMPLNX_EXPORT GroupReader : public ObjectReader */ bool isDataset(const std::string& childName) const; + GroupReader& operator=(const GroupReader& other) = delete; + GroupReader& operator=(GroupReader&& other) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. diff --git a/src/simplnx/Utilities/Parsing/HDF5/Readers/ObjectReader.hpp b/src/simplnx/Utilities/Parsing/HDF5/Readers/ObjectReader.hpp index 440e6c4d37..e5996e76f2 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Readers/ObjectReader.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Readers/ObjectReader.hpp @@ -24,6 +24,9 @@ class SIMPLNX_EXPORT ObjectReader */ ObjectReader(IdType parentId, const std::string& targetName); + ObjectReader(const ObjectReader& other) = delete; + ObjectReader(ObjectReader&& other) noexcept = default; + /** * @brief Releases the wrapped HDF5 object. */ @@ -96,6 +99,9 @@ class SIMPLNX_EXPORT ObjectReader */ AttributeReader getAttributeByIdx(size_t idx) const; + ObjectReader& operator=(const ObjectReader& other) = delete; + ObjectReader& operator=(ObjectReader&& other) noexcept = default; + protected: /** * @brief Constructs an ObjectReader for use in derived classes. This diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/AttributeWriter.hpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/AttributeWriter.hpp index 8f110b5eac..2662a6c1c7 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/AttributeWriter.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/AttributeWriter.hpp @@ -31,6 +31,9 @@ class SIMPLNX_EXPORT AttributeWriter */ AttributeWriter(IdType objectId, const std::string& attributeName); + AttributeWriter(const AttributeWriter& other) = delete; + AttributeWriter(AttributeWriter&& other) noexcept = default; + /** * @brief Default destructor */ @@ -204,6 +207,9 @@ class SIMPLNX_EXPORT AttributeWriter return returnError; } + AttributeWriter& operator=(const AttributeWriter& other) = delete; + AttributeWriter& operator=(AttributeWriter&& other) noexcept = default; + protected: /** * @brief Finds and deletes any existing attribute with the current name. diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp index 8d57584c5c..0d6df38366 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp @@ -27,6 +27,8 @@ DatasetWriter::DatasetWriter(IdType parentId, const std::string& datasetName) #endif } +DatasetWriter::DatasetWriter(DatasetWriter&& other) noexcept = default; + DatasetWriter::~DatasetWriter() { closeHdf5(); diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp index 32c6e92c8f..d6633126bb 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp @@ -28,6 +28,9 @@ class SIMPLNX_EXPORT DatasetWriter : public ObjectWriter */ DatasetWriter(IdType parentId, const std::string& datasetName); + DatasetWriter(const DatasetWriter& other) = delete; + DatasetWriter(DatasetWriter&& other) noexcept; + /** * @brief Default destructor */ @@ -203,6 +206,9 @@ class SIMPLNX_EXPORT DatasetWriter : public ObjectWriter */ IdType getPListId() const; + DatasetWriter& operator=(const DatasetWriter& other) = delete; + DatasetWriter& operator=(DatasetWriter&& other) noexcept = default; + protected: /** * @brief Finds and deletes any existing attribute with the current name. diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/FileWriter.hpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/FileWriter.hpp index ee96bb7953..87e317b8d3 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/FileWriter.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/FileWriter.hpp @@ -36,6 +36,12 @@ class SIMPLNX_EXPORT FileWriter : public GroupWriter */ FileWriter(); + /** + * @brief Copy constructor. + * @param rhs + */ + FileWriter(const FileWriter& rhs) = delete; + /** * @brief Move constructor. * @param rhs @@ -54,6 +60,9 @@ class SIMPLNX_EXPORT FileWriter : public GroupWriter */ std::string getName() const override; + FileWriter& operator=(const FileWriter& rhs) = delete; + FileWriter& operator=(FileWriter&& rhs) noexcept = default; + protected: /** * @brief Constructs a FileWriter that creates and wraps an HDF5 file at the diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/GroupWriter.hpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/GroupWriter.hpp index d4e7c5dfa5..b83129b7d5 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/GroupWriter.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/GroupWriter.hpp @@ -24,6 +24,9 @@ class SIMPLNX_EXPORT GroupWriter : public ObjectWriter */ GroupWriter(IdType parentId, const std::string& objectName); + GroupWriter(const GroupWriter& other) = delete; + GroupWriter(GroupWriter&& other) noexcept = default; + /** * @brief Closes the HDF5 group. */ @@ -62,6 +65,9 @@ class SIMPLNX_EXPORT GroupWriter : public ObjectWriter */ Result<> createLink(const std::string& objectPath); + GroupWriter& operator=(const GroupWriter& other) = delete; + GroupWriter& operator=(GroupWriter&& other) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/ObjectWriter.hpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/ObjectWriter.hpp index 51221f82ae..c1dcbf4fc4 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/ObjectWriter.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/ObjectWriter.hpp @@ -25,6 +25,9 @@ class SIMPLNX_EXPORT ObjectWriter */ ObjectWriter(IdType parentId, IdType objectId = 0); + ObjectWriter(const ObjectWriter& other) = delete; + ObjectWriter(ObjectWriter&& other) noexcept = default; + /** * @brief Releases the wrapped HDF5 object. */ @@ -90,6 +93,9 @@ class SIMPLNX_EXPORT ObjectWriter */ AttributeWriter createAttribute(const std::string& name); + ObjectWriter& operator=(const ObjectWriter& other) = delete; + ObjectWriter& operator=(ObjectWriter&& other) noexcept = default; + protected: /** * @brief Closes the HDF5 ID and resets it to 0. From 7eb4deb59ddc132a63321b1f93a6d0fe231b313e Mon Sep 17 00:00:00 2001 From: Matthew Marine Date: Fri, 19 Apr 2024 14:27:23 -0400 Subject: [PATCH 2/2] Update DatasetWriter move constructor --- src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp | 2 -- src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp index 0d6df38366..8d57584c5c 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp @@ -27,8 +27,6 @@ DatasetWriter::DatasetWriter(IdType parentId, const std::string& datasetName) #endif } -DatasetWriter::DatasetWriter(DatasetWriter&& other) noexcept = default; - DatasetWriter::~DatasetWriter() { closeHdf5(); diff --git a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp index d6633126bb..7a36298be4 100644 --- a/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp +++ b/src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp @@ -29,7 +29,7 @@ class SIMPLNX_EXPORT DatasetWriter : public ObjectWriter DatasetWriter(IdType parentId, const std::string& datasetName); DatasetWriter(const DatasetWriter& other) = delete; - DatasetWriter(DatasetWriter&& other) noexcept; + DatasetWriter(DatasetWriter&& other) noexcept = default; /** * @brief Default destructor