CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
h5_content_base.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_h5_content_base_cc_h__
13#define __cxz_h5_content_base_cc_h__
14
15#include "h5_content_base.h"
16
17namespace CNORXZ
18{
19 namespace hdf5
20 {
21 namespace
22 {
23
24 template <typename T>
25 struct CreateAttribute
26 {
27 static inline herr_t write(hid_t id, const String& name, const T& v)
28 {
29 CXZ_ERROR("type " << typeid(v).name() << " not supported (name "
30 << name << ", id = " << id << ")");
31 return 0;
32 }
33 };
34
35 template <>
36 struct CreateAttribute<Int>
37 {
38 static inline herr_t write(hid_t id, const String& name, const Int& v)
39 {
40 const hsize_t dim = 1;
43 const hid_t attr_id = H5Acreate(id, name.c_str(), type_id, space_id, H5P_DEFAULT,
45 const herr_t err = H5Awrite(attr_id, type_id, &v);
49 return err;
50 }
51 };
52
53 template <>
54 struct CreateAttribute<Double>
55 {
56 static inline herr_t write(hid_t id, const String& name, const Double& v)
57 {
58 const hsize_t dim = 1;
61 const hid_t attr_id = H5Acreate(id, name.c_str(), type_id, space_id, H5P_DEFAULT,
63 const herr_t err = H5Awrite(attr_id, type_id, &v);
67 return err;
68 }
69 };
70
71 template <>
72 struct CreateAttribute<String>
73 {
74 static inline herr_t write(hid_t id, const String& name, const String& v)
75 {
76 const hsize_t len = v.size();
79 const hid_t attr_id = H5Acreate(id, name.c_str(), type_id, space_id, H5P_DEFAULT,
81 const herr_t err = H5Awrite(attr_id, type_id, v.c_str());
85 return err;
86 }
87 };
88
89
90 template <typename T>
91 inline herr_t writeAttr(hid_t id, const String& name, const T& v)
92 {
93 return CreateAttribute<T>::write(id, name, v);
94 }
95 }
96
97 template <typename T>
98 ContentBase& ContentBase::addAttribute(const String& name, const T& value)
99 {
100 const herr_t err = writeAttr(mId, name, value);
101 CXZ_ASSERT(err >= 0, "error while writing attribute " << name);
102 return *this;
103 }
104
105 }
106}
107
108#endif
#define CXZ_ERROR(errmsg)
Definition assert.h:26
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
const String & name() const
ContentBase & addAttribute(const String &name, const T &value)
Abstract content base class declaration.
std::string String
Definition types.h:42
double Double
Definition types.h:39
int32_t Int
Definition types.h:36
Sptr< Range > rangeCast(const RangePtr r)