21#ifndef H5GT_MAX_PATH_LEN
22#define H5GT_MAX_PATH_LEN 510
25# include <boost/multi_array.hpp>
26# include <boost/numeric/ublas/matrix.hpp>
29# include <Eigen/Eigen>
34#include "../H5Exception.hpp"
39template <std::
size_t N>
40class FixedLenStringArray;
44using unqualified_t =
typename std::remove_const<typename std::remove_reference<T>::type
51 using base_type = unqualified_t<T>;
53 static constexpr size_t ndim = 0;
54 static constexpr size_t recursive_ndim = ndim;
56 static std::array<size_t, recursive_ndim> getDimensions(
const type& ) {
57 return std::array<size_t, recursive_ndim>();
66 static constexpr size_t ndim = 1;
67 static constexpr size_t recursive_ndim = ndim;
69 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
70 return std::array<size_t, recursive_ndim>{val.size()};
76 using type = std::vector<T>;
78 using base_type =
typename inspector<value_type>::base_type;
80 static constexpr size_t ndim = 1;
83 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
84 std::array<size_t, recursive_ndim> sizes{val.size()};
97 using base_type =
typename inspector<value_type>::base_type;
99 static constexpr size_t ndim = 1;
102 static std::array<size_t, recursive_ndim> getDimensions(
const type& ) {
103 throw std::string(
"Not possible to have size of a T*");
107template <
typename T,
size_t N>
110 using value_type = T;
111 using base_type =
typename inspector<value_type>::base_type;
113 static constexpr size_t ndim = 1;
116 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
117 std::array<size_t, recursive_ndim> sizes{N};
126template <
typename T,
size_t N>
128 using type = std::array<T, N>;
129 using value_type = T;
130 using base_type =
typename inspector<value_type>::base_type;
132 static constexpr size_t ndim = 1;
135 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
136 std::array<size_t, recursive_ndim> sizes{N};
146template <
typename T,
int M,
int N>
147struct inspector<Eigen::Matrix<T, M, N>> {
148 using type = Eigen::Matrix<T, M, N>;
149 using value_type = T;
150 using base_type =
typename inspector<value_type>::base_type;
152 static constexpr size_t ndim = 2;
155 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
156 std::array<size_t, recursive_ndim> sizes{
static_cast<size_t>(val.rows()),
static_cast<size_t>(val.cols())};
158 for (
const auto& s: inspector<value_type>::getDimensions(val.data()[0])) {
167template <
typename T,
size_t Dims>
168struct inspector<boost::multi_array<T, Dims>> {
169 using type = boost::multi_array<T, Dims>;
170 using value_type = T;
171 using base_type =
typename inspector<value_type>::base_type;
173 static constexpr size_t ndim = Dims;
174 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
176 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
177 std::array<size_t, recursive_ndim> sizes;
178 for (
size_t i = 0; i < ndim; ++i) {
179 sizes[i] = val.shape()[i];
183 for (
const auto& s: inspector<value_type>::getDimensions(val.data()[0])) {
191struct inspector<boost::numeric::ublas::matrix<T>> {
192 using type = boost::numeric::ublas::matrix<T>;
193 using value_type = T;
194 using base_type =
typename inspector<value_type>::base_type;
196 static constexpr size_t ndim = 2;
197 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
199 static std::array<size_t, recursive_ndim> getDimensions(
const type& val) {
200 std::array<size_t, recursive_ndim> sizes{val.size1(), val.size2()};
202 for (
const auto& s: inspector<value_type>::getDimensions(val(0, 0))) {
219 typedef typename std::conditional<
220 std::is_same<unqualified_t<T>,
char>::value,
222 typename type_char_array<T>::type
226template <
typename T, std::
size_t N>
228 typedef typename std::conditional<
229 std::is_same<unqualified_t<T>,
char>::value,
231 typename type_char_array<T>::type
239 static const bool value =
false;
244 static const bool value =
true;
250 static const bool value =
false;
255 static const bool value =
true;
258template <
typename T, std::
size_t N>
260 static const bool value =
true;
265template <
typename Size>
266inline std::vector<std::size_t> to_vector_size_t(
const std::vector<Size>& vec) {
267 static_assert(std::is_same<Size, std::size_t>::value ==
false,
268 " hsize_t != size_t mandatory here");
269 std::vector<size_t> res(vec.size());
270 std::transform(vec.cbegin(), vec.cend(), res.begin(), [](Size e) {
271 return static_cast<size_t>(e);
277inline std::vector<std::size_t> to_vector_size_t(
const std::vector<std::size_t>& vec) {
283inline std::string get_name(T fct) {
284 char buffer[H5GT_MAX_PATH_LEN + 1];
285 ssize_t retcode = fct(buffer,
static_cast<hsize_t
>(H5GT_MAX_PATH_LEN) + 1);
287 HDF5ErrMapper::ToException<GroupException>(
"Error accessing object name");
289 const size_t length =
static_cast<std::size_t
>(retcode);
290 if (length <= H5GT_MAX_PATH_LEN) {
291 return std::string(buffer, length);
293 std::vector<char> bigBuffer(length + 1, 0);
294 fct(bigBuffer.data(),
static_cast<hsize_t
>(length) + 1);
295 return std::string(bigBuffer.data(), length);
303inline std::vector<std::string> splitPath(
305 std::vector<std::string> results;
308 while ((cutAt = path.find_first_of(
'/')) != path.npos){
310 results.push_back(path.substr (0,cutAt));
311 path = path.substr(cutAt+1);
314 if (path.length () > 0)
315 results.push_back(path);
328inline std::string splitPathToParentAndObj(
329 const std::string& path,
330 std::string& objName) {
332 return std::string();
334 std::vector<std::string> pathVec = splitPath(path);
337 return std::string();
340 std::string parentPath;
344 for (
size_t i = 0; i < pathVec.size()-1; i++){
345 if (i < pathVec.size()-2)
346 parentPath += pathVec[i] +
'/';
348 parentPath += pathVec[i];
351 objName = pathVec.back();
A structure representing a set of fixed-length strings.
Definition H5DataType.hpp:305
Definition H5Utils.hpp:49
Definition H5Utils.hpp:249
Definition H5Utils.hpp:238
Definition H5Utils.hpp:213