Table of Contents

Wwise SDK 2021.1.1
AkAssert.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: v2021.1.1 Build: 7601
25  Copyright (c) 2006-2021 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 #ifndef _AK_AKASSERT_H_
29 #define _AK_AKASSERT_H_
30 
31 #if defined(__EMSCRIPTEN__)
32 #include <assert.h>
33 #endif
34 
35 #if defined( _DEBUG ) && !(defined AK_DISABLE_ASSERTS)
36  #ifndef AK_ENABLE_ASSERTS
37  #define AK_ENABLE_ASSERTS
38  #endif
39 #endif
40 
41 #ifdef AK_ENABLE_ASSERTS
43  #ifndef AK_ASSERT_HOOK
44  AK_CALLBACK( void, AkAssertHook)(
45  const char * in_pszExpression, ///< Expression
46  const char * in_pszFileName, ///< File Name
47  int in_lineNumber ///< Line Number
48  );
49  #define AK_ASSERT_HOOK
50  #endif
51 #endif
52 
53 #if !defined( AKASSERT )
54  #include <AK/SoundEngine/Common/AkTypes.h> //For AK_Fail/Success
55 
56  #if defined( AK_ENABLE_ASSERTS )
57  extern AKSOUNDENGINE_API AkAssertHook g_pAssertHook;
58 
59  #if defined(__EMSCRIPTEN__)
60  #define AKASSERT(Condition) assert(Condition)
61  #else
62  // These platforms use a built-in g_pAssertHook (and do not fall back to the regular assert macro)
63  #define AKASSERT(Condition) ((Condition) ? ((void) 0) : g_pAssertHook( #Condition, __FILE__, __LINE__) )
64  #endif
65 
66  #define AKVERIFY AKASSERT
67 
68  #ifdef _DEBUG
69  #define AKASSERTD AKASSERT
70  #else
71  #define AKASSERTD(Condition) ((void)0)
72  #endif
73 
74  #else // defined( AK_ENABLE_ASSERTS )
75 
76  #define AKASSERT(Condition) do { switch ( 0 ) { case 0: break; default: if ( !( Condition ) ) {} } } while ( 0 )
77 
78  #define AKVERIFY(x) ((void)(x))
79 
80  #ifdef _DEBUG
81  #define AKASSERTD AKASSERT
82  #else
83  #define AKASSERTD(Condition) ((void)0)
84  #endif
85 
86  #endif // defined( AK_ENABLE_ASSERTS )
87 
88  #define AKASSERT_RANGE(Value, Min, Max) (AKASSERT(((Value) >= (Min)) && ((Value) <= (Max))))
89 
90  #define AKASSERTANDRETURN( __Expression, __ErrorCode )\
91  if (!(__Expression))\
92  {\
93  AKASSERT(__Expression);\
94  return __ErrorCode;\
95  }\
96 
97  #define AKASSERTPOINTERORFAIL( __Pointer ) AKASSERTANDRETURN( __Pointer != NULL, AK_Fail )
98  #define AKASSERTSUCCESSORRETURN( __akr ) AKASSERTANDRETURN( __akr == AK_Success, __akr )
99 
100  #define AKASSERTPOINTERORRETURN( __Pointer ) \
101  if ((__Pointer) == NULL)\
102  {\
103  AKASSERT((__Pointer) == NULL);\
104  return ;\
105  }\
106 
107  #if defined( AK_WIN ) && ( _MSC_VER >= 1600 )
108  // Compile-time assert
109  #define AKSTATICASSERT( __expr__, __msg__ ) static_assert( (__expr__), (__msg__) )
110  #else
111  // Compile-time assert
112  #define AKSTATICASSERT( __expr__, __msg__ ) typedef char __AKSTATICASSERT__[(__expr__)?1:-1]
113  #endif
114 
115 #endif // ! defined( AKASSERT )
116 
117 #ifdef AK_ENABLE_ASSERTS
118 
119 
120 //Do nothing. This is a dummy function, so that g_pAssertHook is never NULL.
121 #define DEFINEDUMMYASSERTHOOK void AkAssertHookFunc( \
122 const char* in_pszExpression,\
123 const char* in_pszFileName,\
124 int in_lineNumber)\
125 {\
126 \
127 }\
128 AkAssertHook g_pAssertHook = AkAssertHookFunc;
129 #else
130 #define DEFINEDUMMYASSERTHOOK
131 
132 #endif
133 
134 // Compile-time assert. Usage:
135 // AkStaticAssert<[your boolean expression here]>::Assert();
136 // Example:
137 // AkStaticAssert<sizeof(MyStruct) == 20>::Assert(); //If you hit this, you changed the size of MyStruct!
138 // Empty default template
139 template <bool b>
140 struct AkStaticAssert {};
141 
142 // Template specialized on true
143 template <>
144 struct AkStaticAssert<true>
145 {
146  static void Assert() {}
147 };
148 
149 #endif
150 
static void Assert()
Definition: AkAssert.h:146
#define AKSOUNDENGINE_API
#define AK_CALLBACK(_type, _name)
void(* AkAssertHook)(const char *in_pszExpression, const char *in_pszFileName, int in_lineNumber)
Definition: AkSoundEngine.h:106