ALPSCore reference
archive_read_scalar_helpers.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #include <alps/hdf5/archive.hpp>
10 
11 #include "common.hpp"
12 
13 namespace alps {
14  namespace hdf5 {
15  namespace detail {
16 
17  //
18  // hdf5_read_scalar_data_helper
19  //
20 
21  template<typename T, typename U, typename... UTail>
22  inline bool hdf5_read_scalar_data_helper_impl(T & value, data_type const &data_id, type_type const &native_id, std::true_type) {
23  if (check_error(
24  H5Tequal(type_type(H5Tcopy(native_id)), type_type(get_native_type(U())))
25  ) > 0) {
26  U u;
27  check_error(H5Dread(data_id, native_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &u));
28  value = cast<T>(u);
29  return true;
30  } else
31  return hdf5_read_scalar_data_helper_impl<T, UTail...>(value,
32  data_id,
33  native_id,
34  std::integral_constant<bool, sizeof...(UTail) != 0>());
35  }
36  template<typename T, typename... UTail>
37  inline bool hdf5_read_scalar_data_helper_impl(T &, data_type const &, type_type const &, std::false_type) { return false; }
38 
39  template<typename T>
40  bool hdf5_read_scalar_data_helper(T & value, data_type const &data_id, type_type const &native_id) {
41  return hdf5_read_scalar_data_helper_impl<T, ALPS_HDF5_NATIVE_INTEGRAL_TYPES>(value, data_id, native_id, std::true_type());
42  }
43 
44  #define ALPS_HDF5_READ_SCALAR_DATA_HELPER(T) \
45  template bool hdf5_read_scalar_data_helper<T>(T &, data_type const &, type_type const &);
47 
48  //
49  // hdf5_read_scalar_attribute_helper
50  //
51 
52  template<typename T, typename U, typename... UTail>
53  inline bool hdf5_read_scalar_attribute_helper_impl(T & value, attribute_type const &attribute_id, type_type const &native_id, std::true_type) {
54  if (check_error(
55  H5Tequal(type_type(H5Tcopy(native_id)), type_type(get_native_type(U())))
56  ) > 0) {
57  U u;
58  check_error(H5Aread(attribute_id, native_id, &u));
59  value = cast< T >(u);
60  return true;
61  } else
62  return hdf5_read_scalar_attribute_helper_impl<T, UTail...>(value,
63  attribute_id,
64  native_id,
65  std::integral_constant<bool, sizeof...(UTail) != 0>());
66  }
67  template<typename T, typename... UTail>
68  inline bool hdf5_read_scalar_attribute_helper_impl(T &, attribute_type const &, type_type const &, std::false_type) { return false; }
69 
70  template<typename T>
71  bool hdf5_read_scalar_attribute_helper(T & value, attribute_type const &attribute_id, type_type const &native_id) {
72  return hdf5_read_scalar_attribute_helper_impl<T, ALPS_HDF5_NATIVE_INTEGRAL_TYPES>(value, attribute_id, native_id, std::true_type());
73  }
74 
75  #define ALPS_HDF5_READ_SCALAR_ATTRIBUTE_HELPER(T) \
76  template bool hdf5_read_scalar_attribute_helper<T>(T &, attribute_type const &, type_type const &);
78  }
79  }
80 }
#define ALPS_HDF5_READ_SCALAR_ATTRIBUTE_HELPER(T)
#define ALPS_HDF5_READ_SCALAR_DATA_HELPER(T)
ALPS_FOREACH_NATIVE_HDF5_TYPE(ALPS_HDF5_READ_SCALAR)