h5cpp  0.5.1
A modern C++ wrapper for the HDF5 C library
h5c_error.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2017 DESY,ESS
3 //
4 // This file is part of h5cpp.
5 //
6 // This library is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation; either version 2.1 of the License, or
9 // (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the
18 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
19 // Boston, MA 02110-1301 USA
20 // ===========================================================================
21 //
22 // Author: Martin Shetty <martin.shetty@esss.se>
23 // Created on: Oct 25, 2017
24 //
25 #pragma once
26 
28 #include <sstream>
29 #include <stdexcept>
30 #include <list>
31 
32 namespace hdf5 {
33 namespace error {
34 
43 #ifdef __clang__
44 #pragma clang diagnostic push
45 #pragma clang diagnostic ignored "-Wweak-vtables"
46 #endif
47 class H5CError : public std::runtime_error
48 {
49  public:
58  H5CError(const std::list<Descriptor>& H5CError);
59 
66  const char* what() const noexcept override;
67 
73  const std::list<Descriptor>& contents() const;
74 
80  bool empty() const;
81 
82  private:
83  std::list<Descriptor> contents_;
84  std::string what_message_;
85 };
86 #ifdef __clang__
87 #pragma clang diagnostic pop
88 #endif
89 
90 inline H5CError::H5CError(const std::list<Descriptor>& H5CError)
91 : std::runtime_error("")
92 , contents_(H5CError)
93 {
94  std::stringstream ss;
95  for (auto& c : contents_)
96  {
97  c.extract_strings();
98  ss << c << "\n";
99  }
100  what_message_ = ss.str();
101 }
102 
103 
104 inline const char* H5CError::what() const noexcept
105 {
106  return what_message_.c_str();
107 }
108 
109 inline const std::list<Descriptor>& H5CError::contents() const
110 {
111  return contents_;
112 }
113 
114 inline bool H5CError::empty() const
115 {
116  return contents_.empty();
117 }
118 
119 } // namespace file
120 } // namespace hdf5
runtime exception containing an HDF5 error H5CError
Definition: h5c_error.hpp:48
bool empty() const
what it says
Definition: h5c_error.hpp:114
const char * what() const noexcept override
printout of error H5CError
Definition: h5c_error.hpp:104
H5CError(const std::list< Descriptor > &H5CError)
constructor
Definition: h5c_error.hpp:90
const std::list< Descriptor > & contents() const
access to error H5CError
Definition: h5c_error.hpp:109
top-level namespace of the entire library
Definition: attribute.hpp:45