9 #ifndef RMF_HDF5_TYPES_H
10 #define RMF_HDF5_TYPES_H
12 #include "RMF/config.h"
15 #include "RMF/internal/errors.h"
17 #include "internal/types.h"
20 #include <boost/cstdint.hpp>
30 typedef std::vector<Int>
Ints;
56 struct IntTraitsBase {
58 typedef std::vector<int> Types;
59 static const bool BatchOperations =
true;
60 static int get_index() {
return 0; }
61 static const Type& get_null_value() {
62 static Type null = std::numeric_limits<int>::max();
65 static bool get_is_null_value(Type t) {
return t == get_null_value(); }
66 static hid_t get_hdf5_fill_type() {
return H5T_NATIVE_INT; }
67 static hid_t get_hdf5_disk_type() {
return H5T_STD_I64LE; }
68 static hid_t get_hdf5_memory_type() {
return H5T_NATIVE_INT; }
69 static const Type& get_fill_value() {
return get_null_value(); }
70 static std::string get_name() {
return "int"; }
73 struct FloatTraitsBase {
75 typedef std::vector<float> Types;
76 static const bool BatchOperations =
true;
77 static int get_index() {
return 1; }
78 static const Type& get_null_value() {
79 static Type null = std::numeric_limits<float>::max();
82 static bool get_is_null_value(Type t) {
return t == get_null_value(); }
83 static hid_t get_hdf5_fill_type() {
return H5T_NATIVE_FLOAT; }
84 static hid_t get_hdf5_disk_type() {
return H5T_IEEE_F64LE; }
85 static hid_t get_hdf5_memory_type() {
return H5T_NATIVE_FLOAT; }
86 static const Type& get_fill_value() {
return get_null_value(); }
87 static std::string get_name() {
return "float"; }
90 struct IndexTraitsBase :
public IntTraitsBase {
91 static int get_index() {
return 2; }
92 static const Type& get_null_value() {
93 static Type null = -1;
96 static bool get_is_null_value(Type t) {
return t == get_null_value(); }
97 static const Type& get_fill_value() {
return get_null_value(); }
98 static std::string get_name() {
return "index"; }
101 template <
class Base>
102 struct SimpleTraits :
public Base {
103 static void write_value_dataset(hid_t d, hid_t iss, hid_t s,
104 typename Base::Type v) {
106 H5Dwrite(d, Base::get_hdf5_memory_type(), iss, s, H5P_DEFAULT, &v));
108 static typename Base::Type read_value_dataset(hid_t d, hid_t iss, hid_t sp) {
109 typename Base::Type ret;
111 H5Dread(d, Base::get_hdf5_memory_type(), iss, sp, H5P_DEFAULT, &ret));
114 static void write_values_dataset(hid_t d, hid_t iss, hid_t s,
115 const typename Base::Types& v) {
116 if (v.empty())
return;
117 RMF_HDF5_CALL(H5Dwrite(d, Base::get_hdf5_memory_type(), iss, s, H5P_DEFAULT,
118 const_cast<typename Base::Type*>(&v[0])));
120 static typename Base::Types read_values_dataset(hid_t d, hid_t iss, hid_t sp,
122 typename Base::Types ret(sz, Base::get_null_value());
123 RMF_HDF5_CALL(H5Dread(d, Base::get_hdf5_memory_type(), iss, sp, H5P_DEFAULT,
127 static void write_values_attribute(hid_t a,
const typename Base::Types& v) {
128 if (v.empty())
return;
129 RMF_HDF5_CALL(H5Awrite(a, Base::get_hdf5_memory_type(), &v[0]));
131 static typename Base::Types read_values_attribute(hid_t a,
unsigned int sz) {
132 typename Base::Types ret(sz, Base::get_null_value());
133 RMF_HDF5_CALL(H5Aread(a, Base::get_hdf5_memory_type(), &ret[0]));
140 typedef std::string Types;
141 static const bool BatchOperations =
false;
142 static int get_index() {
return 6; }
143 static const Type& get_null_value() {
144 static char null =
'\0';
147 static bool get_is_null_value(Type t) {
return t ==
'\0'; }
148 static hid_t get_hdf5_fill_type() {
return H5T_NATIVE_CHAR; }
149 static hid_t get_hdf5_disk_type() {
return H5T_STD_I8LE; }
150 static hid_t get_hdf5_memory_type() {
return H5T_NATIVE_CHAR; }
151 static const Type& get_fill_value() {
return get_null_value(); }
152 static std::string get_name() {
return "char"; }
154 static void write_value_dataset(hid_t, hid_t, hid_t,
char) {
157 static char read_value_dataset(hid_t, hid_t, hid_t) {
161 static void write_values_dataset(hid_t, hid_t, hid_t,
const Types&) {
164 static Types read_values_dataset(hid_t, hid_t, hid_t,
unsigned int) {
167 static void write_values_attribute(hid_t a,
const Types& v) {
170 static Types read_values_attribute(hid_t a,
unsigned int sz) {
171 std::vector<char> v(sz);
173 return std::string(&v[0], v.size());
177 template <
class Traits>
178 struct SimplePluralTraits {
179 typedef typename Traits::Types Type;
180 typedef std::vector<Type> Types;
181 static const bool BatchOperations =
false;
182 static int get_index() {
return 7 + Traits::get_index(); }
183 static const Type& get_null_value() {
187 static bool get_is_null_value(
const Type& t) {
return t.empty(); }
188 static hid_t get_hdf5_fill_type() {
return get_hdf5_memory_type(); }
189 static hid_t get_hdf5_disk_type() {
190 static RMF_HDF5_HANDLE(
191 ints_type, H5Tvlen_create(Traits::get_hdf5_disk_type()), H5Tclose);
194 static hid_t get_hdf5_memory_type() {
195 static RMF_HDF5_HANDLE(
196 ints_type, H5Tvlen_create(Traits::get_hdf5_memory_type()), H5Tclose);
199 static const Type& get_fill_value() {
return get_null_value(); }
200 static std::string get_name() {
return Traits::get_name() +
"s"; }
202 static void write_value_dataset(hid_t d, hid_t iss, hid_t s,
const Type& v) {
206 data.p =
const_cast<typename Type::pointer
>(&v[0]);
211 H5Dwrite(d, get_hdf5_memory_type(), iss, s, H5P_DEFAULT, &data));
213 static Type read_value_dataset(hid_t d, hid_t iss, hid_t sp) {
215 H5Dread(d, get_hdf5_memory_type(), iss, sp, H5P_DEFAULT, &data);
217 std::copy(static_cast<typename Type::pointer>(data.p),
218 static_cast<typename Type::pointer>(data.p) + data.len,
223 static void write_values_dataset(hid_t, hid_t, hid_t,
const Types&) {
226 static Types read_values_dataset(hid_t, hid_t, hid_t,
unsigned int) {
229 static Types read_values_attribute(hid_t,
unsigned int) {
232 static void write_values_attribute(hid_t,
const Types&) {
237 struct RMFEXPORT StringTraits {
238 typedef std::string Type;
239 typedef std::vector<std::string> Types;
240 static const bool BatchOperations =
false;
241 static int get_index() {
return 3; }
242 static const Type& get_null_value() {
243 static std::string null;
246 static bool get_is_null_value(Type t) {
return t.empty(); }
247 static hid_t get_hdf5_fill_type() {
return internal::get_string_type(); }
248 static hid_t get_hdf5_disk_type() {
return internal::get_string_type(); }
249 static hid_t get_hdf5_memory_type() {
return internal::get_string_type(); }
250 static const Type& get_fill_value() {
return get_null_value(); }
251 static std::string get_name() {
return "string"; }
252 static void write_value_dataset(hid_t d, hid_t iss, hid_t s,
const Type& v);
253 static Type read_value_dataset(hid_t d, hid_t iss, hid_t sp);
254 static void write_values_dataset(hid_t, hid_t, hid_t, Types) {
257 static Types read_values_dataset(hid_t, hid_t, hid_t,
unsigned int) {
260 static Types read_values_attribute(hid_t,
unsigned int) {
263 static void write_values_attribute(hid_t,
const Types&) {
268 struct RMFEXPORT StringsTraits {
269 typedef std::vector<std::string> Type;
270 typedef std::vector<Type> Types;
271 static const bool BatchOperations =
false;
272 static int get_index() {
return 3 + 7; }
273 static const Type& get_null_value() {
277 static bool get_is_null_value(Type t) {
return t.empty(); }
278 static hid_t get_hdf5_fill_type();
279 static hid_t get_hdf5_disk_type();
280 static hid_t get_hdf5_memory_type();
281 static const hvl_t& get_fill_value();
282 static std::string get_name() {
return "strings"; }
283 static void write_value_dataset(hid_t d, hid_t iss, hid_t s,
const Type& v);
284 static Type read_value_dataset(hid_t d, hid_t iss, hid_t sp);
285 static void write_values_dataset(hid_t, hid_t, hid_t,
const Types&) {
288 static Types read_values_dataset(hid_t, hid_t, hid_t,
unsigned int) {
291 static Types read_values_attribute(hid_t,
unsigned int) {
294 static void write_values_attribute(hid_t,
const Types&) {
300 struct IntTraits :
public SimpleTraits<IntTraitsBase> {};
301 struct IntsTraits :
public SimplePluralTraits<IntTraits> {};
302 struct FloatTraits :
public SimpleTraits<FloatTraitsBase> {};
303 struct FloatsTraits :
public SimplePluralTraits<FloatTraits> {};
304 struct IndexTraits :
public SimpleTraits<IndexTraitsBase> {};
305 struct IndexesTraits :
public SimplePluralTraits<IndexTraits> {};
309 template <
class OutType,
class InType>
310 inline void get_as_impl(InType in, OutType& out) {
313 template <
class Traits,
class InType>
314 inline void get_as_impl(InType in, ID<Traits>& out) {
318 out = ID<Traits>(in);
320 template <
class OutType,
class Traits>
321 inline void get_as_impl(ID<Traits> in, OutType& out) {
322 if (in == ID<Traits>())
325 out = in.get_index();
332 template <
class OutType,
class InType>
335 get_as_impl(in, ret);
340 template <
class OutType,
class InType>
341 inline OutType
get_as(
const std::vector<InType> in) {
342 OutType ret(in.size());
343 for (
unsigned int i = 0; i < ret.size(); ++i) {
344 ret[i] = get_as<typename OutType::value_type>(in[i]);
std::vector< String > Strings
OutType get_as(InType in)
Various general useful macros for IMP.
Handle read/write of Model data from/to files.
std::vector< Indexes > IndexesList
std::vector< Index > Indexes
std::vector< Float > Floats
std::vector< Floats > FloatsList
Include all non-deprecated headers in RMF.HDF5.
std::vector< Ints > IntsList
std::vector< Strings > StringsList