Diligent Engine API Reference
Platforms
Basic
interface
DebugUtilities.h
1
/* Copyright 2015-2018 Egor Yusov
2
*
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
6
*
7
* http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12
*
13
* In no event and under no legal theory, whether in tort (including negligence),
14
* contract, or otherwise, unless required by applicable law (such as deliberate
15
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
16
* liable for any damages, including any direct, indirect, special, incidental,
17
* or consequential damages of any character arising as a result of this License or
18
* out of the use or inability to use the software (including but not limited to damages
19
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20
* all other commercial damages or losses), even if such Contributor has been advised
21
* of the possibility of such damages.
22
*/
23
24
#pragma once
25
26
#include "FormatMessage.h"
27
#include "BasicPlatformDebug.h"
28
29
#ifdef _DEBUG
30
31
#include <typeinfo>
32
33
// This function is only requried to ensure that Message argument passed to the macro
34
// is actually string and not something else
35
inline
void
EnsureStr(
const
char
* ){}
36
37
#define ASSERTION_FAILED(Message, ...)\
38
do{ \
39
EnsureStr(Message); \
40
Diligent::MsgStream ms; \
41
Diligent::FormatMsg( ms, Message, ##__VA_ARGS__);\
42
DebugAssertionFailed( ms.str().c_str(), __FUNCTION__, __FILE__, __LINE__); \
43
}while(false)
44
45
# define VERIFY(Expr, Message, ...)\
46
do{ \
47
EnsureStr(Message); \
48
if( !(Expr) ) \
49
{ \
50
ASSERTION_FAILED(Message, ##__VA_ARGS__);\
51
} \
52
}while(false)
53
54
# define UNEXPECTED ASSERTION_FAILED
55
# define UNSUPPORTED ASSERTION_FAILED
56
57
# define VERIFY_EXPR(Expr) VERIFY(Expr, "Debug exression failed:\n", #Expr)
58
59
60
template
<
typename
DstType,
typename
SrcType>
61
void
CheckDynamicType( SrcType *pSrcPtr )
62
{
63
VERIFY(pSrcPtr ==
nullptr
|| dynamic_cast<DstType*> (pSrcPtr) !=
nullptr
,
"Dynamic type cast failed. Src typeid: \'"
,
typeid
(*pSrcPtr).name(),
"\' Dst typeid: \'"
,
typeid
(DstType).name(),
'\''
);
64
}
65
# define CHECK_DYNAMIC_TYPE(DstType, pSrcPtr) do{ CheckDynamicType<DstType>(pSrcPtr); }while(false)
66
67
68
#else
69
70
# define CHECK_DYNAMIC_TYPE(...)do{}while(false)
71
# define VERIFY(...)do{}while(false)
72
# define UNEXPECTED(...)do{}while(false)
73
# define UNSUPPORTED(...)do{}while(false)
74
# define VERIFY_EXPR(...)do{}while(false)
75
76
#endif