H5Utils.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3  *
4  * Distributed under the Boost Software License, Version 1.0.
5  * (See accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9 #ifndef H5UTILS_HPP
10 #define H5UTILS_HPP
11 
12 // internal utilities functions
13 #include <cstddef> // __GLIBCXX__
14 #include <exception>
15 #include <memory>
16 #include <string>
17 #include <type_traits>
18 #include <vector>
19 #include <array>
20 
21 #ifdef H5_USE_BOOST
22 #include <boost/multi_array.hpp>
23 #include <boost/numeric/ublas/matrix.hpp>
24 #endif
25 
26 #include <H5public.h>
27 
28 #ifndef H5_USE_CXX11
29 #if ___cplusplus >= 201103L
30 #define H5_USE_CXX11 1
31 #else
32 #define H5_USE_CXX11 0
33 #endif
34 #endif
35 
36 namespace HighFive {
37 
38 namespace details {
39 
40 // determine at compile time number of dimensions of in memory datasets
41 template <typename T>
42 struct array_dims {
43  static constexpr size_t value = 0;
44 };
45 
46 template <typename T>
47 struct array_dims<std::vector<T> > {
48  static constexpr size_t value = 1 + array_dims<T>::value;
49 };
50 
51 template <typename T>
52 struct array_dims<T*> {
53  static constexpr size_t value = 1 + array_dims<T>::value;
54 };
55 
56 template <typename T, std::size_t N>
57 struct array_dims<T[N]> {
58  static constexpr size_t value = 1 + array_dims<T>::value;
59 };
60 
61 // Only supporting 1D arrays at the moment
62 template<typename T, std::size_t N>
63 struct array_dims<std::array<T,N>> {
64  static constexpr size_t value = 1 + array_dims<T>::value;
65 };
66 
67 #ifdef H5_USE_BOOST
68 template <typename T, std::size_t Dims>
69 struct array_dims<boost::multi_array<T, Dims> > {
70  static constexpr size_t value = Dims;
71 };
72 
73 template <typename T>
74 struct array_dims<boost::numeric::ublas::matrix<T> > {
75  static constexpr size_t value = 2;
76 };
77 #endif
78 
79 // determine recursively the size of each dimension of a N dimension vector
80 template <typename T>
81 void get_dim_vector_rec(const T& vec, std::vector<size_t>& dims) {
82  (void)dims;
83  (void)vec;
84 }
85 
86 template <typename T>
87 void get_dim_vector_rec(const std::vector<T>& vec, std::vector<size_t>& dims) {
88  dims.push_back(vec.size());
89  get_dim_vector_rec(vec[0], dims);
90 }
91 
92 template <typename T>
93 std::vector<size_t> get_dim_vector(const std::vector<T>& vec) {
94  std::vector<size_t> dims;
95  get_dim_vector_rec(vec, dims);
96  return dims;
97 }
98 
99 // determine at compile time recursively the basic type of the data
100 template <typename T>
102  typedef T type;
103 };
104 
105 template <typename T>
106 struct type_of_array<std::vector<T> > {
107  typedef typename type_of_array<T>::type type;
108 };
109 
110 template <typename T, std::size_t N>
111 struct type_of_array<std::array<T, N> > {
112  typedef typename type_of_array<T>::type type;
113 };
114 
115 #ifdef H5_USE_BOOST
116 template <typename T, std::size_t Dims>
117 struct type_of_array<boost::multi_array<T, Dims> > {
118  typedef typename type_of_array<T>::type type;
119 };
120 
121 template <typename T>
122 struct type_of_array<boost::numeric::ublas::matrix<T> > {
123  typedef typename type_of_array<T>::type type;
124 };
125 #endif
126 
127 template <typename T>
128 struct type_of_array<T*> {
129  typedef typename type_of_array<T>::type type;
130 };
131 
132 template <typename T, std::size_t N>
133 struct type_of_array<T[N]> {
134  typedef typename type_of_array<T>::type type;
135 };
136 
137 // check if the type is a container ( only vector supported for now )
138 template <typename>
139 struct is_container {
140  static const bool value = false;
141 };
142 
143 template <typename T>
144 struct is_container<std::vector<T> > {
145  static const bool value = true;
146 };
147 
148 // check if the type is a basic C-Array
149 // check if the type is a container ( only vector supported for now )
150 template <typename>
151 struct is_c_array {
152  static const bool value = false;
153 };
154 
155 template <typename T>
156 struct is_c_array<T*> {
157  static const bool value = true;
158 };
159 
160 template <typename T, std::size_t N>
161 struct is_c_array<T[N]> {
162  static const bool value = true;
163 };
164 
165 
166 
167 // convertor function for hsize_t -> size_t when hsize_t != size_t
168 template<typename Size>
169 inline std::vector<std::size_t> to_vector_size_t(std::vector<Size> vec){
170  static_assert(std::is_same<Size, std::size_t>::value == false, " hsize_t != size_t mandatory here");
171  std::vector<size_t> res(vec.size());
172  std::copy(vec.begin(), vec.end(), res.begin());
173  return res;
174 }
175 
176 // convertor function for hsize_t -> size_t when size_t == hsize_t
177 inline std::vector<std::size_t> to_vector_size_t(std::vector<std::size_t> vec){
178  return vec;
179 }
180 
181 // shared ptr portability
182 // was used pre-C++11, kept for compatibility
183 namespace Mem {
184  using namespace std;
185 } // end Mem
186 
187 } // end details
188 }
189 
190 #endif // H5UTILS_HPP
HighFive::details::type_of_array
Definition: H5Utils.hpp:101
HighFive::details::is_container
Definition: H5Utils.hpp:139
HighFive::details::type_of_array< T * >::type
type_of_array< T >::type type
Definition: H5Utils.hpp:129
HighFive::details::array_dims
Definition: H5Utils.hpp:42
HighFive::details::array_dims::value
static constexpr size_t value
Definition: H5Utils.hpp:43
HighFive::details::is_c_array
Definition: H5Utils.hpp:151
HighFive::details::get_dim_vector
std::vector< size_t > get_dim_vector(const std::vector< T > &vec)
Definition: H5Utils.hpp:93
HighFive::details::is_container::value
static const bool value
Definition: H5Utils.hpp:140
HighFive::details::type_of_array< std::array< T, N > >::type
type_of_array< T >::type type
Definition: H5Utils.hpp:112
HighFive::details::type_of_array::type
T type
Definition: H5Utils.hpp:102
HighFive::details::is_c_array::value
static const bool value
Definition: H5Utils.hpp:152
HighFive::details::type_of_array< std::vector< T > >::type
type_of_array< T >::type type
Definition: H5Utils.hpp:107
std
Definition: HalfEdge.hpp:124
HighFive::details::to_vector_size_t
std::vector< std::size_t > to_vector_size_t(std::vector< Size > vec)
Definition: H5Utils.hpp:169
HighFive::details::type_of_array< T[N]>::type
type_of_array< T >::type type
Definition: H5Utils.hpp:134
HighFive::details::get_dim_vector_rec
void get_dim_vector_rec(const T &vec, std::vector< size_t > &dims)
Definition: H5Utils.hpp:81
HighFive
Definition: H5Annotate_traits.hpp:14


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23