7 #ifndef ALPS_HDF5_STD_VECTOR_HPP 8 #define ALPS_HDF5_STD_VECTOR_HPP 13 #include <type_traits> 29 :
public std::false_type
33 :
public has_complex_elements<typename alps::detail::remove_cvr<typename std::vector<T, A>::value_type>::type>
38 template<
typename T,
typename A>
struct get_extent<std::vector<T, A> > {
39 static std::vector<std::size_t> apply(std::vector<T, A>
const & value) {
41 std::vector<std::size_t>
result(1, value.size());
43 std::vector<std::size_t> first(
get_extent(value[0]));
44 if (!std::is_scalar<
typename std::vector<T, A>::value_type>::value)
45 for(
typename std::vector<T, A>::const_iterator it = value.begin() + 1; it != value.end(); ++it) {
48 first.size() != size.size()
49 || !std::equal(first.begin(), first.end(), size.begin())
53 std::copy(first.begin(), first.end(), std::back_inserter(
result));
59 template<
typename T,
typename A>
struct set_extent<std::vector<T, A> > {
60 static void apply(std::vector<T, A> & value, std::vector<std::size_t>
const & extent) {
62 value.resize(extent[0]);
63 if (extent.size() > 1)
64 for(
typename std::vector<T, A>::iterator it = value.begin(); it != value.end(); ++it)
65 set_extent(*it, std::vector<std::size_t>(extent.begin() + 1, extent.end()));
66 else if (extent.size() == 1 && (
67 (!std::is_enum<T>::value && !std::is_same<typename scalar_type<T>::type, T>::value)
74 template<
typename A>
struct set_extent<std::vector<bool, A> > {
75 static void apply(std::vector<bool, A> & value, std::vector<std::size_t>
const & extent) {
76 if (extent.size() != 1)
78 value.resize(extent[0]);
82 template<
typename T,
typename A>
struct is_vectorizable<std::vector<T, A> > {
83 static bool apply(std::vector<T, A>
const & value) {
89 std::vector<std::size_t> first(
get_extent(value[0]));
90 if (!std::is_scalar<
typename std::vector<T, A>::value_type>::value) {
91 for(
typename std::vector<T, A>::const_iterator it = value.begin(); it != value.end(); ++it)
97 first.size() != size.size()
98 || !std::equal(first.begin(), first.end(), size.begin())
109 static bool apply(std::vector<bool, A>
const & value) {
114 template<
typename T,
typename A>
struct get_pointer<std::vector<T, A> > {
121 template<
typename T,
typename A>
struct get_pointer<std::vector<T, A> const> {
128 template<
typename A>
struct get_pointer<std::vector<bool, A> > {
135 template<
typename A>
struct get_pointer<std::vector<bool, A> const> {
145 template<
typename T,
typename A>
void save(
147 , std::string
const & path
148 , std::vector<T, A>
const & value
149 , std::vector<std::size_t>
size = std::vector<std::size_t>()
150 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
151 , std::vector<std::size_t> offset = std::vector<std::size_t>()
157 ar.
write(path, static_cast<
typename scalar_type<std::vector<T, A> >::
type const *>(NULL), std::vector<std::size_t>());
159 std::vector<std::size_t> extent(
get_extent(value));
160 std::copy(extent.begin(), extent.end(), std::back_inserter(
size));
161 std::copy(extent.begin(), extent.end(), std::back_inserter(chunk));
162 std::fill_n(std::back_inserter(offset), extent.size(), 0);
164 }
else if (value.size() == 0)
165 ar.
write(path, static_cast<int const *>(NULL), std::vector<std::size_t>());
167 size.push_back(value.size());
170 for(
typename std::vector<T, A>::const_iterator it = value.begin(); it != value.end(); ++it) {
171 offset.back() = it - value.begin();
172 save(ar, path, *it,
size, chunk, offset);
175 if (path.find_last_of(
'@') == std::string::npos && ar.
is_data(path))
177 else if (path.find_last_of(
'@') != std::string::npos && ar.
is_attribute(path))
179 for(
typename std::vector<T, A>::const_iterator it = value.begin(); it != value.end(); ++it)
180 save(ar, ar.
complete_path(path) +
"/" + cast<std::string>(it - value.begin()), *it);
184 template<
typename A>
void save(
186 , std::string
const & path
187 , std::vector<bool, A>
const & value
188 , std::vector<std::size_t>
size = std::vector<std::size_t>()
189 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
190 , std::vector<std::size_t> offset = std::vector<std::size_t>()
194 if (value.size() == 0)
195 ar.
write(path, static_cast<bool const *>(NULL), std::vector<std::size_t>());
197 size.push_back(value.size());
200 for(
typename std::vector<bool, A>::const_iterator it = value.begin(); it != value.end(); ++it) {
201 offset.back() = it - value.begin();
202 bool const elem = *it;
203 ar.
write(path, &elem,
size, chunk, offset);
208 template<
typename T,
typename A>
void load(
210 , std::string
const & path
211 , std::vector<T, A> & value
212 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
213 , std::vector<std::size_t> offset = std::vector<std::size_t>()
218 value.resize(children.size());
219 for (
typename std::vector<std::string>::const_iterator it = children.begin(); it != children.end(); ++it)
224 std::vector<std::size_t>
size(ar.
extent(path));
225 if (
size.size() == 0)
227 else if (
size[0] == 0)
232 std::copy(
size.begin() + chunk.size(),
size.end(), std::back_inserter(chunk));
233 std::fill_n(std::back_inserter(offset),
size.size() - offset.size(), 0);
237 value.resize(*(
size.begin() + chunk.size()));
240 for(
typename std::vector<T, A>::iterator it = value.begin(); it != value.end(); ++it) {
241 offset.back() = it - value.begin();
242 load(ar, path, *it, chunk, offset);
248 template<
typename A>
void load(
250 , std::string
const & path
251 , std::vector<bool, A> & value
252 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
253 , std::vector<std::size_t> offset = std::vector<std::size_t>()
260 std::vector<std::size_t>
size(ar.
extent(path));
261 if (
size.size() == 0)
263 else if (
size[0] == 0)
266 value.resize(*(
size.begin() + chunk.size()));
269 for(
typename std::vector<bool, A>::iterator it = value.begin(); it != value.end(); ++it) {
270 offset.back() = it - value.begin();
272 ar.
read(path, &elem, 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)
bool is_attribute(std::string path) const
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)
void delete_attribute(std::string path) const
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
scalar_type< typename std::vector< T, A >::value_type >::type type
traits< Acc >::result_type result(const Acc &acc)
bool is_group(std::string path) const
std::string complete_path(std::string path) const
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 >())