2019-05-23 04:20:00 +08:00
|
|
|
/*
|
2024-02-06 21:50:49 +08:00
|
|
|
Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
|
2019-05-23 04:20:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef JKQTPDEBUGGINGTOOLS_H_INCLUDED
|
|
|
|
#define JKQTPDEBUGGINGTOOLS_H_INCLUDED
|
2019-06-22 20:21:32 +08:00
|
|
|
#include "jkqtcommon/jkqtcommon_imexport.h"
|
2019-05-23 04:20:00 +08:00
|
|
|
#include <QString>
|
|
|
|
#include <QElapsedTimer>
|
2020-10-02 21:41:42 +08:00
|
|
|
#include <stdexcept>
|
2019-05-23 04:20:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __WINDOWS__
|
|
|
|
# if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)
|
|
|
|
# define __WINDOWS__
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __LINUX__
|
|
|
|
# if defined(linux)
|
|
|
|
# define __LINUX__
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef JKTOOLS_TIMER_USE_TIME
|
|
|
|
#if defined(__WINDOWS__)
|
|
|
|
#include<windows.h>
|
|
|
|
#elif defined(__LINUX__)
|
|
|
|
#include <sys/time.h>
|
|
|
|
#else
|
|
|
|
#define JKTOOLS_TIMER_USE_TIME
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief RAII construct that times its lifetime, outputting properly indented qDebug()-message
|
|
|
|
* \ingroup jkqtptools_debugging
|
|
|
|
*/
|
2019-06-22 20:21:32 +08:00
|
|
|
class JKQTCOMMON_LIB_EXPORT JKQTPAutoOutputTimer : public QElapsedTimer
|
2019-05-23 04:20:00 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit JKQTPAutoOutputTimer(const QString& message);
|
|
|
|
~JKQTPAutoOutputTimer();
|
|
|
|
void write(const QString& message) const;
|
|
|
|
protected:
|
|
|
|
QString message;
|
|
|
|
QString indent;
|
2023-06-30 19:52:17 +08:00
|
|
|
|
2019-05-23 04:20:00 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-30 04:40:02 +08:00
|
|
|
/** \brief dynamic assertion, throws an exception with the given \a message, when the given condition \a condition evaluates to \c false
|
|
|
|
* \ingroup jkqtptools_debugging
|
|
|
|
*/
|
2024-01-10 17:30:55 +08:00
|
|
|
#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__)+")"); }
|
2019-05-30 04:40:02 +08:00
|
|
|
/** \brief dynamic assertion, throws an exception with the given \a message, when the given condition \a condition evaluates to \c false
|
|
|
|
* \ingroup jkqtptools_debugging
|
|
|
|
*/
|
2024-01-10 17:30:55 +08:00
|
|
|
#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__)+")"); }
|
2019-05-23 04:20:00 +08:00
|
|
|
|
|
|
|
#endif // JKQTPDEBUGGINGTOOLS_H_INCLUDED
|