JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpdebuggingtools.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21
22#ifndef JKQTPDEBUGGINGTOOLS_H_INCLUDED
23#define JKQTPDEBUGGINGTOOLS_H_INCLUDED
24#include "jkqtcommon/jkqtcommon_imexport.h"
25#include <QString>
26#include <QElapsedTimer>
27#include <stdexcept>
28
29
30#ifndef __WINDOWS__
31# if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)
32# define __WINDOWS__
33# endif
34#endif
35
36#ifndef __LINUX__
37# if defined(linux)
38# define __LINUX__
39# endif
40#endif
41
42#undef JKTOOLS_TIMER_USE_TIME
43#if defined(__WINDOWS__)
44 #include<windows.h>
45#elif defined(__LINUX__)
46 #include <sys/time.h>
47#else
48 #define JKTOOLS_TIMER_USE_TIME
49#endif
50
51
52
53/** \brief RAII construct that times its lifetime, outputting properly indented qDebug()-message
54 * \ingroup jkqtptools_debugging
55 */
56class JKQTCOMMON_LIB_EXPORT JKQTPAutoOutputTimer : public QElapsedTimer
57{
58 public:
59 explicit JKQTPAutoOutputTimer(const QString& message);
61 void write(const QString& message) const;
62 protected:
63 QString message;
64 QString indent;
65
66
67};
68
69
70/** \brief dynamic assertion, throws an exception with the given \a message, when the given condition \a condition evaluates to \c false
71 * \ingroup jkqtptools_debugging
72 */
73#define JKQTPASSERT_M(condition, message) { if (!(condition)) throw std::runtime_error(std::string(message)+" (expression: "+std::string(#condition)+", function: "+std::string(__FUNCTION__)+", file: "+std::string(__FILE__)+":"+std::to_string(__LINE__)+")"); }
74/** \brief dynamic assertion, throws an exception with the given \a message, when the given condition \a condition evaluates to \c false
75 * \ingroup jkqtptools_debugging
76 */
77#define JKQTPASSERT(condition) { if (!(condition)) throw std::runtime_error("assertion failed (expression: "+std::string(#condition)+", function: "+std::string(__FUNCTION__)+", file: "+std::string(__FILE__)+":"+std::to_string(__LINE__)+")"); }
78
79#endif // JKQTPDEBUGGINGTOOLS_H_INCLUDED
RAII construct that times its lifetime, outputting properly indented qDebug()-message.
Definition jkqtpdebuggingtools.h:57
QString indent
Definition jkqtpdebuggingtools.h:64
QString message
Definition jkqtpdebuggingtools.h:63
void write(const QString &message) const
JKQTPAutoOutputTimer(const QString &message)
#define JKQTCOMMON_LIB_EXPORT
Definition jkqtcommon_imexport.h:87