Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:20:39

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 #include <cstdlib>
0012 #include <sstream>
0013 
0014 #include "h5_wrapper.hpp"
0015 #include "h5e_wrapper.hpp"
0016 
0017 namespace HighFive {
0018 
0019 struct HDF5ErrMapper {
0020     template <typename ExceptionType>
0021     static inline herr_t stackWalk(unsigned /* n */,
0022                                    const H5E_error2_t* err_desc,
0023                                    void* client_data) {
0024         auto** e_iter = static_cast<ExceptionType**>(client_data);
0025 
0026         const char* major_err = detail::nothrow::h5e_get_major(err_desc->maj_num);
0027         const char* minor_err = detail::nothrow::h5e_get_minor(err_desc->min_num);
0028 
0029         std::ostringstream oss;
0030         oss << '(' << major_err << ") " << minor_err;
0031 
0032         detail::nothrow::h5_free_memory((void*) major_err);
0033         detail::nothrow::h5_free_memory((void*) minor_err);
0034 
0035         auto* e = new ExceptionType(oss.str());
0036         e->_err_major = err_desc->maj_num;
0037         e->_err_minor = err_desc->min_num;
0038         (*e_iter)->_next.reset(e);
0039         *e_iter = e;
0040         return 0;
0041     }
0042 
0043     template <typename ExceptionType>
0044     [[noreturn]] static inline void ToException(const std::string& prefix_msg) {
0045         hid_t err_stack = H5Eget_current_stack();
0046         if (err_stack >= 0) {
0047             ExceptionType e("");
0048             ExceptionType* e_iter = &e;
0049 
0050             detail::nothrow::h5e_walk2(err_stack,
0051                                        H5E_WALK_UPWARD,
0052                                        &HDF5ErrMapper::stackWalk<ExceptionType>,
0053                                        (void*) &e_iter);
0054             detail::nothrow::h5e_clear2(err_stack);
0055 
0056             const char* next_err_msg = (e.nextException() != NULL) ? (e.nextException()->what())
0057                                                                    : ("");
0058 
0059             e.setErrorMsg(prefix_msg + " " + next_err_msg);
0060             throw e;
0061         }
0062         // throw generic error, unrecognized error
0063         throw ExceptionType(prefix_msg + ": Unknown HDF5 error");
0064     }
0065 };
0066 
0067 }  // namespace HighFive