byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
assert.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 Kristiyan Manev (University of Manchester)
3  *
4  * Licensed under the Apache License, Version 2.0(the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #ifndef ASSERT_H
18 #define ASSERT_H
19 
20 #include<stdexcept>
21 /*
22  throwingAssertPrintVar_{N} takes {N} additional arguments and prints their values if assert fails
23 */
24 #ifdef NDEBUG
25  #define throwingAssert(left, operator, right) {;}
26  #define throwingAssertPrintVar_1(left, operator, right, var1) {;}
27  #define throwingAssertPrintVar_2(left, operator, right, var1, var2) {;}
28  #define throwingAssertPrintVar_3(left, operator, right, var1, var2, var3) {;}
29  #define throwingAssertPrintVar_4(left, operator, right, var1, var2, var3, var4) {;}
30  #define throwingAssertPrintVar_5(left, operator, right, var1, var2, var3, var4, var5) {;}
31 #else
32  #define throwingAssert(left, operator, right) {if(!((left) operator (right))){ throw std::runtime_error(std::string("Assertion failed in ").append(__FILE__).append(":").append(std::to_string(__LINE__)).append(":\n\tassert(").append(#left).append(" ").append(#operator).append(" ").append(#right).append(")\n\twith variable values:\n\t\t").append(#left).append(" = ").append(std::to_string(left)).append("\n\t\t").append(#right).append(" = ").append(std::to_string(right)) ); }}
33  #define throwingAssertPrintVar_1(left, operator, right, var1) {if(!((left) operator (right))){ throw std::runtime_error(std::string("Assertion failed in ").append(__FILE__).append(":").append(std::to_string(__LINE__)).append(":\n\tassert(").append(#left).append(" ").append(#operator).append(" ").append(#right).append(")\n\twith variable values:\n\t\t").append(#left).append(" = ").append(std::to_string(left)).append("\n\t\t").append(#right).append(" = ").append(std::to_string(right)).append("\n\t\t").append(#var1).append(" = ").append(std::to_string(var1)) ); }}
34  #define throwingAssertPrintVar_2(left, operator, right, var1, var2) {if(!((left) operator (right))){ throw std::runtime_error(std::string("Assertion failed in ").append(__FILE__).append(":").append(std::to_string(__LINE__)).append(":\n\tassert(").append(#left).append(" ").append(#operator).append(" ").append(#right).append(")\n\twith variable values:\n\t\t").append(#left).append(" = ").append(std::to_string(left)).append("\n\t\t").append(#right).append(" = ").append(std::to_string(right)).append("\n\t\t").append(#var1).append(" = ").append(std::to_string(var1)).append("\n\t\t").append(#var2).append(" = ").append(std::to_string(var2)) ); }}
35  #define throwingAssertPrintVar_3(left, operator, right, var1, var2, var3) {if(!((left) operator (right))){ throw std::runtime_error(std::string("Assertion failed in ").append(__FILE__).append(":").append(std::to_string(__LINE__)).append(":\n\tassert(").append(#left).append(" ").append(#operator).append(" ").append(#right).append(")\n\twith variable values:\n\t\t").append(#left).append(" = ").append(std::to_string(left)).append("\n\t\t").append(#right).append(" = ").append(std::to_string(right)).append("\n\t\t").append(#var1).append(" = ").append(std::to_string(var1)).append("\n\t\t").append(#var2).append(" = ").append(std::to_string(var2)).append("\n\t\t").append(#var3).append(" = ").append(std::to_string(var3)) ); }}
36  #define throwingAssertPrintVar_4(left, operator, right, var1, var2, var3, var4) {if(!((left) operator (right))){ throw std::runtime_error(std::string("Assertion failed in ").append(__FILE__).append(":").append(std::to_string(__LINE__)).append(":\n\tassert(").append(#left).append(" ").append(#operator).append(" ").append(#right).append(")\n\twith variable values:\n\t\t").append(#left).append(" = ").append(std::to_string(left)).append("\n\t\t").append(#right).append(" = ").append(std::to_string(right)).append("\n\t\t").append(#var1).append(" = ").append(std::to_string(var1)).append("\n\t\t").append(#var2).append(" = ").append(std::to_string(var2)).append("\n\t\t").append(#var3).append(" = ").append(std::to_string(var3)).append("\n\t\t").append(#var4).append(" = ").append(std::to_string(var4)) ); }}
37  #define throwingAssertPrintVar_5(left, operator, right, var1, var2, var3, var4, var5) {if(!((left) operator (right))){ throw std::runtime_error(std::string("Assertion failed in ").append(__FILE__).append(":").append(std::to_string(__LINE__)).append(":\n\tassert(").append(#left).append(" ").append(#operator).append(" ").append(#right).append(")\n\twith variable values:\n\t\t").append(#left).append(" = ").append(std::to_string(left)).append("\n\t\t").append(#right).append(" = ").append(std::to_string(right)).append("\n\t\t").append(#var1).append(" = ").append(std::to_string(var1)).append("\n\t\t").append(#var2).append(" = ").append(std::to_string(var2)).append("\n\t\t").append(#var3).append(" = ").append(std::to_string(var3)).append("\n\t\t").append(#var4).append(" = ").append(std::to_string(var4)).append("\n\t\t").append(#var5).append(" = ").append(std::to_string(var5)) ); }}
38 #endif
39 
40 #endif//ASSERT_H