7 #ifndef ALPS_HDF5_STD_PAIR 8 #define ALPS_HDF5_STD_PAIR 19 template <
typename T,
typename U>
void save(
21 , std::string
const & path
22 , std::pair<T, U>
const & value
23 , std::vector<std::size_t> = std::vector<std::size_t>()
24 , std::vector<std::size_t> = std::vector<std::size_t>()
25 , std::vector<std::size_t> = std::vector<std::size_t>()
35 template <
typename T,
typename U>
void load(
37 , std::string
const & path
38 , std::pair<T, U> & value
39 , std::vector<std::size_t> = std::vector<std::size_t>()
40 , std::vector<std::size_t> = std::vector<std::size_t>()
51 template<
typename T>
struct scalar_type<
std::pair<T *, std::vector<std::size_t> > > {
65 template<
typename T>
struct get_extent<std::pair<T *, std::vector<std::size_t> > > {
66 static std::vector<std::size_t> apply(std::pair<T *, std::vector<std::size_t> >
const & value) {
68 std::vector<std::size_t> extent(value.second);
69 std::vector<std::size_t>
size(value.second.size() ?
get_extent(*value.first) : std::vector<std::size_t>());
71 for (std::size_t i = 1; i < std::accumulate(value.second.begin(), value.second.end(), std::size_t(1), std::multiplies<std::size_t>()); ++i)
72 if (!std::equal(size.begin(), size.end(),
get_extent(value.first[i]).begin()))
75 std::copy(size.begin(), size.end(), std::back_inserter(extent));
80 template<
typename T>
struct set_extent<std::pair<T *, std::vector<std::size_t> > > {
81 static void apply(std::pair<T *, std::vector<std::size_t> > & value, std::vector<std::size_t>
const &
size) {
83 if (value.second.size() > size.size() || !std::equal(value.second.begin(), value.second.end(), size.begin()))
86 for (std::size_t i = 0; i < std::accumulate(value.second.begin(), value.second.end(), std::size_t(1), std::multiplies<std::size_t>()); ++i)
87 set_extent(value.first[i], std::vector<std::size_t>(size.begin() + value.second.size(), size.end()));
91 template<
typename T>
struct is_vectorizable<std::pair<T *, std::vector<std::size_t> > > {
92 static bool apply(std::pair<T *, std::vector<std::size_t> >
const & value) {
96 for (std::size_t i = 1; i < std::accumulate(value.second.begin(), value.second.end(), std::size_t(1), std::multiplies<std::size_t>()); ++i)
103 template<
typename T>
struct get_pointer<std::pair<T *, std::vector<std::size_t> > > {
110 template<
typename T>
struct get_pointer<std::pair<T *, std::vector<std::size_t> > const> {
119 template<
typename T>
void save(
121 , std::string
const & path
122 , std::pair<T *, std::vector<std::size_t> >
const & value
123 , std::vector<std::size_t>
size = std::vector<std::size_t>()
124 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
125 , std::vector<std::size_t> offset = std::vector<std::size_t>()
128 std::vector<std::size_t> extent(
get_extent(value));
129 std::copy(extent.begin(), extent.end(), std::back_inserter(
size));
130 std::copy(extent.begin(), extent.end(), std::back_inserter(chunk));
131 std::fill_n(std::back_inserter(offset), extent.size(), 0);
133 }
else if (value.second.size() == 0)
134 ar.
write(path, static_cast<int const *>(NULL), std::vector<std::size_t>());
136 std::copy(value.second.begin(), value.second.end(), std::back_inserter(
size));
137 std::fill_n(std::back_inserter(chunk), value.second.size(), 1);
140 i < std::accumulate(value.second.begin(), value.second.end(), std::size_t(1), std::multiplies<std::size_t>());
143 std::vector<std::size_t> local_offset(offset);
144 local_offset.push_back(
145 i / std::accumulate(value.second.begin() + 1, value.second.end(), std::size_t(1), std::multiplies<std::size_t>())
147 for (std::vector<std::size_t>::const_iterator it = value.second.begin() + 1; it != value.second.end(); ++it)
148 local_offset.push_back((i % std::accumulate(
149 it, value.second.end(), std::size_t(1), std::multiplies<std::size_t>()
150 )) / std::accumulate(
151 it + 1, value.second.end(), std::size_t(1), std::multiplies<std::size_t>()
153 save(ar, path, value.first[i],
size, chunk, local_offset);
156 if (path.find_last_of(
'@') != std::string::npos)
160 offset = std::vector<std::size_t>(value.second.size(), 0);
162 std::size_t last = offset.size() - 1, pos = 0;
163 std::string location =
"";
164 for (std::vector<std::size_t>::const_iterator it = offset.begin(); it != offset.end(); ++it) {
165 location +=
"/" + cast<std::string>(*it);
166 pos += *it * std::accumulate(
167 value.second.begin() + (it - offset.begin()) + 1,
170 std::multiplies<std::size_t>()
173 save(ar, path + location, value.first[pos]);
174 if (offset[last] + 1 == value.second[last] && last) {
175 for (pos = last; ++offset[pos] == value.second[pos] && pos; --pos);
176 for (++pos; pos <= last; ++pos)
180 }
while (offset[0] < value.second[0]);
184 template<
typename T>
void load(
186 , std::string
const & path
187 , std::pair<T *, std::vector<std::size_t> > & value
188 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
189 , std::vector<std::size_t> offset = std::vector<std::size_t>()
192 offset = std::vector<std::size_t>(value.second.size(), 0);
194 std::size_t last = offset.size() - 1, pos = 0;
195 std::string location =
"";
196 for (std::vector<std::size_t>::const_iterator it = offset.begin(); it != offset.end(); ++it) {
197 location +=
"/" + cast<std::string>(*it);
198 pos += *it * std::accumulate(
199 value.second.begin() + (it - offset.begin()) + 1,
202 std::multiplies<std::size_t>()
205 load(ar, path + location, value.first[pos]);
206 if (offset[last] + 1 == value.second[last] && last) {
207 for (pos = last; ++offset[pos] == value.second[pos] && pos; --pos);
208 for (++pos; pos <= last; ++pos)
212 }
while (offset[0] < value.second[0]);
214 std::vector<std::size_t>
size(ar.
extent(path));
217 std::copy(
size.begin(),
size.end(), std::back_inserter(chunk));
218 std::fill_n(std::back_inserter(offset),
size.size(), 0);
220 }
else if (value.second.size()) {
221 std::fill_n(std::back_inserter(chunk), value.second.size(), 1);
224 i < std::accumulate(value.second.begin(), value.second.end(), std::size_t(1), std::multiplies<std::size_t>());
227 std::vector<std::size_t> local_offset(offset);
228 local_offset.push_back(
229 i / std::accumulate(value.second.begin() + 1, value.second.end(), std::size_t(1), std::multiplies<std::size_t>())
231 for (std::vector<std::size_t>::iterator it = value.second.begin() + 1; it != value.second.end(); ++it)
232 local_offset.push_back((i % std::accumulate(
233 it, value.second.end(), std::size_t(1), std::multiplies<std::size_t>()
234 )) / std::accumulate(
235 it + 1, value.second.end(), std::size_t(1), std::multiplies<std::size_t>()
237 load(ar, path, value.first[i], chunk, local_offset);
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 >())
bool is_vectorizable(T const &value)
void set_extent(T &value, std::vector< std::size_t > const &size)
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
bool is_data(std::string path) const
std::vector< std::size_t > get_extent(T const &value)
void delete_data(std::string path) const
scalar_type< T >::type * get_pointer(T &value)
scalar_type< typename alps::detail::remove_cvr< T >::type >::type type
std::vector< std::size_t > extent(std::string path) const
auto read(std::string path, T *, std::vector< std::size_t >, std::vector< std::size_t >=std::vector< std::size_t >()) const -> typename std::enable_if<!is_native_type< T >::value, void >::type
auto write(std::string path, T const *value, std::vector< std::size_t > size, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t > offset=std::vector< std::size_t >()) const -> typename std::enable_if<!is_native_type< T >::value, void >::type
void set_complex(std::string path)
bool is_group(std::string path) const
std::string complete_path(std::string path) const
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 >())