CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
pia_Assert.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/pia_Platform.h>
17 
18 
19 // @addtogroup pia_common_debug_macro Pia の提供するデバッグ用マクロ定義
20 // @brief Pia の提供するデバッグ用マクロです。
21 //! @{
22 //! @name アサート
23 //! @{
24 
25 /*!
26  @brief 引数 EXP が false もしくは NULL の場合プログラムが強制的に停止します。
27 
28  @details このマクロを使った場合、直前まで @ref PIA_BASIC_PRINT で出力した文字列がキャッシュから書き出されます。
29  <br>
30  @details release ビルド時にはこのマクロは無視されます。
31 
32  @param[in] EXP この値が false もしくは NULL の場合プログラムが強制的に停止します。
33 
34  @see PIA_BASIC_PRINT
35  */
36 #if NN_PIA_ENABLE_ASSERT
37 #define PIA_ASSERT(EXP) \
38  (static_cast<void>((EXP) || (::nn::pia::Assert(#EXP, PIA_CODE_POSITION_FILE, PIA_CODE_POSITION_LINE, NULL), true)))
39 
40 #else
41 #define PIA_ASSERT(EXP) ((void)0)
42 #endif
43 
44 
45 /*!
46  @brief 引数 EXP が false もしくは NULL の場合プログラムが強制的に停止します。
47 
48  @details このマクロを使った場合、直前まで @ref PIA_BASIC_PRINT で出力した文字列がキャッシュから書き出されます。
49  <br>
50  @details release ビルド時にはこのマクロは無視されます。
51 
52  @param[in] EXP この値が false もしくは NULL の場合プログラムが強制的に停止します。
53  @param[in] ... 標準ライブラリの printf の引数と同様です。
54 
55  @see PIA_BASIC_PRINT
56  */
57 #if NN_PIA_ENABLE_ASSERT
58 #define PIA_ASSERTMSG(EXP, ...) \
59  (static_cast<void>((EXP) || (::nn::pia::Assert(#EXP, PIA_CODE_POSITION_FILE, PIA_CODE_POSITION_LINE, __VA_ARGS__), true)))
60 #else
61 #define PIA_ASSERTMSG(EXP, ...) ((void)0)
62 #endif
63 
64 
65 //! @cond PRIVATE
66 #define PIA_MACRO_CAT(l, r) l##r
67 #define PIA_MACRO_EXPANDING_CAT(l, r) PIA_MACRO_CAT(l, r)
68 //! @endcond
69 
70 /*!
71  @brief 引数 EXP が false もしくは NULL の場合コンパイルエラーとなります。
72 
73  @details コンパイル時の(静的)アサートマクロです。
74  引数 EXP には定数式を指定する必要があります。
75 
76  @param[in] EXP この値が false もしくは NULL の場合コンパイルエラーとなります。
77  */
78 #if NN_PIA_NINTENDOSDK
79 #define PIA_COMPILE_ASSERT(EXP) static_assert((EXP), "Pia compile assert.")
80 #else
81 #define PIA_COMPILE_ASSERT(EXP) \
82  typedef ::nn::pia::PIA_COMPILE_ASSERT_INNER< \
83  sizeof(::nn::pia::PIA_COMPILE_ASSERT_FAILURE<static_cast<bool>(EXP)>)> \
84 PIA_MACRO_EXPANDING_CAT(pia_compile_assert_at_, __LINE__)
85 #endif
86 
87 //! @}
88 
89 
90 //! @name パニック
91 //! @{
92 
93 /*!
94  @brief プログラムを強制的に停止させます。
95 
96  @details このマクロを使った場合、直前まで @ref PIA_BASIC_PRINT で出力した文字列がキャッシュから書き出されます。
97  <br>
98  @param[in] ... 標準ライブラリの printf の引数と同様です。
99 
100  @see PIA_BASIC_PRINT
101  */
102 #if NN_PIA_ENABLE_ASSERT
103 #define PIA_PANIC(...) ::nn::pia::Panic(PIA_CODE_POSITION_FILE, PIA_CODE_POSITION_LINE, __VA_ARGS__)
104 #else
105 #define PIA_PANIC(...) PIA_BASIC_HALT(__VA_ARGS__)
106 #endif
107 
108 //! @}
109 //! @}
110 
111 
112 namespace nn
113 {
114 namespace pia
115 {
116 
117 /*!
118 @cond PRIVATE
119  @brief アサート関数です。
120 
121  @details この関数は、 PIA_ASSERT や PIA_ASSERTMSG などのマクロから
122  利用されることを想定しています。
123  この関数を直接呼び出すことは推奨しません。
124 
125  @param[in] pExp 条件式の文字列表現。
126  @param[in] pPos コード内の位置を示す文字列表現。( __FILE__ や __FUNCTION__ 、 __MODULE__ など)
127  @param[in] line 行番号。
128  @param[in] pMsg アサート時に出力する追加メッセージ。
129  */
130 void Assert(const char* pExp, const char* pPos, uint32_t line, const char* pMsg, ...);
131 //! @endcond
132 
133 
134 /*!
135 @cond PRIVATE
136  @brief パニック関数です。
137 
138  @details この関数は、 PIA_PANIC などのマクロから
139  利用されることを想定しています。
140  この関数を直接呼び出すことは推奨しません。
141 
142  @param[in] pPos コード内の位置を示す文字列表現。( __FILE__ や __FUNCTION__ 、 __MODULE__ など)
143  @param[in] line 行番号。
144  @param[in] pMsg アサート時に出力する追加メッセージ。
145  */
146 void Panic(const char* pPos, uint32_t line, const char* pMsg, ...);
147 //! @endcond
148 
149 
150 /*!
151 @cond PRIVATE
152  @brief コンパイルアサート用のテンプレートクラスです。
153 
154  @details これらのテンプレートクラスは PIA_COMPILE_ASSERT などのマクロから
155  利用されることを想定しています。
156  これらのテンプレートクラスをその他の用途で利用することは推奨しません。
157  */
158 template <bool b>
159 struct PIA_COMPILE_ASSERT_FAILURE;
160 template <>
161 struct PIA_COMPILE_ASSERT_FAILURE<true>
162 {
163 };
164 template <int x>
165 struct PIA_COMPILE_ASSERT_INNER
166 {
167 };
168 //! @endcond
169 }
170 } // end of namespace nn::pia