UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils_trace.hh
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2017 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Università degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
20//
21// file: Utils_trace.hh
22//
23
24#pragma once
25
26#ifndef UTILS_TRACE_HH
27#define UTILS_TRACE_HH
28
29#include "Utils.hh"
30
31#ifndef DOXYGEN_SHOULD_SKIP_THIS
32
33#ifndef UTILS_ERROR_TRACE0
34 #define UTILS_ERROR_TRACE0(MSG) \
35 throw Utils::Runtime_TraceError( MSG, __FILENAME__, __LINE__ )
36#endif
37
38#ifndef UTILS_ASSERT_TRACE0
39 #define UTILS_ASSERT_TRACE0(COND,MSG) if ( !(COND) ) UTILS_ERROR_TRACE0( MSG )
40#endif
41
42#ifndef UTILS_ERROR_TRACE
43 #define UTILS_ERROR_TRACE(...) \
44 throw Utils::Runtime_TraceError( fmt::format(__VA_ARGS__), __FILENAME__, __LINE__ )
45#endif
46
47#ifndef UTILS_ASSERT_TRACE
48 #define UTILS_ASSERT_TRACE(COND,...) if ( !(COND) ) UTILS_ERROR_TRACE( __VA_ARGS__ )
49#endif
50
51#endif
52
53#ifdef __GNUC__
54#pragma GCC diagnostic push
55#pragma GCC diagnostic ignored "-Wpadded"
56#endif
57#ifdef __clang__
58#pragma clang diagnostic push
59#pragma clang diagnostic ignored "-Wpadded"
60#endif
61
62namespace Utils {
63
64 using std::string;
65 using std::runtime_error;
66
71
86 void
88 int line,
89 string_view file,
90 string_view msg,
91 ostream_type & stream
92 );
93
97 inline
98 void
100 int line,
101 string_view file,
102 string_view reason,
103 ostream_type & stream
104 ) {
105 print_trace( line, file, reason, stream );
106 }
107
118 class Runtime_TraceError : public runtime_error {
119 private:
133 static
134 string
135 grab_backtrace(
136 string_view reason,
137 string_view file,
138 int line
139 );
140
141 public:
152 explicit
154 string_view reason,
155 string_view file,
156 int line
157 )
158 : std::runtime_error( grab_backtrace( reason, file, line ) )
159 { }
160
161 char const * what() const noexcept override;
162 };
163
165
166}
167
168#endif
169
170//
171// eof: Utils_trace.hh
172//
Runtime_TraceError(string_view reason, string_view file, int line)
Constructs a Runtime_TraceError with a backtrace.
Definition Utils_trace.hh:153
char const * what() const noexcept override
void printTrace(int line, string_view file, string_view reason, ostream_type &stream)
Definition Utils_trace.hh:99
void print_trace(int line, string_view file, string_view msg, ostream_type &stream)
Prints a formatted trace message to the specified stream.
Definition SystemUtils.cc:39
std::basic_ostream< char > ostream_type
Type for output stream.
Definition Console.hxx:28