1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 ****************************************************************************/
24 #ifndef __SWR_ASSERT_H__
25 #define __SWR_ASSERT_H__
27 #if !defined(__SWR_OS_H__)
28 #error swr_assert.h should not be included directly, please include "common/os.h" instead.
31 #if !defined(SWR_ENABLE_ASSERTS)
34 #define SWR_ENABLE_ASSERTS 1
36 #define SWR_ENABLE_ASSERTS 0
39 #endif // SWR_ENABLE_ASSERTS
41 #if !defined(SWR_ENABLE_REL_ASSERTS)
42 #define SWR_ENABLE_REL_ASSERTS 1
45 #if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
48 #if !defined(__cplusplus)
50 #pragma message("C++ is required for SWR Asserts, falling back to assert.h")
52 #if SWR_ENABLE_ASSERTS
53 #define SWR_ASSERT(e, ...) assert(e)
56 #if SWR_ENABLE_REL_ASSERTS
57 #define SWR_REL_ASSERT(e, ...) assert(e)
62 #if SWR_ENABLE_ASSERTS
66 #define assert(exp) SWR_ASSERT(exp)
72 const char* pExpression
,
73 const char* pFileName
,
76 const char* pFmtString
= nullptr,
79 #define _SWR_ASSERT(chkDebugger, e, ...) {\
80 bool expFailed = !(e);\
82 static bool swrAssertEnabled = true;\
83 expFailed = SwrAssert(chkDebugger, swrAssertEnabled, #e, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
84 if (expFailed) { DEBUGBREAK; }\
88 #if SWR_ENABLE_ASSERTS
89 #define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
92 #if SWR_ENABLE_REL_ASSERTS
93 #define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
97 #endif // SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
99 #if !SWR_ENABLE_ASSERTS
100 #define SWR_ASSERT(e, ...)
103 #if !SWR_ENABLE_REL_ASSERTS
104 #define SWR_REL_ASSERT(e, ...)
107 #define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)
109 #endif//__SWR_ASSERT_H__