Table of Contents

Wwise SDK 2019.2.2
AkAssert.h
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: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> 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
42  #include <AK/SoundEngine/Common/AkSoundEngineExport.h>
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) ((void)0)
77  #define AKASSERTD(Condition) ((void)0)
78  #define AKVERIFY(x) ((void)(x))
79 
80  #endif // defined( AK_ENABLE_ASSERTS )
81 
82  #define AKASSERT_RANGE(Value, Min, Max) (AKASSERT(((Value) >= (Min)) && ((Value) <= (Max))))
83 
84  #define AKASSERTANDRETURN( __Expression, __ErrorCode )\
85  if (!(__Expression))\
86  {\
87  AKASSERT(__Expression);\
88  return __ErrorCode;\
89  }\
90 
91  #define AKASSERTPOINTERORFAIL( __Pointer ) AKASSERTANDRETURN( __Pointer != NULL, AK_Fail )
92  #define AKASSERTSUCCESSORRETURN( __akr ) AKASSERTANDRETURN( __akr == AK_Success, __akr )
93 
94  #define AKASSERTPOINTERORRETURN( __Pointer ) \
95  if ((__Pointer) == NULL)\
96  {\
97  AKASSERT((__Pointer) == NULL);\
98  return ;\
99  }\
100 
101  #if defined( AK_WIN ) && ( _MSC_VER >= 1600 )
102  // Compile-time assert
103  #define AKSTATICASSERT( __expr__, __msg__ ) static_assert( (__expr__), (__msg__) )
104  #else
105  // Compile-time assert
106  #define AKSTATICASSERT( __expr__, __msg__ ) typedef char __AKSTATICASSERT__[(__expr__)?1:-1]
107  #endif
108 
109 #endif // ! defined( AKASSERT )
110 
111 #ifdef AK_ENABLE_ASSERTS
112 
113 
114 //Do nothing. This is a dummy function, so that g_pAssertHook is never NULL.
115 #define DEFINEDUMMYASSERTHOOK void AkAssertHookFunc( \
116 const char* in_pszExpression,\
117 const char* in_pszFileName,\
118 int in_lineNumber)\
119 {\
120 \
121 }\
122 AkAssertHook g_pAssertHook = AkAssertHookFunc;
123 #else
124 #define DEFINEDUMMYASSERTHOOK
125 
126 #endif
127 
128 // Compile-time assert. Usage:
129 // AkStaticAssert<[your boolean expression here]>::Assert();
130 // Example:
131 // AkStaticAssert<sizeof(MyStruct) == 20>::Assert(); //If you hit this, you changed the size of MyStruct!
132 // Empty default template
133 template <bool b>
134 struct AkStaticAssert {};
135 
136 // Template specialized on true
137 template <>
138 struct AkStaticAssert<true>
139 {
140  static void Assert() {}
141 };
142 
143 #endif
144 
static void Assert()
Definition: AkAssert.h:140