Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_ERROR_H__ |
| 25 | #define __ARM_COMPUTE_ERROR_H__ |
| 26 | |
| 27 | /** Print the given message then throw an std::runtime_error. |
| 28 | * |
| 29 | * @param[in] ... Message to display before aborting. |
| 30 | */ |
| 31 | #define ARM_COMPUTE_ERROR(...) ::arm_compute::error(__func__, __FILE__, __LINE__, __VA_ARGS__) // NOLINT |
| 32 | |
| 33 | /** Print the given message then throw an std::runtime_error. |
| 34 | * |
| 35 | * @param[in] func Function in which the error occurred. |
| 36 | * @param[in] file File in which the error occurred. |
| 37 | * @param[in] line Line in which the error occurred. |
| 38 | * @param[in] ... Message to display before aborting. |
| 39 | */ |
| 40 | #define ARM_COMPUTE_ERROR_LOC(func, file, line, ...) ::arm_compute::error(func, file, line, __VA_ARGS__) // NOLINT |
| 41 | |
| 42 | /** To avoid unused variables warnings |
| 43 | * |
| 44 | * This is useful if for example a variable is only used |
| 45 | * in debug builds and generates a warning in release builds. |
| 46 | * |
| 47 | * @param[in] var Variable which is unused |
| 48 | */ |
| 49 | #define ARM_COMPUTE_UNUSED(var) (void)(var) |
| 50 | |
| 51 | #ifdef ARM_COMPUTE_DEBUG_ENABLED |
| 52 | /** Print the given message |
| 53 | * |
| 54 | * @param[in] ... Message to display |
| 55 | */ |
| 56 | #define ARM_COMPUTE_INFO(...) ::arm_compute::debug(__func__, __FILE__, __LINE__, __VA_ARGS__) // NOLINT |
| 57 | /** If the condition is true, the given message is printed |
| 58 | * |
| 59 | * @param[in] cond Condition to evaluate. |
| 60 | * @param[in] ... Message to print if cond is false. |
| 61 | */ |
| 62 | #define ARM_COMPUTE_INFO_ON_MSG(cond, ...) \ |
| 63 | do \ |
| 64 | { \ |
| 65 | if(cond) \ |
| 66 | { \ |
| 67 | ARM_COMPUTE_INFO(__VA_ARGS__); \ |
| 68 | } \ |
| 69 | } while(0) |
| 70 | #else /* ARM_COMPUTE_DEBUG_ENABLED */ |
| 71 | #define ARM_COMPUTE_INFO_ON_MSG(cond, ...) |
| 72 | #define ARM_COMPUTE_INFO(...) |
| 73 | #endif /* ARM_COMPUTE_DEBUG_ENABLED */ |
| 74 | |
| 75 | #ifdef ARM_COMPUTE_ASSERTS_ENABLED |
| 76 | /** If the condition is true, the given message is printed and an exception is thrown |
| 77 | * |
| 78 | * @param[in] cond Condition to evaluate. |
| 79 | * @param[in] ... Message to print if cond is false. |
| 80 | */ |
| 81 | #define ARM_COMPUTE_ERROR_ON_MSG(cond, ...) \ |
| 82 | do \ |
| 83 | { \ |
| 84 | if(cond) \ |
| 85 | { \ |
| 86 | ARM_COMPUTE_ERROR(__VA_ARGS__); \ |
| 87 | } \ |
| 88 | } while(0) |
| 89 | |
| 90 | /** If the condition is true, the given message is printed and an exception is thrown |
| 91 | * |
| 92 | * @param[in] cond Condition to evaluate. |
| 93 | * @param[in] func Function in which the error occurred. |
| 94 | * @param[in] file File in which the error occurred. |
| 95 | * @param[in] line Line in which the error occurred. |
| 96 | * @param[in] ... Message to print if cond is false. |
| 97 | */ |
| 98 | #define ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, ...) \ |
| 99 | do \ |
| 100 | { \ |
| 101 | if(cond) \ |
| 102 | { \ |
| 103 | ARM_COMPUTE_ERROR_LOC(func, file, line, __VA_ARGS__); \ |
| 104 | } \ |
| 105 | } while(0) |
| 106 | |
| 107 | /** If the condition is true, the given message is printed and an exception is thrown, otherwise value is returned |
| 108 | * |
| 109 | * @param[in] cond Condition to evaluate. |
| 110 | * @param[in] val Value to be returned. |
| 111 | * @param[in] msg Message to print if cond is false. |
| 112 | */ |
| 113 | #define ARM_COMPUTE_CONST_ON_ERROR(cond, val, msg) (cond) ? throw std::logic_error(msg) : val; |
| 114 | #else /* ARM_COMPUTE_ASSERTS_ENABLED */ |
| 115 | #define ARM_COMPUTE_ERROR_ON_MSG(cond, ...) |
| 116 | #define ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, ...) |
| 117 | #define ARM_COMPUTE_CONST_ON_ERROR(cond, val, msg) val |
| 118 | #endif /* ARM_COMPUTE_ASSERTS_ENABLED */ |
| 119 | |
| 120 | /** If the condition is true then an error message is printed and an exception thrown |
| 121 | * |
| 122 | * @param[in] cond Condition to evaluate |
| 123 | */ |
| 124 | #define ARM_COMPUTE_ERROR_ON(cond) \ |
| 125 | ARM_COMPUTE_ERROR_ON_MSG(cond, #cond) |
| 126 | |
| 127 | /** If the condition is true then an error message is printed and an exception thrown |
| 128 | * |
| 129 | * @param[in] cond Condition to evaluate |
| 130 | * @param[in] func Function in which the error occurred. |
| 131 | * @param[in] file File in which the error occurred. |
| 132 | * @param[in] line Line in which the error occurred. |
| 133 | */ |
| 134 | #define ARM_COMPUTE_ERROR_ON_LOC(cond, func, file, line) \ |
| 135 | ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, #cond) |
| 136 | |
| 137 | namespace arm_compute |
| 138 | { |
| 139 | /** Print an error message then throw an std::runtime_error |
| 140 | * |
| 141 | * @param[in] function Function in which the error occurred. |
| 142 | * @param[in] file Name of the file where the error occurred. |
| 143 | * @param[in] line Line on which the error occurred. |
| 144 | * @param[in] msg Message to display before aborting. |
| 145 | * @param[in] ... Variable number of arguments of the message. |
| 146 | */ |
| 147 | [[noreturn]] void error(const char *function, const char *file, const int line, const char *msg, ...); |
| 148 | |
| 149 | /** Print a debug message |
| 150 | * |
| 151 | * @param[in] function Function in which the error occurred. |
| 152 | * @param[in] file Name of the file where the error occurred. |
| 153 | * @param[in] line Line on which the error occurred. |
| 154 | * @param[in] msg Message to display before aborting. |
| 155 | * @param[in] ... Variable number of arguments of the message. |
| 156 | */ |
| 157 | void debug(const char *function, const char *file, const int line, const char *msg, ...); |
| 158 | } |
| 159 | |
| 160 | #endif /* __ARM_COMPUTE_ERROR_H__ */ |