ALPSCore reference
map.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_STD_MAP
8 #define ALPS_HDF5_STD_MAP
9 
10 #include <alps/hdf5/archive.hpp>
11 #include <alps/utilities/cast.hpp>
12 
13 #include <map>
14 
15 namespace alps {
16  namespace hdf5 {
17 
18  template <typename K, typename T, typename C, typename A> void save(
19  archive & ar
20  , std::string const & path
21  , std::map<K, T, C, A> const & value
22  , std::vector<std::size_t> size = std::vector<std::size_t>()
23  , std::vector<std::size_t> chunk = std::vector<std::size_t>()
24  , std::vector<std::size_t> offset = std::vector<std::size_t>()
25  ) {
26  if (ar.is_group(path))
27  ar.delete_group(path);
28  ar.create_group(path);
29  for(typename std::map<K, T, C, A>::const_iterator it = value.begin(); it != value.end(); ++it)
30  save(ar, ar.complete_path(path) + "/" + ar.encode_segment(cast<std::string>(it->first)), it->second);
31  }
32 
33  template <typename K, typename T, typename C, typename A> void load(
34  archive & ar
35  , std::string const & path
36  , std::map<K, T, C, A> & value
37  , std::vector<std::size_t> chunk = std::vector<std::size_t>()
38  , std::vector<std::size_t> offset = std::vector<std::size_t>()
39  ) {
40  std::vector<std::string> children = ar.list_children(path);
41  for (typename std::vector<std::string>::const_iterator it = children.begin(); it != children.end(); ++it)
42  load(ar, ar.complete_path(path) + "/" + *it, value[ar.decode_segment(cast<K>(*it))]);
43  }
44  }
45 }
46 
47 #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
void delete_group(std::string path) const
Definition: archive.cpp:376
void create_group(std::string path) const
Definition: archive.cpp:327
std::string encode_segment(std::string segment) const
Definition: archive.cpp:128
std::vector< std::string > list_children(std::string path) const
Definition: archive.cpp:259
bool is_group(std::string path) const
Definition: archive.cpp:189
std::string complete_path(std::string path) const
Definition: archive.cpp:153
std::string decode_segment(std::string segment) const
Definition: archive.cpp:136
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