TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches
macros.hpp
Go to the documentation of this file.
1// Copyright (c) 2019-2024 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
22#ifndef LIBH5_MACROS_HPP
23#define LIBH5_MACROS_HPP
24
25#include <iostream>
26#include <exception>
27
28// ---------------- Stringify ----------------
29
30#define H5_AS_STRING(...) H5_AS_STRING2(__VA_ARGS__)
31#define H5_AS_STRING2(...) #__VA_ARGS__
32
33// ---------------- Requires ----------------
34
35#ifdef __clang__
36#define H5_REQUIRES(...) __attribute__((enable_if(__VA_ARGS__, H5_AS_STRING2(__VA_ARGS__))))
37#elif __GNUC__
38#define H5_REQUIRES(...) requires(__VA_ARGS__)
39#endif
40
41// ---------------- Print ----------------
42
43#define H5_PRINT(X) std::cerr << H5_AS_STRING(X) << " = " << X << " at " << __FILE__ << ":" << __LINE__ << '\n'
44
45// ---------------- Inline ----------------
46
47#define H5_FORCEINLINE __inline__ __attribute__((always_inline))
48
49// ---------------- Debugging ----------------
50
51#define H5_EXPECTS(X) \
52 if (!(X)) { \
53 std::cerr << "Precondition " << H5_AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
54 std::terminate(); \
55 }
56#define H5_ASSERT(X) \
57 if (!(X)) { \
58 std::cerr << "Assertion " << H5_AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
59 std::terminate(); \
60 }
61#define H5_ENSURES(X) \
62 if (!(X)) { \
63 std::cerr << "Postcondition " << H5_AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
64 std::terminate(); \
65 }
66
67#endif // LIBH5_MACROS_HPP