From 676b978dceef5488369fad79f936dee6dbc10c1c Mon Sep 17 00:00:00 2001 From: Oliver Ruebel Date: Tue, 3 Sep 2024 02:18:04 -0700 Subject: [PATCH] Add ReadDataWrapperBase as common base class for ReadDatasetWrapper and ReadAttributeWrapper --- src/BaseIO.hpp | 104 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 71 insertions(+), 33 deletions(-) diff --git a/src/BaseIO.hpp b/src/BaseIO.hpp index 83baa56d..fbef79bf 100644 --- a/src/BaseIO.hpp +++ b/src/BaseIO.hpp @@ -507,21 +507,68 @@ class BaseIO }; /** - * @brief The base class for reading data from a dataset in a file + * @brief The base class for wrapping data objects for reading data from a file */ -class ReadDatasetWrapper +class ReadDataWrapperBase { public: /** * @brief Default constructor. */ - ReadDatasetWrapper(const std::shared_ptr io, // BaseIO* io, - std::string dataPath) + ReadDataWrapperBase(const std::shared_ptr io, std::string dataPath) : io(io) , dataPath(dataPath) { } + /** + * @brief Deleted copy constructor to prevent construction-copying. + */ + ReadDataWrapperBase(const ReadDataWrapperBase&) = delete; + + /** + * @brief Deleted copy assignment operator to prevent copying. + */ + ReadDataWrapperBase& operator=(const ReadDataWrapperBase&) = delete; + + /** + * @brief Destructor. + */ + virtual ~ReadDataWrapperBase() {} + + /** + * @brief Reads an attribute or dataset and determines the data type to + * allocate the memory + * + * @return An DataBlockGeneric structure containing the data and shape. + */ + virtual DataBlockGeneric valuesGeneric() = 0; + +protected: + /** + * @brief Pointer to the I/O object to use for reading. + */ + const std::shared_ptr io; // BaseIO* io; + /** + * @brief Path to the dataset or attribute to read + */ + std::string dataPath; +}; + +/** + * @brief Wrapper class for lazily reading data from a dataset in a file + */ +class ReadDatasetWrapper : public ReadDataWrapperBase +{ +public: + /** + * @brief Default constructor. + */ + ReadDatasetWrapper(const std::shared_ptr io, std::string dataPath) + : ReadDataWrapperBase(io, dataPath) + { + } + /** * @brief Deleted copy constructor to prevent construction-copying. */ @@ -538,16 +585,28 @@ class ReadDatasetWrapper virtual ~ReadDatasetWrapper() {} /** - * @brief Reads an dataset or attribute and determines the data type. + * @brief Reads a dataset and determines the data type. * - * @param start The starting indices for the slice (optional). + * This functions calls the overloaded valuesGeneric({}, {}, {}, {}) variant + * + * @return An DataBlockGeneric structure containing the data and shape. + */ + DataBlockGeneric valuesGeneric() override + { + return this->valuesGeneric({}, {}, {}, {}); + } + + /** + * @brief Reads a dataset and determines the data type. + * + * @param start The starting indices for the slice (required). * @param count The number of elements to read for each dimension (optional). * @param stride The stride for each dimension (optional). * @param block The block size for each dimension (optional). * * @return An DataBlockGeneric structure containing the data and shape. */ - DataBlockGeneric valuesGeneric(const std::vector& start = {}, + DataBlockGeneric valuesGeneric(const std::vector& start, const std::vector& count = {}, const std::vector& stride = {}, const std::vector& block = {}) @@ -556,7 +615,7 @@ class ReadDatasetWrapper } /** - * @brief Reads an dataset or attribute with a specified data type. + * @brief Reads an dataset with a specified data type. * * This convenience function uses valuesGeneric to read the data and then * convert the DataBlockGeneric to a specific DataBlock @@ -578,30 +637,19 @@ class ReadDatasetWrapper this->valuesGeneric(start, count, stride, block)); } -private: - /** - * @brief Pointer to the I/O object to use for reading. - */ - const std::shared_ptr io; // BaseIO* io; - /** - * @brief Path to the dataset or attribute to read - */ - std::string dataPath; - }; // ReadDatasetWrapper /** - * @brief The base class for reading data from a dataset in a file + * @brief Wrapper class for lazily reading data from an attribute in a file */ -class ReadAttributeWrapper +class ReadAttributeWrapper : public ReadDataWrapperBase { public: /** * @brief Default constructor. */ ReadAttributeWrapper(const std::shared_ptr io, std::string dataPath) - : io(io) - , dataPath(dataPath) + : ReadDataWrapperBase(io, dataPath) { } @@ -625,7 +673,7 @@ class ReadAttributeWrapper * * @return An DataBlockGeneric structure containing the data and shape. */ - DataBlockGeneric valuesGeneric() + DataBlockGeneric valuesGeneric() override { return this->io->readAttribute(this->dataPath); } @@ -644,16 +692,6 @@ class ReadAttributeWrapper return DataBlock::fromGeneric(this->valuesGeneric()); } -private: - /** - * @brief Pointer to the I/O object to use for reading. - */ - const std::shared_ptr io; - /** - * @brief Path to the dataset or attribute to read - */ - std::string dataPath; - }; // ReadAttributeWrapper /**