xerus
a general purpose tensor library
check.h
Go to the documentation of this file.
1 // Xerus - A General Purpose Tensor Library
2 // Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3 //
4 // Xerus is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published
6 // by the Free Software Foundation, either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // Xerus is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // For further information on Xerus visit https://libXerus.org
18 // or contact us at contact@libXerus.org.
19 
25 #pragma once
26 
48 #ifdef XERUS_TEST_COVERAGE
49  #include "../test/test.h"
50 #else
51  #define XERUS_REQUIRE_TEST (void)0
52 #endif
53 
54 #ifndef XERUS_DISABLE_RUNTIME_CHECKS
55  #include "namedLogger.h"
56  #include "callStack.h"
57  #include "containerOutput.h"
58 
59  #ifdef XERUS_TEST_COVERAGE
60  #define XERUS_CHECK(condition, level, message) XERUS_REQUIRE_TEST; if(XERUS_IS_LOGGING(level) && !(condition)) { XERUS_LOG(level, #condition " failed msg: " << message); } else void(0)
61  #else
62  #define XERUS_CHECK(condition, level, message) if(XERUS_IS_LOGGING(level) && !(condition)) { XERUS_LOG(level, #condition " failed msg: " << message); } else void(0)
63  #endif
64 
65  #define XERUS_REQUIRE(condition, message) XERUS_CHECK(condition, error, message)
66 
67  #define XERUS_INTERNAL_CHECK(condition, message) \
68  if(!(condition)) { \
69  ::std::cerr << "\n"\
70  "########################################################################\n"\
71  "### AN INTERNAL ERROR OCCURED! ###\n"\
72  "### Please send the following information to contact@libxerus.org ! ###\n"\
73  "########################################################################\n"\
74  "xerus version: " << ::xerus::VERSION_MAJOR << '.' << ::xerus::VERSION_MINOR << '.' << ::xerus::VERSION_REVISION << '-' << ::xerus::VERSION_COMMIT << "\n" \
75  "at: " __FILE__ " : " XERUS_STRINGIFY(__LINE__) "\n" \
76  "message: " #condition " failed: " << message << '\n' \
77  << "callstack: \n" << ::xerus::misc::get_call_stack() << "\n" \
78  "########################################################################\n"\
79  "### thank you :-) ###\n"\
80  "########################################################################" << std::endl; \
81  XERUS_LOG(critical, #condition " failed msg: " << message); \
82  } else void(0)
83 
84  #define XERUS_IF_CHECK(expression) expression
85 
86  #define XERUS_IF_NO_CHECK(expression)
87 #else
88  #define XERUS_CHECK(condition, level, message) void(0)
89 
90  #define XERUS_REQUIRE(condition, message) void(0)
91 
92  #define XERUS_INTERNAL_CHECK(condition, msg) void(0)
93 
94  #define XERUS_IF_CHECK(expression)
95 
96  #define XERUS_IF_NO_CHECK(expression) expression
97 #endif
Header file for the call-stack functionality.
Header file for all logging macros and log-buffer functionality.
Header file for the standard container to standard ostream operators.