CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
h5_content_base.cc
Go to the documentation of this file.
1// -*- C++ -*-
14#include "h5_content_base.h"
15
16namespace CNORXZ
17{
18 namespace hdf5
19 {
21 mName(_name), mParent(_parent)
22 {}
23
25 {
26 return mName;
27 }
28
30 {
31 return mParent;
32 }
33
35 {
36 return mId;
37 }
38
40 {
41 return mId != 0;
42 }
43
45 {
46 CXZ_ASSERT(attributeExists(name), "no attribute with name '" << name
47 << "' in object " << mName);
48 const hid_t attr = H5Aopen(mId, name.c_str(), H5P_DEFAULT);
49 CXZ_ASSERT(attr != H5I_INVALID_HID, "error while reading attribute " << name);
52 "error while determining type of attribute " << name);
53
55 DType o;
56 switch(tc){
57 case H5T_INTEGER: {
58 Int v;
60 o = DType(v);
61 break;
62 }
63 case H5T_FLOAT: {
64 Double v;
66 o = DType(v);
67 break;
68 }
69 case H5T_STRING: {
72 H5Aread(attr, atype_id, v.data());
73 o = DType( String( v.data() ) );
74 break;
75 }
76 case H5T_ARRAY: {
78 CXZ_ASSERT(ndims, "array of dimension " << ndims << " not supported");
83 switch(atc){
84 case H5T_INTEGER: {
86 H5Aread(attr, atype_id, v.data());
87 o = DType(v);
88 break;
89 }
90 case H5T_FLOAT: {
92 H5Aread(attr, atype_id, v.data());
93 o = DType(v);
94 break;
95 }
96 default:
97 CXZ_ERROR("attribute type id " << atype_id << " not supported");
98 }
100 break;
101 }
102 default:
103 CXZ_ERROR("attribute type id " << atype_id << " not supported");
104 }
105
107 H5Aclose(attr);
108 return o;
109 }
110
111 bool ContentBase::attributeExists(const String& name) const
112 {
113 CXZ_ASSERT(isOpen(), "tried to get attribute of closed object");
114 const htri_t ret = H5Aexists(mId, name.c_str());
115 CXZ_ASSERT(ret > 0, "error while reading attribute " << name);
116 return ret;
117 }
118
119 std::map<String,DType> ContentBase::getAttributes() const
120 {
121 CXZ_ASSERT(isOpen(), "tried to get attribute of closed object");
122 struct ItData
123 {
124 std::map<String,DType> d;
125 const ContentBase* _this;
126 } itdata;
127 itdata._this = this;
128 auto itop = [](hid_t loc_id, const char *attr_name,
129 const H5A_info_t* ainfo, void *op_data)
130 {
131 ItData* x = reinterpret_cast<ItData*>(op_data);
132 const String n = attr_name;
133 x->d[n] = x->_this->getAttribute( String(attr_name) );
134 return static_cast<herr_t>(0);
135 };
137 itop, &itdata);
138 return itdata.d;
139 }
140
141 std::map<String,DType> ContentBase::getRecursiveAttributes() const
142 {
143 std::map<String,DType> out = getAttributes();
144 if(mParent){
145 std::map<String,DType> par = mParent->getRecursiveAttributes();
146 out.insert(par.begin(), par.end());
147 }
148 return out;
149 }
150 }
151}
#define CXZ_ERROR(errmsg)
Definition assert.h:26
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
const ContentBase * parent() const
const String & name() const
std::map< String, DType > getAttributes() const
ContentBase(const String &_name, const ContentBase *_parent=nullptr)
bool attributeExists(const String &name) const
std::map< String, DType > getRecursiveAttributes() const
const ContentBase * mParent
DType getAttribute(const String &name) const
Abstract content base class declaration.
std::string String
Definition types.h:42
double Double
Definition types.h:39
uint64_t SizeT
Definition types.h:38
std::vector< T, Allocator< T > > Vector
Definition types.h:310
int32_t Int
Definition types.h:36
Sptr< Range > rangeCast(const RangePtr r)