1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_FOUNDATION_PX_ASSERT_H
15#define PX_FOUNDATION_PX_ASSERT_H
16
17/** \addtogroup foundation
18@{ */
19
20#include "foundation/Px.h"
21
22#ifndef PX_DOXYGEN
23namespace physx
24{
25#endif
26
27 /* Base class to handle assert failures */
28 class PxAssertHandler
29 {
30 public:
31 virtual ~PxAssertHandler() {}
32 virtual void operator()(const char* exp, const char* file, int line, bool& ignore) = 0;
33 };
34
35 PX_FOUNDATION_API PxAssertHandler& PxGetAssertHandler();
36 PX_FOUNDATION_API void PxSetAssertHandler(PxAssertHandler& handler);
37
38#ifndef PX_DOXYGEN
39} // namespace physx
40#endif
41
42#if (!defined(PX_DEBUG) && !(defined(PX_CHECKED) && defined(PX_ENABLE_CHECKED_ASSERTS))) || defined(__CUDACC__)
43# define PX_ASSERT(exp) ((void)0)
44# define PX_ALWAYS_ASSERT_MESSAGE(exp) ((void)0)
45# define PX_ASSERT_WITH_MESSAGE(condition, message) ((void)0)
46#elif !defined(__SPU__)
47 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
48 // We want to run code analysis on VS2005 and later. This macro will be used to get rid of analysis warning messages if a PX_ASSERT is used to "guard" illegal mem access, for example.
49 #define PX_CODE_ANALYSIS_ASSUME(exp) __analysis_assume(!!(exp))
50 #else
51 #define PX_CODE_ANALYSIS_ASSUME(exp)
52 #endif
53# define PX_ASSERT(exp) { static bool _ignore = false; ((void)((!!(exp)) || (!_ignore && (physx::PxGetAssertHandler()(#exp, __FILE__, __LINE__, _ignore), false)))); PX_CODE_ANALYSIS_ASSUME(exp); }
54# define PX_ALWAYS_ASSERT_MESSAGE(exp) { static bool _ignore = false; if(!_ignore)physx::PxGetAssertHandler()(exp, __FILE__, __LINE__, _ignore); }
55# define PX_ASSERT_WITH_MESSAGE(exp, message) {static bool _ignore = false; ((void)((!!(exp)) || (!_ignore && (physx::PxGetAssertHandler()(message, __FILE__, __LINE__, _ignore), false)))); PX_CODE_ANALYSIS_ASSUME(exp);}
56#else
57# include "ps3/PxPS3Assert.h"
58#endif
59
60#define PX_ALWAYS_ASSERT() PX_ASSERT(0)
61
62/** @} */
63#endif // PX_FOUNDATION_PX_ASSERT_H
64