qpmad
Eigen-based C++ QP solver.
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_EXCEPTION
12 #define H_QPMAD_EXCEPTION
13 
14 #include <stdexcept>
15 
16 #define QPMAD_UTILS_THROW_EXCEPTION(exception_type, message) throw exception_type((message))
17 
18 #define QPMAD_UTILS_THROW(s) \
19  QPMAD_UTILS_THROW_EXCEPTION(std::runtime_error, (std::string("In ") + __func__ + "() // " + (s)))
20 
21 
22 #define QPMAD_UTILS_PERSISTENT_ASSERT(condition, ...) \
23  if (!(condition)) \
24  { \
25  QPMAD_UTILS_THROW(__VA_ARGS__); \
26  };
27 
28 #ifdef DNDEBUG
29 # define QPMAD_UTILS_ASSERT(condition, ...)
30 #else
31 # define QPMAD_UTILS_ASSERT(condition, ...) QPMAD_UTILS_PERSISTENT_ASSERT(condition, __VA_ARGS__)
32 #endif
33 
34 #endif