|
84 | 84 | /** |
85 | 85 | * @brief Abort execution if @p EXP is true. |
86 | 86 | * @param EXP The expression to check. |
87 | | - * @param MSG The message to associate with the error, can be anything streamable to std::cout. |
| 87 | + * @param MSG The message to associate with the error, can be anything streamable to a std::ostream. |
88 | 88 | * @note This macro can be used in both host and device code. |
89 | 89 | * @note Tries to provide as much information about the location of the error |
90 | 90 | * as possible. On host this should result in the file and line of the error |
|
117 | 117 |
|
118 | 118 | /** |
119 | 119 | * @brief Abort execution. |
120 | | - * @param MSG The message to associate with the error, can be anything streamable to std::cout. |
| 120 | + * @param MSG The message to associate with the error, can be anything streamable to a std::ostream. |
121 | 121 | */ |
122 | 122 | #define LVARRAY_ERROR( MSG ) LVARRAY_ERROR_IF( true, MSG ) |
123 | 123 |
|
124 | 124 | /** |
125 | 125 | * @brief Abort execution if @p EXP is false but only when |
126 | 126 | * NDEBUG is not defined.. |
127 | 127 | * @param EXP The expression to check. |
128 | | - * @param MSG The message to associate with the error, can be anything streamable to std::cout. |
| 128 | + * @param MSG The message to associate with the error, can be anything streamable to a std::ostream. |
129 | 129 | * @note This macro can be used in both host and device code. |
130 | 130 | * @note Tries to provide as much information about the location of the error |
131 | 131 | * as possible. On host this should result in the file and line of the error |
|
138 | 138 | #define LVARRAY_ASSERT_MSG( EXP, MSG ) ((void) 0) |
139 | 139 | #endif |
140 | 140 |
|
| 141 | +#define LVARRAY_THROW_IF( EXP, MSG, TYPE ) \ |
| 142 | + do \ |
| 143 | + { \ |
| 144 | + if( EXP ) \ |
| 145 | + { \ |
| 146 | + std::ostringstream __oss; \ |
| 147 | + __oss << "\n"; \ |
| 148 | + __oss << "***** LOCATION: " LOCATION "\n"; \ |
| 149 | + __oss << "***** Controlling expression (should be false): " STRINGIZE( EXP ) "\n"; \ |
| 150 | + __oss << MSG << "\n"; \ |
| 151 | + __oss << LvArray::system::stackTrace( true ); \ |
| 152 | + throw TYPE( __oss.str() ); \ |
| 153 | + } \ |
| 154 | + } while( false ) |
| 155 | + |
141 | 156 | /// Assert @p EXP is true with no message. |
142 | 157 | #define LVARRAY_ASSERT( EXP ) LVARRAY_ASSERT_MSG( EXP, "" ) |
143 | 158 |
|
144 | 159 | /** |
145 | 160 | * @brief Print a warning if @p EXP is true. |
146 | 161 | * @param EXP The expression to check. |
147 | | - * @param MSG The message to associate with the warning, can be anything streamable to std::cout. |
| 162 | + * @param MSG The message to associate with the warning, can be anything streamable to a std::ostream. |
148 | 163 | */ |
149 | 164 | #define LVARRAY_WARNING_IF( EXP, MSG ) \ |
150 | 165 | do \ |
|
206 | 221 | " " << #lhs << " = " << lhs << "\n" << \ |
207 | 222 | " " << #rhs << " = " << rhs << "\n" ) |
208 | 223 |
|
| 224 | +#define LVARRAY_THROW_IF_OP_MSG( lhs, OP, NOP, rhs, msg, TYPE ) \ |
| 225 | + LVARRAY_THROW_IF( lhs OP rhs, \ |
| 226 | + msg << "\n" << \ |
| 227 | + "Expected " << #lhs << " " << #NOP << " " << #rhs << "\n" << \ |
| 228 | + " " << #lhs << " = " << lhs << "\n" << \ |
| 229 | + " " << #rhs << " = " << rhs << "\n", TYPE ) |
| 230 | + |
209 | 231 | /** |
210 | 232 | * @brief Raise a hard error if two values are equal. |
211 | 233 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
|
214 | 236 | */ |
215 | 237 | #define LVARRAY_ERROR_IF_EQ_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, ==, !=, rhs, msg ) |
216 | 238 |
|
| 239 | +#define LVARRAY_THROW_IF_EQ_MSG( lhs, rhs, msg, TYPE ) LVARRAY_THROW_IF_OP_MSG( lhs, ==, !=, rhs, msg, TYPE ) |
| 240 | + |
217 | 241 | /** |
218 | 242 | * @brief Raise a hard error if two values are equal. |
219 | 243 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
220 | 244 | * @param rhs expression to be evaluated and used as right-hand side in comparison |
221 | 245 | */ |
222 | 246 | #define LVARRAY_ERROR_IF_EQ( lhs, rhs ) LVARRAY_ERROR_IF_EQ_MSG( lhs, rhs, "" ) |
223 | 247 |
|
| 248 | +#define LVARRAY_THROW_IF_EQ( lhs, rhs, TYPE ) LVARRAY_THROW_IF_EQ_MSG( lhs, rhs, "", TYPE ) |
| 249 | + |
224 | 250 | /** |
225 | 251 | * @brief Raise a hard error if two values are not equal. |
226 | 252 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
|
229 | 255 | */ |
230 | 256 | #define LVARRAY_ERROR_IF_NE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, !=, ==, rhs, msg ) |
231 | 257 |
|
| 258 | +#define LVARRAY_THROW_IF_NE_MSG( lhs, rhs, msg, TYPE ) LVARRAY_THROW_IF_OP_MSG( lhs, !=, ==, rhs, msg, TYPE ) |
| 259 | + |
232 | 260 | /** |
233 | 261 | * @brief Raise a hard error if two values are not equal. |
234 | 262 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
235 | 263 | * @param rhs expression to be evaluated and used as right-hand side in comparison |
236 | 264 | */ |
237 | 265 | #define LVARRAY_ERROR_IF_NE( lhs, rhs ) LVARRAY_ERROR_IF_NE_MSG( lhs, rhs, "" ) |
238 | 266 |
|
| 267 | +#define LVARRAY_THROW_IF_NE( lhs, rhs, TYPE ) LVARRAY_THROW_IF_NE_MSG( lhs, rhs, "", TYPE ) |
| 268 | + |
239 | 269 | /** |
240 | 270 | * @brief Raise a hard error if one value compares greater than the other. |
241 | 271 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
|
244 | 274 | */ |
245 | 275 | #define LVARRAY_ERROR_IF_GT_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, >, <=, rhs, msg ) |
246 | 276 |
|
| 277 | +#define LVARRAY_THROW_IF_GT_MSG( lhs, rhs, msg, TYPE ) LVARRAY_THROW_IF_OP_MSG( lhs, >, <=, rhs, msg, TYPE ) |
| 278 | + |
247 | 279 | /** |
248 | 280 | * @brief Raise a hard error if one value compares greater than the other. |
249 | 281 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
250 | 282 | * @param rhs expression to be evaluated and used as right-hand side in comparison |
251 | 283 | */ |
252 | 284 | #define LVARRAY_ERROR_IF_GT( lhs, rhs ) LVARRAY_ERROR_IF_GT_MSG( lhs, rhs, "" ) |
253 | 285 |
|
| 286 | +#define LVARRAY_THROW_IF_GT( lhs, rhs, TYPE ) LVARRAY_THROW_IF_GT_MSG( lhs, rhs, "", TYPE ) |
| 287 | + |
254 | 288 | /** |
255 | 289 | * @brief Raise a hard error if one value compares greater than or equal to the other. |
256 | 290 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
|
259 | 293 | */ |
260 | 294 | #define LVARRAY_ERROR_IF_GE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, >=, <, rhs, msg ) |
261 | 295 |
|
| 296 | +#define LVARRAY_THROW_IF_GE_MSG( lhs, rhs, msg, TYPE ) LVARRAY_THROW_IF_OP_MSG( lhs, >=, <, rhs, msg, TYPE ) |
| 297 | + |
262 | 298 | /** |
263 | 299 | * @brief Raise a hard error if one value compares greater than or equal to the other. |
264 | 300 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
265 | 301 | * @param rhs expression to be evaluated and used as right-hand side in comparison |
266 | 302 | */ |
267 | 303 | #define LVARRAY_ERROR_IF_GE( lhs, rhs ) LVARRAY_ERROR_IF_GE_MSG( lhs, rhs, "" ) |
268 | 304 |
|
| 305 | +#define LVARRAY_THROW_IF_GE( lhs, rhs, TYPE ) LVARRAY_THROW_IF_GE_MSG( lhs, rhs, "", TYPE ) |
| 306 | + |
| 307 | + |
269 | 308 | /** |
270 | 309 | * @brief Raise a hard error if one value compares less than the other. |
271 | 310 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
|
274 | 313 | */ |
275 | 314 | #define LVARRAY_ERROR_IF_LT_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, <, >=, rhs, msg ) |
276 | 315 |
|
| 316 | +#define LVARRAY_THROW_IF_LT_MSG( lhs, rhs, msg, TYPE ) LVARRAY_THROW_IF_OP_MSG( lhs, <, >=, rhs, msg, TYPE ) |
| 317 | + |
277 | 318 | /** |
278 | 319 | * @brief Raise a hard error if one value compares less than the other. |
279 | 320 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
280 | 321 | * @param rhs expression to be evaluated and used as right-hand side in comparison |
281 | 322 | */ |
282 | 323 | #define LVARRAY_ERROR_IF_LT( lhs, rhs ) LVARRAY_ERROR_IF_LT_MSG( lhs, rhs, "" ) |
283 | 324 |
|
| 325 | +#define LVARRAY_THROW_IF_LT( lhs, rhs, TYPE ) LVARRAY_THROW_IF_LT_MSG( lhs, rhs, "", TYPE ) |
| 326 | + |
284 | 327 | /** |
285 | 328 | * @brief Raise a hard error if one value compares less than or equal to the other. |
286 | 329 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
|
289 | 332 | */ |
290 | 333 | #define LVARRAY_ERROR_IF_LE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, <=, >, rhs, msg ) |
291 | 334 |
|
| 335 | +#define LVARRAY_THROW_IF_LE_MSG( lhs, rhs, msg, TYPE ) LVARRAY_THROW_IF_OP_MSG( lhs, <=, >, rhs, msg, TYPE ) |
| 336 | + |
292 | 337 | /** |
293 | 338 | * @brief Raise a hard error if one value compares less than or equal to the other. |
294 | 339 | * @param lhs expression to be evaluated and used as left-hand side in comparison |
295 | 340 | * @param rhs expression to be evaluated and used as right-hand side in comparison |
296 | 341 | */ |
297 | 342 | #define LVARRAY_ERROR_IF_LE( lhs, rhs ) LVARRAY_ERROR_IF_GE_MSG( lhs, rhs, "" ) |
298 | 343 |
|
| 344 | +#define LVARRAY_THROW_IF_LE( lhs, rhs, TYPE ) LVARRAY_THROW_IF_GE_MSG( lhs, rhs, "", TYPE ) |
| 345 | + |
299 | 346 | /** |
300 | 347 | * @brief Abort execution if @p lhs @p OP @p rhs is false. |
301 | 348 | * @param lhs The left side of the operation. |
|
0 commit comments