/*---------------------------------------------------------------------------* Project: Horizon File: util_Result.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 31786 $ *---------------------------------------------------------------------------*/ #ifndef NN_UTIL_UTIL_RESULT_H_ #define NN_UTIL_UTIL_RESULT_H_ #ifdef __cplusplus #include #include #include #include #include #include #ifdef NN_SWITCH_DISABLE_DEBUG_PRINT #define NN_UTIL_BEGIN_CHECK_RESULT(result) \ { \ ::nn::Result nn_util_result_try_result = (result); \ if (nn_util_result_try_result.IsFailure()) \ { #define NN_UTIL_ADD_RESULT_MESSAGE(expected, ...) #define NN_UTIL_END_CHECK_RESULT \ ::nnResultTFailureHandler(nn_util_result_try_result, "", 0, ""); \ ::nn::dbg::Break(::nn::dbg::BREAK_REASON_PANIC); \ } \ } #else #define NN_UTIL_BEGIN_CHECK_RESULT(result) \ { \ ::nn::Result nn_util_result_try_result = (result); \ if (nn_util_result_try_result.IsFailure()) \ { \ do { #define NN_UTIL_ADD_RESULT_MESSAGE(expected, ...) \ if (nn_util_result_try_result == (expected)) \ { \ ::nnResultFailureHandler(nn_util_result_try_result, NN_FILE_NAME, __LINE__, __VA_ARGS__); \ break; \ } #define NN_UTIL_END_CHECK_RESULT \ ::nnResultTFailureHandler(nn_util_result_try_result, NN_FILE_NAME, __LINE__, "Unexpected Result Failure."); \ } while (0); \ ::nn::dbg::Break(::nn::dbg::BREAK_REASON_PANIC); \ } \ } #endif // NN_SWITCH_DISABLE_DEBUG_PRINT #define NN_UTIL_RETURN_IF_FAILED_BASE(result, s1, s2, s3, s4, s5) \ do \ { \ ::nn::Result nn_util_return_if_failure_result = (result); \ if (nn_util_return_if_failure_result.IsFailure()) \ { \ s1; s2; s3; s4; s5; \ return nn_util_return_if_failure_result; \ } \ } while(0) #define NN_UTIL_RETURN_IF_FAILED(result) NN_UTIL_RETURN_IF_FAILED_BASE(result,,,,,) #define NN_UTIL_RETURN_IF_FAILED_0(result) NN_UTIL_RETURN_IF_FAILED_BASE(result,,,,,) #define NN_UTIL_RETURN_IF_FAILED_1(result, c1) NN_UTIL_RETURN_IF_FAILED_BASE(result,c1,,,,) #define NN_UTIL_RETURN_IF_FAILED_2(result, c1, c2) NN_UTIL_RETURN_IF_FAILED_BASE(result,c1,c2,,,) #define NN_UTIL_RETURN_IF_FAILED_3(result, c1, c2, c3) NN_UTIL_RETURN_IF_FAILED_BASE(result,c1,c2,c3,,) #define NN_UTIL_RETURN_IF_FAILED_4(result, c1, c2, c3, c4) NN_UTIL_RETURN_IF_FAILED_BASE(result,c1,c2,c3,c4,) #define NN_UTIL_RETURN_IF_FAILED_5(result, c1, c2, c3, c4, c5) NN_UTIL_RETURN_IF_FAILED_BASE(result,c1,c2,c3,c4,c5) #define NN_UTIL_RETURN_IF_FAILED_EXCEPT(result, exceptResult) \ do \ { \ ::nn::Result nn_util_return_if_failure_result_except = (result); \ if (!(nn_util_return_if_failure_result_except <= (exceptResult))) \ { \ NN_UTIL_RETURN_IF_FAILED(nn_util_return_if_failure_result_except); \ } \ } while (0) #ifdef NN_SWITCH_DISABLE_DEBUG_PRINT #define NN_UTIL_THROW_RESULT(result) return (result) #else #define NN_UTIL_THROW_RESULT(result) \ do \ { \ ::nn::Result nn_util_return_throw_result = (result); \ NN_TASSERT_(nn_util_return_throw_result.IsFailure()); \ NN_UTIL_RETURN_IF_FAILED_0(nn_util_return_throw_result); \ return nn_util_return_throw_result; \ } while(0) #endif #define NN_UTIL_PANIC_IF_FAILED(result) \ do { \ NN_UTIL_BEGIN_CHECK_RESULT(result) \ NN_TLOG_("RESULT FAILURE: result = %s\n", #result); \ NN_UTIL_END_CHECK_RESULT \ } while (0) namespace nn { namespace util { inline Result MakePermanentResult(Result::Summary summary, int description) { return Result(Result::LEVEL_PERMANENT, summary, Result::MODULE_NN_UTIL, description); } inline Result ResultAlreadyInitialized() { return Result(Result::LEVEL_INFO, Result::SUMMARY_INVALID_STATE, Result::MODULE_NN_UTIL, Result::DESCRIPTION_ALREADY_INITIALIZED); } inline Result ResultOutOfMemory() { return Result(Result::LEVEL_PERMANENT, Result::SUMMARY_OUT_OF_RESOURCE, Result::MODULE_NN_UTIL, Result::DESCRIPTION_OUT_OF_MEMORY); } }} #endif // __cplusplus #endif