1 /* 2 * Copyright (c) 2022, Alliance for Open Media. All rights reserved 3 * 4 * This source code is subject to the terms of the BSD 3-Clause Clear License 5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear 6 * License was not distributed with this source code in the LICENSE file, you 7 * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the 8 * Alliance for Open Media Patent License 1.0 was not distributed with this 9 * source code in the PATENTS file, you can obtain it at 10 * www.aomedia.org/license/patent. 11 */ 12 #ifndef COMMON_UTILS_MACROS_H_ 13 #define COMMON_UTILS_MACROS_H_ 14 15 namespace iamf_tools { 16 17 // For propagating errors when calling a function. 18 #define RETURN_IF_NOT_OK(...) \ 19 do { \ 20 absl::Status _status = (__VA_ARGS__); \ 21 if (!_status.ok()) return _status; \ 22 } while (0) 23 24 // For propagating errors when calling a function, but ignoring errors when 25 // built with `-DIGNORE_ERRORS_USE_ONLY_FOR_IAMF_TEST_SUITE`. Beware that 26 // defining `IGNORE_ERRORS_USE_ONLY_FOR_IAMF_TEST_SUITE` is not thoroughly 27 // tested and may result in unexpected behavior. This define should only be used 28 // when creating test files which intentionally violate the IAMF spec. 29 #ifdef IGNORE_ERRORS_USE_ONLY_FOR_IAMF_TEST_SUITE 30 #define MAYBE_RETURN_IF_NOT_OK(...) \ 31 do { \ 32 (__VA_ARGS__).IgnoreError(); \ 33 } while (0) 34 #else 35 #define MAYBE_RETURN_IF_NOT_OK(...) RETURN_IF_NOT_OK(__VA_ARGS__) 36 #endif 37 38 } // namespace iamf_tools 39 40 #endif // COMMON_UTILS_MACROS_H_ 41