qpmad
Eigen-based C++ QP solver.
cpput_exception.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2019 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @brief Throw & assert macro
9 */
10 
11 #ifndef H_QPMAD_UTILS_EXCEPTION
12 #define H_QPMAD_UTILS_EXCEPTION
13 
14 #include <string>
15 #include <stdexcept>
16 
17 #define QPMAD_UTILS_THROW_EXCEPTION(exception_type, message) throw exception_type((message))
18 
19 #ifdef CMAKEUT_COMPILER_SUPPORTS_FUNC_
20 # define QPMAD_UTILS_THROW(s) QPMAD_UTILS_THROW_EXCEPTION(std::runtime_error, (std::string("In ") + __func__ + "() // " + (s)))
21 #else //
22 # ifdef CMAKEUT_COMPILER_SUPPORTS_FUNCTION_
23 # define QPMAD_UTILS_THROW(s) \
24  QPMAD_UTILS_THROW_EXCEPTION(std::runtime_error, (std::string("In ") + __FUNCTION__ + "() // " + (s)))
25 # else //
26 # define QPMAD_UTILS_THROW(s) QPMAD_UTILS_THROW_EXCEPTION(std::runtime_error, (s))
27 # endif //
28 #endif //
29 
30 
31 #define QPMAD_UTILS_PERSISTENT_ASSERT(condition, message) \
32  if (!(condition)) \
33  { \
34  QPMAD_UTILS_THROW(message); \
35  };
36 
37 #ifdef DNDEBUG
38 # define QPMAD_UTILS_ASSERT(condition, message)
39 #else
40 # define QPMAD_UTILS_ASSERT(condition, message) QPMAD_UTILS_PERSISTENT_ASSERT(condition, message)
41 #endif
42 
43 #endif