ALPSCore reference
tuple.hpp
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 #ifndef ALPS_HDF5_BOOST_TUPLE
8 #define ALPS_HDF5_BOOST_TUPLE
9 
10 #include <alps/hdf5/archive.hpp>
11 #include <alps/utilities/cast.hpp>
14 
15 #include <boost/tuple/tuple.hpp>
16 
17 #include <utility>
18 
19 namespace alps {
20  namespace hdf5 {
21 
22  namespace detail {
23 
24  template <int N, typename T, typename E> struct save_helper {
25  template <
26  typename A, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
27  > static void apply(
28  A & ar
29  , std::string const & path
30  , boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> const & value
31  ) {
32  using boost::get;
33  save(ar, path, get<N>(value));
34  if (has_complex_elements<typename alps::detail::remove_cvr<T>::type>::value)
35  ar.set_complex(path);
36  }
37  };
38 
39  template <int N, typename T> struct save_helper<N, T, std::true_type> {
40  template <
41  typename A, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
42  > static void apply(
43  A &
44  , std::string const &
45  , boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> const &
46  ) {}
47  };
48 
49  template <int N, typename T, class E> struct load_helper {
50  template <
51  typename A, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
52  > static void apply(
53  A & ar
54  , std::string const & path
55  , boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & value
56  ) {
57  using boost::get;
58  load(ar, path, get<N>(value));
59  }
60  };
61 
62  template <int N, typename T> struct load_helper<N, T, std::true_type> {
63  template <
64  typename A, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
65  > static void apply(
66  A &
67  , std::string const &
68  , boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &
69  ) {}
70  };
71  }
72 
73  template <
74  typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
75  > void save(
76  archive & ar
77  , std::string const & path
78  , boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> const & value
79  , std::vector<std::size_t> size = std::vector<std::size_t>()
80  , std::vector<std::size_t> chunk = std::vector<std::size_t>()
81  , std::vector<std::size_t> offset = std::vector<std::size_t>()
82  ) {
83  detail::save_helper<0, T0, typename std::is_same<T0, boost::tuples::null_type>::type>::apply(
84  ar, ar.complete_path(path) + "/0", value
85  );
86  detail::save_helper<1, T1, typename std::is_same<T1, boost::tuples::null_type>::type>::apply(
87  ar, ar.complete_path(path) + "/1", value
88  );
89  detail::save_helper<2, T2, typename std::is_same<T2, boost::tuples::null_type>::type>::apply(
90  ar, ar.complete_path(path) + "/2", value
91  );
92  detail::save_helper<3, T3, typename std::is_same<T3, boost::tuples::null_type>::type>::apply(
93  ar, ar.complete_path(path) + "/3", value
94  );
95  detail::save_helper<4, T4, typename std::is_same<T4, boost::tuples::null_type>::type>::apply(
96  ar, ar.complete_path(path) + "/4", value
97  );
98  detail::save_helper<5, T5, typename std::is_same<T5, boost::tuples::null_type>::type>::apply(
99  ar, ar.complete_path(path) + "/5", value
100  );
101  detail::save_helper<6, T6, typename std::is_same<T6, boost::tuples::null_type>::type>::apply(
102  ar, ar.complete_path(path) + "/6", value
103  );
104  detail::save_helper<7, T7, typename std::is_same<T7, boost::tuples::null_type>::type>::apply(
105  ar, ar.complete_path(path) + "/7", value
106  );
107  detail::save_helper<8, T8, typename std::is_same<T8, boost::tuples::null_type>::type>::apply(
108  ar, ar.complete_path(path) + "/8", value
109  );
110  detail::save_helper<9, T9, typename std::is_same<T9, boost::tuples::null_type>::type>::apply(
111  ar, ar.complete_path(path) + "/9", value
112  );
113  }
114 
115  template <
116  typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
117  > void load(
118  archive & ar
119  , std::string const & path
120  , boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & value
121  , std::vector<std::size_t> chunk = std::vector<std::size_t>()
122  , std::vector<std::size_t> offset = std::vector<std::size_t>()
123  ) {
124  detail::load_helper<0, T0, typename std::is_same<T0, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/0", value);
125  detail::load_helper<1, T1, typename std::is_same<T1, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/1", value);
126  detail::load_helper<2, T2, typename std::is_same<T2, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/2", value);
127  detail::load_helper<3, T3, typename std::is_same<T3, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/3", value);
128  detail::load_helper<4, T4, typename std::is_same<T4, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/4", value);
129  detail::load_helper<5, T5, typename std::is_same<T5, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/5", value);
130  detail::load_helper<6, T6, typename std::is_same<T6, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/6", value);
131  detail::load_helper<7, T7, typename std::is_same<T7, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/7", value);
132  detail::load_helper<8, T8, typename std::is_same<T8, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/8", value);
133  detail::load_helper<9, T9, typename std::is_same<T9, boost::tuples::null_type>::type>::apply(ar, ar.complete_path(path) + "/9", value);
134  }
135  }
136 }
137 
138 #endif
void load(archive &ar, std::string const &path, T &value, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
Definition: archive.hpp:309
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
Definition: size.hpp:20
STL namespace.
std::string complete_path(std::string path) const
Definition: archive.cpp:153
void save(archive &ar, std::string const &path, T const &value, std::vector< std::size_t >=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
Definition: archive.hpp:292