HyperHDG
tpp_assert.hxx
Go to the documentation of this file.
1 /*!*************************************************************************************************
2  * \file tpp_assert.hxx
3  * \brief This file provides the function \c tpp_assert.
4  *
5  * This is a wrapper file to provide a function that allows to use assertions that are similar to
6  * those provided by cassert. That is, we define a macro \c tpp_assert that implements assert.
7  * If a user wants to use assertions, it is recommended to use \c tpp_assert(\c Expr, \c Msg). The
8  * use of the function \c __TPP_Assert is \b not recommended.
9  *
10  * Whether this functionality is active or not can be deduced via setting \c NDEBUG, when the code
11  * is compiled. Using this functionality makes your program significantly slower. However, usage is
12  * highly recommended for testing.
13  *
14  * \authors Andreas Rupp, Heidelberg University, 2021.
15  **************************************************************************************************/
16 
17 #pragma once // Ensure that file is included only once in a single compilation.
18 
19 #ifndef NDEBUG
20 #include <iostream>
21 #endif
22 
23 namespace TPP
24 {
25 #ifndef NDEBUG
26 
27 /*!*************************************************************************************************
28  * \brief The assertion to be used within tpp --- deactivate using -DNDEBUG compile flag.
29  *
30  * \param Expr C++ Expression that can be evaluated to \c true or \c false.
31  * \param Msg Message that is to be displayed if \c Expr is evaluated to \c false.
32  **************************************************************************************************/
33 #define tpp_assert(Expr, Msg) __TPP_Assert(#Expr, Expr, __FILE__, __LINE__, Msg)
34 
35 // -------------------------------------------------------------------------------------------------
37 // -------------------------------------------------------------------------------------------------
38 
39 /*!*************************************************************************************************
40  * \brief This function is not (never) to be used.
41  *
42  * This function is \b not to be used in regular code. It only / solely is defined to allow the use
43  * of function \c tpp_assert( \c Expr, \c Msg) which is implemented as a macro in file HyAssert.hxx.
44  **************************************************************************************************/
45 constexpr void __TPP_Assert(const char* exp_str,
46  bool exp,
47  const char* file,
48  int line,
49  const char* msg)
50 {
51  if (!exp)
52  {
53  std::cerr << "Assert failed: " << msg << std::endl
54  << "Expected: " << exp_str << std::endl
55  << "Source: " << file << ", line " << line << std::endl;
56  abort();
57  }
58 }
59 
60 #else // alternative branch of ifndef NDEBUG
61 #define tpp_assert(Expr, Msg) ;
62 #endif // end of ifndef NDEBUG
63 
64 // -------------------------------------------------------------------------------------------------
66 // -------------------------------------------------------------------------------------------------
67 
68 } // end of namespace TPP
TPP
Contains the functionalities to evaluate and integrate tensor product type polynomials.
Definition: compile_time_tricks.hxx:7
file
to the best of my is covered under an appropriate open source license and I have the right under that license to submit that work with whether created in whole or in part by under the same open source as indicated in the file
Definition: DeveloperCertificateOfOrigin.txt:27