ALPSCore reference
complex.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_COMPLEX
8 #define ALPS_HDF5_STD_COMPLEX
9 
10 #include <alps/hdf5/archive.hpp>
11 
12 #include <complex>
13 
14 namespace alps {
15  namespace hdf5 {
16 
17  template<typename T> struct scalar_type<std::complex<T> > {
19  };
20 
21  template<typename T> struct is_continuous<std::complex<T> >
22  : public is_continuous<T>
23  {};
24  template<typename T> struct is_continuous<std::complex<T> const >
25  : public is_continuous<T>
26  {};
27 
28  template<typename T> struct has_complex_elements<std::complex<T> >
29  : public std::true_type
30  {};
31 
32  namespace detail {
33 
34  template<typename T> struct get_extent<std::complex<T> > {
35  static std::vector<std::size_t> apply(std::complex<T> const & /*value*/) {
36  return std::vector<std::size_t>(1, 2);
37  }
38  };
39 
40  template<typename T> struct set_extent<std::complex<T> > {
41  static void apply(std::complex<T> & /*value*/, std::vector<std::size_t> const & /*extent*/) {}
42  };
43 
44  template<typename T> struct is_vectorizable<std::complex<T> > {
45  static bool apply(std::complex<T> const & /*value*/) {
46  return true;
47  }
48  };
49  template<typename T> struct is_vectorizable<std::complex<T> const> {
50  static bool apply(std::complex<T> const & /*value*/) {
51  return true;
52  }
53  };
54 
55  template<typename T> struct get_pointer<std::complex<T> > {
56  static typename scalar_type<std::complex<T> >::type * apply(std::complex<T> & value) {
58  return get_pointer(*reinterpret_cast<typename scalar_type<std::complex<T> >::type *> (&value));
59  }
60  };
61 
62  template<typename T> struct get_pointer<std::complex<T> const> {
63  static typename scalar_type<std::complex<T> >::type const * apply(std::complex<T> const & value) {
65  return get_pointer(*reinterpret_cast<typename scalar_type<std::complex<T> >::type const *> (&value));
66  }
67  };
68  }
69 
70  template<typename T> void save(
71  archive & ar
72  , std::string const & path
73  , std::complex<T> const & value
74  , std::vector<std::size_t> size = std::vector<std::size_t>()
75  , std::vector<std::size_t> chunk = std::vector<std::size_t>()
76  , std::vector<std::size_t> offset = std::vector<std::size_t>()
77  ) {
79  size.push_back(2);
80  chunk.push_back(2);
81  offset.push_back(0);
82  ar.write(path, get_pointer(value), size, chunk, offset);
83  } else
84  throw wrong_type("invalid type" + ALPS_STACKTRACE);
85  }
86 
87  template<typename T> void load(
88  archive & ar
89  , std::string const & path
90  , std::complex<T> & value
91  , std::vector<std::size_t> chunk = std::vector<std::size_t>()
92  , std::vector<std::size_t> offset = std::vector<std::size_t>()
93  ) {
94  if (ar.is_group(path) || !is_continuous<T>::value)
95  throw wrong_type("invalid path" + ALPS_STACKTRACE);
96  else if (!ar.is_complex(path))
97  throw archive_error("no complex value in archive" + ALPS_STACKTRACE);
98  else {
99  chunk.push_back(2);
100  offset.push_back(0);
101  ar.read(path, get_pointer(value), chunk, offset);
102  }
103  }
104  }
105 }
106 
107 #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
bool is_vectorizable(T const &value)
Definition: archive.hpp:288
void set_extent(T &value, std::vector< std::size_t > const &size)
Definition: archive.hpp:284
scalar_type< typename std::complex< T >::value_type >::type type
Definition: complex.hpp:18
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
Definition: size.hpp:20
STL namespace.
std::vector< std::size_t > get_extent(T const &value)
Definition: archive.hpp:280
scalar_type< T >::type * get_pointer(T &value)
Definition: archive.hpp:272
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
Definition: archive.hpp:163
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
Definition: archive.hpp:172
#define ALPS_STACKTRACE
Definition: stacktrace.hpp:37
bool is_group(std::string path) const
Definition: archive.cpp:189
bool is_complex(std::string path) const
Definition: archive.cpp:242
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