CTR Pia  4.11.3
Game Communication Engine
assertableResult.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: assertableResult.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/platform.h>
18 
19 #if NN_PIA_NIN_WIN
20 #include <nn/nn_ErrorResult.h>
21 #endif
22 
23 namespace nn
24 {
25 namespace pia
26 {
27 
28 /*!
29 @cond PRIVATE
30 @brief Enables or disables assertions for all <tt>Result</tt> values.
31 */
32 struct AssertableResultAll
33 {
34 public:
35 /*!
36 @brief Enables assertions.
37 */
38  static void EnableAssert()
39  {
40  m_IsAssertEnable = true;
41  }
42 
43 /*!
44 @brief Disables assertions.
45 */
46  static void DisableAssert()
47  {
48  m_IsAssertEnable = false;
49  }
50 
51 /*!
52 @brief Gets whether assertions are enabled.
53 @return Returns <tt>true</tt> if assertions are enabled, and <tt>false</tt> otherwise.
54 */
55  static bool IsAssertEnable()
56  {
57  return m_IsAssertEnable;
58  }
59 
60 private:
61  static bool m_IsAssertEnable;
62 };
63 //! @endcond
64 
65 #if NN_PIA_NIN_WIN
66 /*!
67 @cond PRIVATE
68 @brief Represents the <tt>Result</tt> structure used to manage enabling and disabling assertions.
69 For more information, see <tt>NN_DEFINE_ERROR_RANGE_RESULT</tt> in <tt>result_ErrorResult.h</tt>.
70 */
71 template <int module, int descriptionBegin>
72 struct AssertableResult
73  : public ::nn::result::detail::ErrorResultBase<module, descriptionBegin>
74  , public ::nn::result::detail::ErrorRange<module, descriptionBegin, descriptionBegin+1>
75 {
76 public:
77 /*!
78 @brief Enables assertions.
79 */
80  static void EnableAssert()
81  {
82  m_IsAssertEnable = true;
83  }
84 
85 /*!
86 @brief Disables assertions.
87 */
88  static void DisableAssert()
89  {
90  m_IsAssertEnable = false;
91  }
92 
93 /*!
94 @brief Gets whether assertions are enabled.
95 @return Returns <tt>true</tt> if assertions are enabled, and <tt>false</tt> otherwise.
96 */
97  static bool IsAssertEnable()
98  {
99  return (m_IsAssertEnable || AssertableResultAll::IsAssertEnable());
100  }
101 
102 private:
103  static bool m_IsAssertEnable;
104 };
105 
106 
107 template <int TModule, int TDescription>
108 bool AssertableResult<TModule, TDescription>::m_IsAssertEnable = false;
109 //! @endcond
110 #else
111 /*!
112 @cond PRIVATE
113 @brief Represents the <tt>Result</tt> structure used to manage enabling and disabling assertions.
114 */
115 template <Result::Level TLevel, Result::Summary TSummary, Result::Module TModule, int TDescription>
116 struct AssertableResult : public nn::Result::Const<TLevel, TSummary, TModule, TDescription>
117 {
118 public:
119 /*!
120 @brief Enables assertions.
121 */
122  static void EnableAssert()
123  {
124  m_IsAssertEnable = true;
125  }
126 
127 /*!
128 @brief Disables assertions.
129 */
130  static void DisableAssert()
131  {
132  m_IsAssertEnable = false;
133  }
134 
135 /*!
136 @brief Gets whether assertions are enabled.
137 @return Returns <tt>true</tt> if assertions are enabled, and <tt>false</tt> otherwise.
138 */
139  static bool IsAssertEnable()
140  {
141  return (m_IsAssertEnable || AssertableResultAll::IsAssertEnable());
142  }
143 
144 private:
145  static bool m_IsAssertEnable;
146 };
147 
148 
149 template <Result::Level TLevel, Result::Summary TSummary, Result::Module TModule, int TDescription>
150 bool AssertableResult<TLevel, TSummary, TModule, TDescription>::m_IsAssertEnable = false;
151 //! @endcond
152 #endif
153 
154 /*!
155 @cond PRIVATE
156 @brief Wraps the <tt>GetValue()</tt> function of <tt>nn::Result</tt>.
157 */
158 #if NN_PIA_NIN_WIN
159 inline int32_t PiaResultGetValue(nn::Result result)
160 {
161  return result.GetInnerValueForDebug();
162 }
163 #else
164 inline u32 PiaResultGetValue(nn::Result result)
165 {
166  return result.GetValue();
167 }
168 //! @endcond
169 #endif
170 }
171 } // end of namespace nn::pia
172 
173 #if NN_PIA_NIN_WIN
174 /*!
175 @cond PRIVATE
176 @brief Directly enters the NintendoSDK Pia module number.
177 */
178 namespace nn{
179 namespace pia{
180  const int PiaResultModuleNo = 301;
181 }
182 } // end of namespace nn::pia
183 
184 #define PIA_DEFINE_RESULT(name, level, summary, module, description) \
185  typedef ::nn::pia::AssertableResult<(::nn::pia::PiaResultModuleNo), (description)> name
186 //! @endcond
187 #else
188 //! @cond PRIVATE
189 #define PIA_DEFINE_RESULT(name, level, summary, module, description) \
190  typedef ::nn::pia::AssertableResult<(level), (summary), (module), (description)> name
191 //! @endcond
192 #endif
Definition: assert.h:115