Turi Create  4.0
Verify.hpp
1 /* Copyright © 2020 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 
7 #pragma once
8 
9 #include <core/system/exceptions/TuriException.hpp>
10 
11 #define VerifyImpl(x, error_code, msg) \
12  do { \
13  if (!(x)) { \
14  throw TuriException(error_code, msg); \
15  } \
16  } while (0)
17 
18 #if defined(NDEBUG)
19 #define VerifyDebugImpl(x, error_code, msg)
20 #else
21 #define VerifyDebugImpl(x, error_code, msg) VerifyImpl(x, error_code, msg)
22 #endif
23 
24 // VerifyIsTrue - verifies expression x is true in all runtime environments.
25 // If failure, error_code (TuriErrorCode) will compose the thrown TuriException.
26 #define VerifyIsTrue(x, error_code) VerifyImpl(x, error_code, std::string())
27 
28 // VerifyIsTrue - verifies expression x is true in all runtime environments.
29 // If failure, error_code (TuriErrorCode) and the detailed error message will compose the thrown
30 // TuriException.
31 #define VerifyIsTrueWithMessage(x, error_code, msg) VerifyImpl(x, error_code, msg)
32 
33 // VerifyIsTrue - verifies expression x is true in debug builds only.
34 // If failure, error_code (TuriErrorCode) will compose the thrown TuriException.
35 #define VerifyDebugIsTrue(x, error_code) VerifyDebugImpl(x, error_code, std::string())
36 
37 // VerifyIsTrue - verifies expression x is true in debug builds only.
38 // If failure, error_code (TuriErrorCode) and the detailed error message will compose the thrown
39 // TuriException.
40 #define VerifyDebugIsTrueWithMessage(x, error_code, msg) VerifyDebugImpl(x, error_code, msg)