libquentier  0.5.0
The library for rich desktop clients of Evernote service
QuentierCheckPtr.h
1 /*
2  * Copyright 2016-2020 Dmitry Ivanov
3  *
4  * This file is part of libquentier
5  *
6  * libquentier 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, version 3 of the License.
9  *
10  * libquentier is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LIB_QUENTIER_UTILITY_QUENTIER_CHECK_PTR_H
20 #define LIB_QUENTIER_UTILITY_QUENTIER_CHECK_PTR_H
21 
22 #include <quentier/exception/NullPtrException.h>
23 #include <quentier/logging/QuentierLogger.h>
24 
25 #ifndef QUENTIER_CHECK_PTR
26 #define QUENTIER_CHECK_PTR(pointer, ...) \
27 { \
28  if (Q_UNLIKELY(!pointer)) \
29  { \
30  using quentier::NullPtrException; \
31  ErrorString quentier_null_ptr_error( \
32  QT_TRANSLATE_NOOP("", "Detected unintended null pointer")); \
33  quentier_null_ptr_error.details() = QStringLiteral(__FILE__); \
34  quentier_null_ptr_error.details() += QStringLiteral(" ("); \
35  quentier_null_ptr_error.details() += QString::number(__LINE__); \
36  quentier_null_ptr_error.details() += QStringLiteral(") "); \
37  quentier_null_ptr_error.details() += \
38  QString::fromUtf8("" #__VA_ARGS__ ""); \
39  QNERROR(quentier_null_ptr_error); \
40  throw NullPtrException(quentier_null_ptr_error); \
41  } \
42 } \
43 // QUENTIER_CHECK_PTR
44 #endif
45 
46 #endif // LIB_QUENTIER_UTILITY_QUENTIER_CHECK_PTR_H