7 #ifndef ALPS_HDF5_BOOST_ARRAY_HPP 8 #define ALPS_HDF5_BOOST_ARRAY_HPP 13 #include <boost/array.hpp> 16 #include <type_traits> 30 template<
typename T, std::
size_t N>
struct is_continuous<boost::array<T, N> const >
35 :
public has_complex_elements<typename alps::detail::remove_cvr<typename boost::array<T, N>::value_type>::type>
40 template<
typename T, std::
size_t N>
struct get_extent<boost::array<T, N> > {
41 static std::vector<std::size_t> apply(boost::array<T, N>
const & value) {
43 std::vector<std::size_t>
result(1, value.size());
45 std::vector<std::size_t> first(
get_extent(value[0]));
46 std::copy(first.begin(), first.end(), std::back_inserter(
result));
52 template<
typename T, std::
size_t N>
struct set_extent<boost::array<T, N> > {
53 static void apply(boost::array<T, N> & value, std::vector<std::size_t>
const & extent) {
55 if (extent.size() > 1)
56 for(
typename boost::array<T, N>::iterator it = value.begin(); it != value.end(); ++it)
57 set_extent(*it, std::vector<std::size_t>(extent.begin() + 1, extent.end()));
58 else if (extent.size() == 0 && !std::is_same<typename scalar_type<T>::type, T>::value)
63 template<
typename T, std::
size_t N>
struct is_vectorizable<boost::array<T, N> > {
64 static bool apply(boost::array<T, N>
const & value) {
70 std::vector<std::size_t> first(
get_extent(value[0]));
71 for(
typename boost::array<T, N>::const_iterator it = value.begin(); it != value.end(); ++it)
77 first.size() != size.size()
78 || !std::equal(first.begin(), first.end(), size.begin())
87 template<
typename T, std::
size_t N>
struct get_pointer<boost::array<T, N> > {
94 template<
typename T, std::
size_t N>
struct get_pointer<boost::array<T, N> const > {
102 template<
typename T, std::
size_t N>
void save(
104 , std::string
const & path
105 , boost::array<T, N>
const & value
106 , std::vector<std::size_t>
size = std::vector<std::size_t>()
107 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
108 , std::vector<std::size_t> offset = std::vector<std::size_t>()
114 ar.
write(path, static_cast<
typename scalar_type<boost::array<T, N> >::
type const *>(NULL), std::vector<std::size_t>());
116 std::vector<std::size_t> extent(
get_extent(value));
117 std::copy(extent.begin(), extent.end(), std::back_inserter(
size));
118 std::copy(extent.begin(), extent.end(), std::back_inserter(chunk));
119 std::fill_n(std::back_inserter(offset), extent.size(), 0);
121 }
else if (value.size() == 0)
122 ar.
write(path, static_cast<int const *>(NULL), std::vector<std::size_t>());
124 size.push_back(value.size());
127 for(
typename boost::array<T, N>::const_iterator it = value.begin(); it != value.end(); ++it) {
128 offset.back() = it - value.begin();
129 save(ar, path, *it,
size, chunk, offset);
134 for(
typename boost::array<T, N>::const_iterator it = value.begin(); it != value.end(); ++it)
135 save(ar, ar.
complete_path(path) +
"/" + cast<std::string>(it - value.begin()), *it);
139 template<
typename T, std::
size_t N>
void load(
141 , std::string
const & path
142 , boost::array<T, N> & value
143 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
144 , std::vector<std::size_t> offset = std::vector<std::size_t>()
149 if (children.size() != N)
151 for (
typename std::vector<std::string>::const_iterator it = children.begin(); it != children.end(); ++it)
156 std::vector<std::size_t>
size(ar.
extent(path));
162 std::copy(
size.begin() + chunk.size(),
size.end(), std::back_inserter(chunk));
163 std::fill_n(std::back_inserter(offset),
size.size() - offset.size(), 0);
167 set_extent(value, std::vector<std::size_t>(1, *(
size.begin() + chunk.size())));
170 for(
typename boost::array<T, N>::iterator it = value.begin(); it != value.end(); ++it) {
171 offset.back() = it - value.begin();
172 load(ar, path, *it, chunk, 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
void delete_group(std::string path) const
scalar_type< T >::type * get_pointer(T &value)
std::vector< std::size_t > extent(std::string path) const
std::vector< std::string > list_children(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
traits< Acc >::result_type result(const Acc &acc)
bool is_group(std::string path) const
std::string complete_path(std::string path) const
scalar_type< typename boost::array< T, N >::value_type >::type type
bool is_complex(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 >())