AppAssert.h
1 //##################################################################################################
2 //
3 // Ceetron Desktop Components
4 // Component: Core
5 //
6 // --------------------------------------------------------------------------------------------
7 // Copyright (C) 2019, Ceetron AS
8 // This is UNPUBLISHED PROPRIETARY SOURCE CODE of Ceetron AS. The contents of this file may
9 // not be disclosed to third parties, copied or duplicated in any form, in whole or in part,
10 // without the prior written permission of Ceetron AS.
11 //##################################################################################################
12 
13 #pragma once
14 
15 #include "CeeCore/Base.h"
16 
17 namespace cee {
18 
19 
20 //==================================================================================================
21 //
22 // Static helper class for handling assert failures in CDC
23 //
24 //==================================================================================================
25 class CEE_CORE_EXPORT AssertHelper
26 {
27 public:
30  {
32  DEBUGBREAK
33  };
34 
35 public:
36  static PostFailAction handleFailedAssert(const char* fileName, int lineNumber, const char* expr, const char* msg);
37 };
38 
39 } // namespace cee
40 
41 
42 
43 // Default behavior for assert macros
44 // In debug builds, all asserts are in action, both normal asserts and tight asserts
45 // In release builds, tight asserts are disabled by default while normal asserts are still in action
46 #ifndef CEE_ENABLE_APP_ASSERTS
47  #define CEE_ENABLE_APP_ASSERTS 1
48 #endif
49 
50 #ifndef CEE_ENABLE_TIGHT_APP_ASSERTS
51  #ifdef _DEBUG
52  #define CEE_ENABLE_TIGHT_APP_ASSERTS 1
53  #else
54  #define CEE_ENABLE_TIGHT_APP_ASSERTS 0
55  #endif
56 #endif
57 
58 
59 // Define to trigger debug trap for use with assert macros on Windows
60 #ifdef WIN32
61  #define CEE_APP_ASSERT_DEBUGTRAP() __debugbreak()
62 #else
63  #define CEE_APP_ASSERT_DEBUGTRAP() ((void)0)
64 #endif
65 
66 
67 
68 // Define our assert macros
69 #if CEE_ENABLE_APP_ASSERTS == 1
70  #define CEE_APP_ASSERT(expr) (void)( (!!(expr)) || (cee::AssertHelper::CONTINUE == cee::AssertHelper::handleFailedAssert(__FILE__, __LINE__, #expr, NULL)) || (CEE_APP_ASSERT_DEBUGTRAP(), 0) )
71  #define CEE_APP_ASSERT_MSG(expr, msg) (void)( (!!(expr)) || (cee::AssertHelper::CONTINUE == cee::AssertHelper::handleFailedAssert(__FILE__, __LINE__, #expr, (msg))) || (CEE_APP_ASSERT_DEBUGTRAP(), 0) )
72  #define CEE_APP_FAIL_MSG(msg) (void)( (cee::AssertHelper::CONTINUE == cee::AssertHelper::handleFailedAssert(__FILE__, __LINE__, NULL, (msg))) || (CEE_APP_ASSERT_DEBUGTRAP(), 0) )
73 #else
74  #define CEE_APP_ASSERT(expr) ((void)0)
75  #define CEE_APP_ASSERT_MSG(expr, msg) ((void)0)
76  #define CEE_APP_FAIL_MSG(msg) ((void)0)
77 #endif
78 
79 #if CEE_ENABLE_TIGHT_APP_ASSERTS == 1 && CEE_ENABLE_APP_ASSERTS == 1
80  #define CEE_APP_TIGHT_ASSERT(expr) CEE_APP_ASSERT(expr)
81 #else
82  #define CEE_APP_TIGHT_ASSERT(expr) ((void)0)
83 #endif
84 
85 
86 
Namespace cee contains all functionality and structures under the Core component. ...
Definition: AppAssert.cpp:18
Static helper class for handling application assert failures in CDC.
Definition: AppAssert.h:25
PostFailAction
Post fail actions.
Definition: AppAssert.h:29
Continue execution.
Definition: AppAssert.h:31