Version
menu_open

include/AK/Tools/Common/AkAssert.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
00003 released in source code form as part of the SDK installer package.
00004 
00005 Commercial License Usage
00006 
00007 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
00008 may use this file in accordance with the end user license agreement provided 
00009 with the software or, alternatively, in accordance with the terms contained in a
00010 written agreement between you and Audiokinetic Inc.
00011 
00012 Apache License Usage
00013 
00014 Alternatively, this file may be used under the Apache License, Version 2.0 (the 
00015 "Apache License"); you may not use this file except in compliance with the 
00016 Apache License. You may obtain a copy of the Apache License at 
00017 http://www.apache.org/licenses/LICENSE-2.0.
00018 
00019 Unless required by applicable law or agreed to in writing, software distributed
00020 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
00021 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
00022 the specific language governing permissions and limitations under the License.
00023 
00024   Version: <VERSION>  Build: <BUILDNUMBER>
00025   Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
00026 *******************************************************************************/
00027 
00028 #ifndef _AK_AKASSERT_H_
00029 #define _AK_AKASSERT_H_
00030 
00031 #if defined( _DEBUG ) && !(defined AK_DISABLE_ASSERTS)
00032     #ifndef AK_ENABLE_ASSERTS
00033         #define AK_ENABLE_ASSERTS
00034     #endif
00035 #endif
00036 
00037 #if !defined( AKASSERT )
00038 
00039     #include <AK/SoundEngine/Common/AkTypes.h> //For AK_Fail/Success
00040     #include <AK/SoundEngine/Common/AkSoundEngineExport.h>
00041 
00042     #if defined( AK_ENABLE_ASSERTS )
00043 
00044         #ifndef AK_ASSERT_HOOK
00045             AK_CALLBACK( void, AkAssertHook)( 
00046                                     const char * in_pszExpression,  ///< Expression
00047                                     const char * in_pszFileName,    ///< File Name
00048                                     int in_lineNumber               ///< Line Number
00049                                     );
00050             #define AK_ASSERT_HOOK
00051         #endif
00052 
00053         extern AKSOUNDENGINE_API AkAssertHook g_pAssertHook;
00054 
00055         // These platforms use a built-in g_pAssertHook (and do not fall back to the regular assert macro)
00056         #define AKASSERT(Condition) ((Condition) ? ((void) 0) : g_pAssertHook( #Condition, __FILE__, __LINE__) )
00057 
00058 
00059         #define AKVERIFY AKASSERT
00060 
00061         #ifdef _DEBUG
00062             #define AKASSERTD AKASSERT
00063         #else
00064             #define AKASSERTD(Condition) ((void)0)
00065         #endif      
00066 
00067     #else //  defined( AK_ENABLE_ASSERTS )
00068 
00069         #define AKASSERT(Condition) ((void)0)
00070         #define AKASSERTD(Condition) ((void)0)
00071         #define AKVERIFY(x) ((void)(x))     
00072 
00073     #endif //  defined( AK_ENABLE_ASSERTS )
00074 
00075     #define AKASSERT_RANGE(Value, Min, Max) (AKASSERT(((Value) >= (Min)) && ((Value) <= (Max))))
00076 
00077     #define AKASSERTANDRETURN( __Expression, __ErrorCode )\
00078         if (!(__Expression))\
00079         {\
00080             AKASSERT(__Expression);\
00081             return __ErrorCode;\
00082         }\
00083 
00084     #define AKASSERTPOINTERORFAIL( __Pointer ) AKASSERTANDRETURN( __Pointer != NULL, AK_Fail )
00085     #define AKASSERTSUCCESSORRETURN( __akr ) AKASSERTANDRETURN( __akr == AK_Success, __akr )
00086 
00087     #define AKASSERTPOINTERORRETURN( __Pointer ) \
00088         if ((__Pointer) == NULL)\
00089         {\
00090             AKASSERT((__Pointer) == NULL);\
00091             return ;\
00092         }\
00093 
00094     #if defined( AK_WIN ) && ( _MSC_VER >= 1600 )
00095         // Compile-time assert
00096         #define AKSTATICASSERT( __expr__, __msg__ ) static_assert( (__expr__), (__msg__) )
00097     #else
00098         // Compile-time assert
00099         #define AKSTATICASSERT( __expr__, __msg__ ) typedef char __AKSTATICASSERT__[(__expr__)?1:-1]
00100     #endif  
00101 
00102 #endif // ! defined( AKASSERT )
00103 
00104 #ifdef AK_ENABLE_ASSERTS
00105 
00106 
00107 //Do nothing. This is a dummy function, so that g_pAssertHook is never NULL.
00108 #define DEFINEDUMMYASSERTHOOK void AkAssertHookFunc( \
00109 const char* in_pszExpression,\
00110 const char* in_pszFileName,\
00111 int in_lineNumber)\
00112 {\
00113 \
00114 }\
00115 AkAssertHook g_pAssertHook = AkAssertHookFunc;
00116 #else
00117 #define DEFINEDUMMYASSERTHOOK
00118 
00119 #endif
00120 
00121 // Compile-time assert.  Usage:
00122 // AkStaticAssert<[your boolean expression here]>::Assert();
00123 // Example: 
00124 // AkStaticAssert<sizeof(MyStruct) == 20>::Assert();    //If you hit this, you changed the size of MyStruct!
00125 // Empty default template
00126 template <bool b>
00127 struct AkStaticAssert {};
00128 
00129 // Template specialized on true
00130 template <>
00131 struct AkStaticAssert<true>
00132 {
00133     static void Assert() {}
00134 };
00135 
00136 #endif
00137 

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise