22# include <boost/multi_array.hpp>
23# include <boost/numeric/ublas/matrix.hpp>
26# include <Eigen/Eigen>
31#include "../H5Exception.hpp"
36template <std::
size_t N>
37class FixedLenStringArray;
41using unqualified_t =
typename std::remove_const<typename std::remove_reference<T>::type
50 static constexpr size_t ndim = 0;
51 static constexpr size_t recursive_ndim = ndim;
53 static std::array<size_t, recursive_ndim> getDimensions(
const type& ) {
54 return std::array<size_t, recursive_ndim>();
63 static constexpr size_t ndim = 1;
64 static constexpr size_t recursive_ndim = ndim;
66 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
67 return std::array<size_t, recursive_ndim>{val.
size()};
72struct inspector<std::vector<T>> {
73 using type = std::vector<T>;
75 using base_type =
typename inspector<value_type>::base_type;
77 static constexpr size_t ndim = 1;
78 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
80 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
81 std::array<size_t, recursive_ndim> sizes{val.size()};
83 for (
const auto& s: inspector<value_type>::getDimensions(val[0])) {
94 using base_type =
typename inspector<value_type>::base_type;
96 static constexpr size_t ndim = 1;
97 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
99 static std::array<size_t, recursive_ndim> getDimensions(
const type& ) {
100 throw std::string(
"Not possible to have size of a T*");
104template <
typename T,
size_t N>
105struct inspector<T[N]> {
107 using value_type = T;
108 using base_type =
typename inspector<value_type>::base_type;
110 static constexpr size_t ndim = 1;
111 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
113 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
114 std::array<size_t, recursive_ndim> sizes{N};
116 for (
const auto& s: inspector<value_type>::getDimensions(val[0])) {
123template <
typename T,
size_t N>
124struct inspector<std::array<T, N>> {
125 using type = std::array<T, N>;
126 using value_type = T;
127 using base_type =
typename inspector<value_type>::base_type;
129 static constexpr size_t ndim = 1;
130 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
132 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
133 std::array<size_t, recursive_ndim> sizes{N};
135 for (
const auto& s: inspector<value_type>::getDimensions(val[0])) {
143template <
typename T,
int M,
int N>
144struct inspector<Eigen::Matrix<T, M, N>> {
145 using type = Eigen::Matrix<T, M, N>;
146 using value_type = T;
147 using base_type =
typename inspector<value_type>::base_type;
149 static constexpr size_t ndim = 2;
150 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
152 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
153 std::array<size_t, recursive_ndim> sizes{
static_cast<size_t>(val.rows()),
static_cast<size_t>(val.cols())};
155 for (
const auto& s: inspector<value_type>::getDimensions(val.data()[0])) {
164template <
typename T,
size_t Dims>
165struct inspector<boost::multi_array<T, Dims>> {
166 using type = boost::multi_array<T, Dims>;
167 using value_type = T;
168 using base_type =
typename inspector<value_type>::base_type;
170 static constexpr size_t ndim = Dims;
171 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
173 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
174 std::array<size_t, recursive_ndim> sizes;
175 for (
size_t i = 0; i < ndim; ++i) {
176 sizes[i] = val.shape()[i];
180 for (
const auto& s: inspector<value_type>::getDimensions(val.data()[0])) {
188struct inspector<boost::numeric::ublas::matrix<T>> {
189 using type = boost::numeric::ublas::matrix<T>;
190 using value_type = T;
191 using base_type =
typename inspector<value_type>::base_type;
193 static constexpr size_t ndim = 2;
194 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
196 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
197 std::array<size_t, recursive_ndim> sizes{val.size1(), val.size2()};
199 for (
const auto& s: inspector<value_type>::getDimensions(val(0, 0))) {
210struct type_char_array {
215struct type_char_array<T*> {
216 typedef typename std::conditional<
217 std::is_same<unqualified_t<T>,
char>::value,
219 typename type_char_array<T>::type
223template <
typename T, std::
size_t N>
224struct type_char_array<T[N]> {
225 typedef typename std::conditional<
226 std::is_same<unqualified_t<T>,
char>::value,
228 typename type_char_array<T>::type
236 static const bool value =
false;
240struct is_container<std::vector<T> > {
241 static const bool value =
true;
247 static const bool value =
false;
251struct is_c_array<T*> {
252 static const bool value =
true;
255template <
typename T, std::
size_t N>
256struct is_c_array<T[N]> {
257 static const bool value =
true;
262template <
typename Size>
263inline std::vector<std::size_t> to_vector_size_t(
const std::vector<Size>& vec) {
264 static_assert(std::is_same<Size, std::size_t>::value ==
false,
265 " hsize_t != size_t mandatory here");
266 std::vector<size_t> res(vec.size());
267 std::transform(vec.cbegin(), vec.cend(), res.begin(), [](Size e) {
268 return static_cast<size_t>(e);
274inline std::vector<std::size_t> to_vector_size_t(
const std::vector<std::size_t>& vec) {
280inline std::string get_name(T fct) {
281 const size_t maxLength = 255;
282 char buffer[maxLength + 1];
283 ssize_t retcode = fct(buffer,
static_cast<hsize_t
>(maxLength) + 1);
285 HDF5ErrMapper::ToException<GroupException>(
"Error accessing object name");
287 const size_t length =
static_cast<std::size_t
>(retcode);
288 if (length <= maxLength) {
289 return std::string(buffer, length);
291 std::vector<char> bigBuffer(length + 1, 0);
292 fct(bigBuffer.data(),
static_cast<hsize_t
>(length) + 1);
293 return std::string(bigBuffer.data(), length);
A structure representing a set of fixed-length strings.
Definition: H5DataType.hpp:239
std::size_t size() const noexcept
Definition: H5DataType.hpp:281
Definition: H5_definitions.hpp:15
typename std::remove_const< typename std::remove_reference< T >::type >::type unqualified_t
Definition: H5Utils.hpp:42