18 #include <type_traits>
22 # include <boost/multi_array.hpp>
23 # include <boost/numeric/ublas/matrix.hpp>
26 # include <Eigen/Eigen>
31 #include "../H5Exception.hpp"
36 template <std::
size_t N>
37 class FixedLenStringArray;
45 static constexpr
size_t value = 0;
48 template <std::
size_t N>
49 struct array_dims<FixedLenStringArray<N>> {
50 static constexpr
size_t value = 1;
54 struct array_dims<std::vector<T> > {
55 static constexpr
size_t value = 1 + array_dims<T>::value;
59 struct array_dims<T*> {
60 static constexpr
size_t value = 1 + array_dims<T>::value;
63 template <
typename T, std::
size_t N>
64 struct array_dims<T[N]> {
65 static constexpr
size_t value = 1 + array_dims<T>::value;
69 template<
typename T, std::
size_t N>
70 struct array_dims<std::array<T,N>> {
71 static constexpr
size_t value = 1 + array_dims<T>::value;
75 template <
typename T, std::
size_t Dims>
76 struct array_dims<boost::multi_array<T, Dims> > {
77 static constexpr
size_t value = Dims;
81 struct array_dims<boost::numeric::ublas::matrix<T> > {
82 static constexpr
size_t value = 2;
87 template<
typename T,
int M,
int N>
88 struct array_dims<Eigen::Matrix<T, M, N>> {
89 static constexpr
size_t value = 2;
92 template<
typename T,
int M,
int N>
93 struct array_dims<std::vector<Eigen::Matrix<T, M, N>>> {
94 static constexpr
size_t value = 2;
100 inline void get_dim_vector_rec(
const T& , std::vector<size_t>& ) {}
102 template <
typename T>
103 inline void get_dim_vector_rec(
const std::vector<T>& vec, std::vector<size_t>& dims) {
104 dims.push_back(vec.size());
105 get_dim_vector_rec(vec[0], dims);
108 template <
typename T>
109 inline std::vector<size_t> get_dim_vector(
const std::vector<T>& vec) {
110 std::vector<size_t> dims;
111 get_dim_vector_rec(vec, dims);
116 template <
typename T, std::
size_t N>
117 inline void get_dim_vector_rec(
const T(&vec)[N], std::vector<size_t>& dims) {
119 get_dim_vector_rec(vec[0], dims);
122 template <
typename T, std::
size_t N>
123 inline std::vector<size_t> get_dim_vector(
const T(&vec)[N]) {
124 std::vector<size_t> dims;
125 get_dim_vector_rec(vec, dims);
130 template <
typename T>
131 using unqualified_t =
typename std::remove_const<typename std::remove_reference<T>::type
135 template <
typename T>
136 struct type_of_array {
137 typedef unqualified_t<T> type;
140 template <
typename T>
141 struct type_of_array<std::vector<T>> {
142 typedef typename type_of_array<T>::type type;
145 template <
typename T, std::
size_t N>
146 struct type_of_array<std::array<T, N>> {
147 typedef typename type_of_array<T>::type type;
151 template <
typename T, std::
size_t Dims>
152 struct type_of_array<boost::multi_array<T, Dims>> {
153 typedef typename type_of_array<T>::type type;
156 template <
typename T>
157 struct type_of_array<boost::numeric::ublas::matrix<T>> {
158 typedef typename type_of_array<T>::type type;
163 template<
typename T,
int M,
int N>
164 struct type_of_array<Eigen::Matrix<T, M, N>> {
169 template <
typename T>
170 struct type_of_array<T*> {
171 typedef typename type_of_array<T>::type type;
174 template <
typename T, std::
size_t N>
175 struct type_of_array<T[N]> {
176 typedef typename type_of_array<T>::type type;
182 struct type_char_array {
186 template <
typename T>
187 struct type_char_array<T*> {
188 typedef typename std::conditional<
189 std::is_same<unqualified_t<T>,
char>::value,
191 typename type_char_array<T>::type
195 template <
typename T, std::
size_t N>
196 struct type_char_array<T[N]> {
197 typedef typename std::conditional<
198 std::is_same<unqualified_t<T>,
char>::value,
200 typename type_char_array<T>::type
207 struct is_container {
208 static const bool value =
false;
211 template <
typename T>
212 struct is_container<std::vector<T> > {
213 static const bool value =
true;
219 static const bool value =
false;
222 template <
typename T>
223 struct is_c_array<T*> {
224 static const bool value =
true;
227 template <
typename T, std::
size_t N>
228 struct is_c_array<T[N]> {
229 static const bool value =
true;
234 template <
typename Size>
235 inline std::vector<std::size_t> to_vector_size_t(
const std::vector<Size>& vec) {
236 static_assert(std::is_same<Size, std::size_t>::value ==
false,
237 " hsize_t != size_t mandatory here");
238 std::vector<size_t> res(vec.size());
239 std::transform(vec.cbegin(), vec.cend(), res.begin(), [](Size e) {
240 return static_cast<size_t>(e);
246 inline std::vector<std::size_t> to_vector_size_t(
const std::vector<std::size_t>& vec) {
252 inline std::string get_name(T fct) {
253 const size_t maxLength = 255;
254 char buffer[maxLength + 1];
255 ssize_t retcode = fct(buffer,
static_cast<hsize_t
>(maxLength) + 1);
257 HDF5ErrMapper::ToException<GroupException>(
"Error accessing object name");
259 const size_t length =
static_cast<std::size_t
>(retcode);
260 if (length <= maxLength) {
261 return std::string(buffer, length);
263 std::vector<char> bigBuffer(length + 1, 0);
264 fct(bigBuffer.data(),
static_cast<hsize_t
>(length) + 1);
265 return std::string(bigBuffer.data(), length);
Definition: H5_definitions.hpp:15