From caed6b4469665e9c2ed722077a68975aae2bc093 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 13 Jan 2023 01:40:19 +0100 Subject: [PATCH] hdf5: group --- CMakeLists.txt | 6 ++ src/CMakeLists.txt | 4 ++ src/opt/hdf5/include/h5_content_base.h | 3 + src/opt/hdf5/include/h5_file.h | 1 - src/opt/hdf5/include/h5_group.h | 37 +++++++++++ src/opt/hdf5/lib/h5_content_base.cc | 5 ++ src/opt/hdf5/lib/h5_group.cc | 89 ++++++++++++++++++++++++++ 7 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/opt/hdf5/include/h5_group.h create mode 100644 src/opt/hdf5/lib/h5_group.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f77b8b..24e17db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,4 +36,10 @@ else() message(FATAL_ERROR "Threads not found") endif() +if(DEFINED ENABLE_hdf5) + set(ENABLE_hdf5 ${ENABLE_hdf5} CACHE BOOL "enable hdf5") +else() + set(ENABLE_hdf5 TRUE CACHE BOOL "enable hdf5") +endif() + add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 272d174..9e5567b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,4 +3,8 @@ include_directories(${CMAKE_SOURCE_DIR}/src/include) add_subdirectory(tests) add_subdirectory(lib) +#if(ENABLE_hdf5) +# add_subdirectory(opt/hdf5) +#endif() + install(DIRECTORY include/ DESTINATION ${INSTALL_PATH}/include) diff --git a/src/opt/hdf5/include/h5_content_base.h b/src/opt/hdf5/include/h5_content_base.h index 1256ac6..77580ff 100644 --- a/src/opt/hdf5/include/h5_content_base.h +++ b/src/opt/hdf5/include/h5_content_base.h @@ -3,6 +3,7 @@ #define __cxz_h5_content_base_h__ #include "cnorxz.h" +#include namespace CNORXZ { @@ -37,11 +38,13 @@ namespace CNORXZ const String& name() const; const ContentBase* parent() const; RangePtr range() const; + hid_t id() const; protected: String mName; const ContentBase* mParent = nullptr; RangePtr mRange; + hid_t mId = 0; }; } diff --git a/src/opt/hdf5/include/h5_file.h b/src/opt/hdf5/include/h5_file.h index f28d866..8e7146a 100644 --- a/src/opt/hdf5/include/h5_file.h +++ b/src/opt/hdf5/include/h5_file.h @@ -32,7 +32,6 @@ namespace CNORXZ private: bool mRo = true; - hid_t mId = 0; MArray mCont; }; } diff --git a/src/opt/hdf5/include/h5_group.h b/src/opt/hdf5/include/h5_group.h new file mode 100644 index 0000000..aa66864 --- /dev/null +++ b/src/opt/hdf5/include/h5_group.h @@ -0,0 +1,37 @@ + +#ifndef __cxz_h5_group_h__ +#define __cxz_h5_group_h__ + +#include "h5_content_base.h" + +namespace CNORXZ +{ + namespace hdf5 + { + class Group : public ContentBase + { + public: + DEFAULT_MEMBERS(Group); + Group(const String& gname, const ContentBase* _parent); + ~Group(); + + virtual ContentType type() const override final; + virtual bool ro() const override final; + virtual Group& load() override final; + virtual Group& close() override final; + virtual MArray* get() override final; + virtual const MArray* get() const override final; + virtual String path() const override final; + virtual String filename() const override final; + + bool exists() const; + Group& append(const ContentPtr& c); + + private: + MArray mCont; + }; + + } +} + +#endif diff --git a/src/opt/hdf5/lib/h5_content_base.cc b/src/opt/hdf5/lib/h5_content_base.cc index cbb4fba..686e2e6 100644 --- a/src/opt/hdf5/lib/h5_content_base.cc +++ b/src/opt/hdf5/lib/h5_content_base.cc @@ -23,5 +23,10 @@ namespace CNORXZ { return mRange; } + + hid_t ContentBase::id() const + { + return mId; + } } } diff --git a/src/opt/hdf5/lib/h5_group.cc b/src/opt/hdf5/lib/h5_group.cc new file mode 100644 index 0000000..d6242e0 --- /dev/null +++ b/src/opt/hdf5/lib/h5_group.cc @@ -0,0 +1,89 @@ + +#include "h5_group.h" + +namespace CNORXZ +{ + namespace hdf5 + { + Group::Group(const String& gname, const ContentBase* _parent) : + ContentBase(gname, _parent) + { + if(this->exists()){ + mId = H5Gopen( mParent->id(), mName.c_str(), H5P_DEFAULT ); + } + else { + mId = H5Gcreate( mParent->id(), mName.c_str(), + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ); + } + } + + Group::~Group() + { + if(mId != 0){ + H5Gclose(mId); + } + } + + ContentType Group::type() const + { + return ContentType::GROUP; + } + + bool Group::ro() const + { + if(mParent){ + return mParent->ro(); + } + return false; + } + + Group& Group::load() + { + // load content!!! + return *this; + } + + Group& Group::close() + { + return *this; + } + + MArray* Group::get() + { + return mCont; + } + + const MArray* Group::get() const + { + return mCont; + } + + String Group::path() const + { + if(mParent){ + return mParent->path() + "/" + this->name(); + } + return this->name(); + } + + String Group::filename() const + { + if(mParent){ + return mParent->filename(); + } + return String(); + } + + bool Group::exists() const + { + return H5Lexists(mParent->id(), mName.c_str(), H5P_DEFAULT) != 0; + } + + Group& Group::append(const ContentPtr& c) + { + + return *this; + } + + } +}