hdf5: group

This commit is contained in:
Christian Zimmermann 2023-01-13 01:40:19 +01:00
parent 631d187c91
commit caed6b4469
7 changed files with 144 additions and 1 deletions

View file

@ -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)

View file

@ -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)

View file

@ -3,6 +3,7 @@
#define __cxz_h5_content_base_h__
#include "cnorxz.h"
#include <hdf5.h>
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;
};
}

View file

@ -32,7 +32,6 @@ namespace CNORXZ
private:
bool mRo = true;
hid_t mId = 0;
MArray<ContentPtr> mCont;
};
}

View file

@ -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<ContentBase>* get() override final;
virtual const MArray<ContentBase>* 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<ContentPtr> mCont;
};
}
}
#endif

View file

@ -23,5 +23,10 @@ namespace CNORXZ
{
return mRange;
}
hid_t ContentBase::id() const
{
return mId;
}
}
}

View file

@ -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<ContentBase>* Group::get()
{
return mCont;
}
const MArray<ContentBase>* 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;
}
}
}