CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
src
opt
hdf5
include
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
17
namespace
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;
41
const
hid_t
type_id
=
H5Tarray_create
(
H5T_NATIVE_INT
, 1, &dim);
42
const
hid_t
space_id
=
H5Screate
(
H5S_SCALAR
);
43
const
hid_t
attr_id
=
H5Acreate
(
id
, name.c_str(),
type_id
,
space_id
,
H5P_DEFAULT
,
44
H5P_DEFAULT
);
45
const
herr_t
err
=
H5Awrite
(
attr_id
,
type_id
, &
v
);
46
H5Aclose
(
attr_id
);
47
H5Sclose
(
space_id
);
48
H5Tclose
(
type_id
);
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;
59
const
hid_t
type_id
=
H5Tarray_create
(
H5T_NATIVE_DOUBLE
, 1, &dim);
60
const
hid_t
space_id
=
H5Screate
(
H5S_SCALAR
);
61
const
hid_t
attr_id
=
H5Acreate
(
id
, name.c_str(),
type_id
,
space_id
,
H5P_DEFAULT
,
62
H5P_DEFAULT
);
63
const
herr_t
err
=
H5Awrite
(
attr_id
,
type_id
, &
v
);
64
H5Aclose
(
attr_id
);
65
H5Sclose
(
space_id
);
66
H5Tclose
(
type_id
);
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();
77
const
hid_t
type_id
=
H5Tcreate
(
H5T_STRING
,
len
);
78
const
hid_t
space_id
=
H5Screate
(
H5S_SCALAR
);
79
const
hid_t
attr_id
=
H5Acreate
(
id
, name.c_str(),
type_id
,
space_id
,
H5P_DEFAULT
,
80
H5P_DEFAULT
);
81
const
herr_t
err
=
H5Awrite
(
attr_id
,
type_id
,
v
.c_str());
82
H5Aclose
(
attr_id
);
83
H5Sclose
(
space_id
);
84
H5Tclose
(
type_id
);
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
CXZ_ERROR
#define CXZ_ERROR(errmsg)
Definition
assert.h:26
CXZ_ASSERT
#define CXZ_ASSERT(statement, errmsg)
Definition
assert.h:40
CNORXZ::hdf5::ContentBase
Definition
h5_content_base.h:41
CNORXZ::hdf5::ContentBase::name
const String & name() const
Definition
h5_content_base.cc:24
CNORXZ::hdf5::ContentBase::addAttribute
ContentBase & addAttribute(const String &name, const T &value)
Definition
h5_content_base.cc.h:98
CNORXZ::hdf5::ContentBase::mId
hid_t mId
Definition
h5_content_base.h:142
h5_content_base.h
Abstract content base class declaration.
CNORXZ
Definition
aindex.cc.h:18
CNORXZ::String
std::string String
Definition
types.h:42
CNORXZ::Double
double Double
Definition
types.h:39
CNORXZ::Int
int32_t Int
Definition
types.h:36
CNORXZ::rangeCast
Sptr< Range > rangeCast(const RangePtr r)
Definition
range_base.cc.h:53
Generated by
1.10.0