RMF
Toggle main menu visibility
ConstAttributes.h
Go to the documentation of this file.
1
/**
2
* \file RMF/HDF5/ConstAttributes.h
3
* \brief Handle read/write of Model data from/to files.
4
*
5
* Copyright 2007-2022 IMP Inventors. All rights reserved.
6
*
7
*/
8
9
#ifndef RMF_HDF5_CONST_ATTRIBUTES_H
10
#define RMF_HDF5_CONST_ATTRIBUTES_H
11
12
#include "RMF/config.h"
13
#include "
handle.h
"
14
#include "
types.h
"
15
#include "
infrastructure_macros.h
"
16
#include <hdf5.h>
17
18
RMF_ENABLE_WARNINGS
19
20
namespace
RMF
{
21
namespace
HDF5
{
22
23
/** Wrap getting the attributes from an HDF5 Object. Each data set or
24
group can have associated data. These data should be relatively small
25
(a few k at most). See MutableAttributes for the methods to change
26
the attribute data.
27
*/
28
template
<
class
Base>
29
class
ConstAttributes :
public
Base {
30
#ifndef SWIG
31
protected
:
32
ConstAttributes(std::shared_ptr<SharedHandle> h) : Base(h) {}
33
ConstAttributes() {}
34
#else
35
private
:
36
ConstAttributes();
37
#endif
38
public
:
39
/** \name Template attribute methods
40
When manipulating attributes from C++ you can use these
41
templated methods.
42
@{
43
*/
44
template
<
class
TypeTraits>
45
typename
TypeTraits::Types get_attribute(std::string name)
const
{
46
if
(!H5Aexists(Base::get_shared_handle()->get_hid(), name.c_str())) {
47
return
typename
TypeTraits::Types();
48
}
else
{
49
RMF_HDF5_HANDLE(a, H5Aopen(Base::get_shared_handle()->get_hid(),
50
name.c_str(), H5P_DEFAULT),
51
&H5Aclose);
52
RMF_HDF5_HANDLE(s, H5Aget_space(a), &H5Sclose);
53
hsize_t dim, maxdim;
54
RMF_HDF5_CALL
(H5Sget_simple_extent_dims(s, &dim, &maxdim));
55
typename
TypeTraits::Types ret =
56
TypeTraits::read_values_attribute(a, dim);
57
return
ret;
58
}
59
}
60
/** @} */
61
template
<
class
CT,
class
CF>
62
CT copy_to(
const
CF& cf)
const
{
63
return
CT(cf.begin(), cf.end());
64
}
65
bool
get_has_attribute(std::string nm)
const
{
66
return
H5Aexists_by_name(Base::get_handle(),
"."
, nm.c_str(), H5P_DEFAULT) >
67
0;
68
}
69
/** \name Nontemplated attributes
70
When using python, call the non-template versions of the
71
attribute manipulation methods.
72
@{
73
*/
74
#define RMF_HDF5_CONST_ATTRIBUTE(lcname, UCName, PassValue, ReturnValue, \
75
PassValues, ReturnValues) \
76
ReturnValues get_##lcname##_attribute(std::string nm) const { \
77
return get_attribute<UCName##Traits>(nm); \
78
}
79
80
RMF_FOREACH_SIMPLE_TYPE
(RMF_HDF5_CONST_ATTRIBUTE);
81
RMF_HDF5_CONST_ATTRIBUTE(
char
,
Char
,
char
,
char
, std::string, std::string);
82
/** @} */
83
};
84
85
}
/* namespace HDF5 */
86
}
/* namespace RMF */
87
88
RMF_DISABLE_WARNINGS
89
90
#endif
/* RMF_HDF5_CONST_ATTRIBUTES_H */
infrastructure_macros.h
Various general useful macros for IMP.
RMF_HDF5_CALL
#define RMF_HDF5_CALL(v)
Definition
HDF5/infrastructure_macros.h:28
types.h
Handle read/write of Model data from/to files.
handle.h
Handle read/write of Model data from/to files.
RMF_FOREACH_SIMPLE_TYPE
#define RMF_FOREACH_SIMPLE_TYPE(macroname)
Definition
infrastructure_macros.h:139
RMF::HDF5
The namespace for all HDF5 functionality in the library.
Definition
ConstAttributes.h:21
RMF::HDF5::Char
char Char
Definition
HDF5/types.h:52
RMF
The namespace for all functionality in the library.
Definition
BufferConstHandle.h:21