Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-25 08:27:26

0001 /*
0002  *  Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
0003  *
0004  *  Distributed under the Boost Software License, Version 1.0.
0005  *    (See accompanying file LICENSE_1_0.txt or copy at
0006  *          http://www.boost.org/LICENSE_1_0.txt)
0007  *
0008  */
0009 #pragma once
0010 
0011 // internal utilities functions
0012 #include <algorithm>
0013 #include <array>
0014 #include <cstddef>  // __GLIBCXX__
0015 #include <exception>
0016 #include <string>
0017 #include <type_traits>
0018 #include <vector>
0019 #include <sstream>
0020 
0021 #include <H5public.h>
0022 
0023 #include "../H5Exception.hpp"
0024 #include "H5Friends.hpp"
0025 
0026 namespace HighFive {
0027 
0028 namespace details {
0029 // converter function for hsize_t -> size_t when hsize_t != size_t
0030 template <typename Size>
0031 inline std::vector<std::size_t> to_vector_size_t(const std::vector<Size>& vec) {
0032     static_assert(!std::is_same<Size, std::size_t>::value, " hsize_t != size_t mandatory here");
0033     std::vector<size_t> res(vec.size());
0034     std::transform(vec.cbegin(), vec.cend(), res.begin(), [](Size e) {
0035         return static_cast<size_t>(e);
0036     });
0037     return res;
0038 }
0039 
0040 // converter function for hsize_t -> size_t when size_t == hsize_t
0041 inline std::vector<std::size_t> to_vector_size_t(const std::vector<std::size_t>& vec) {
0042     return vec;
0043 }
0044 
0045 // read name from a H5 object using the specified function
0046 template <typename T>
0047 inline std::string get_name(T fct) {
0048     constexpr size_t maxLength = 255;
0049     std::array<char, maxLength + 1> buffer;
0050     ssize_t retcode = fct(buffer.data(), static_cast<hsize_t>(buffer.size()));
0051     if (retcode < 0) {
0052         HDF5ErrMapper::ToException<GroupException>("Error accessing object name");
0053     }
0054     const size_t length = static_cast<std::size_t>(retcode);
0055     if (length <= maxLength) {
0056         return std::string(buffer.data(), length);
0057     }
0058     std::vector<char> bigBuffer(length + 1, 0);
0059     fct(bigBuffer.data(), length + 1);
0060     return std::string(bigBuffer.data(), length);
0061 }
0062 
0063 template <class Container>
0064 inline std::string format_vector(const Container& container) {
0065     auto sout = std::stringstream{};
0066 
0067     sout << "[ ";
0068     for (size_t i = 0; i < container.size(); ++i) {
0069         sout << container[i] << (i == container.size() - 1 ? "" : ", ");
0070     }
0071     sout << "]";
0072 
0073     return sout.str();
0074 }
0075 
0076 }  // namespace details
0077 }  // namespace HighFive