InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
K2Assert.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: ???
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // Summary: Debugging functions and macros.
24 // Written by: Jesse Jones (from Whisper)
25 //
26 // Abstract: This file provides the following macros:
27 //
28 // ASSERT(p) - No-op in release builds. In debug builds drops into the
29 // debugger if p is false.
30 //
31 // COMPILE_CHECK(p) - An ASSERT that fires at compile time. This is useful
32 // for doing things like verifying the layout of items within a struct.
33 // Note that this check is also done in release builds.
34 //
35 // ASSERT_MSG(predicate, str) - Drops into the debugger
36 // if p is false, and displays the string.
37 //
38 // ASSERT_UNIMPLEMENTED() - Drops into the debugger and
39 // displays a string saying "Unimplemented function in [file] at [line]".
40 //
41 // ASSERT_FAIL(formatStr) - Drops into the debugger, and displays
42 // the string.
43 //
44 // FORMAT_ARGS(formatStr, arg1, arg2, ...) - Does printf-style formatting on the
45 // arguments, and returns the resulting string. Used in confunction with
46 // ASSERT_MSG and ASSERT_FAIL when you want formatted output, e.g.:
47 // ASSERT_MSG(!success, FORMAT_ARGS("Operation %s failed! Try %s.", opName, tryName));
48 //
49 //========================================================================================
50 
51 #ifndef K2ASSERT_H
52 #define K2ASSERT_H
53 
54 #include "OMTypes.h"
55 
56 // #pragma export on
57 
58 #if defined(DEBUG)
59 #ifndef ID_ENABLE_DEBUGGING
60 #error ID_ENABLE_DEBUGGING is not defined in DEBUG.
61 #endif
62 #endif
63 
64 
65 #if !defined( _lint) && !defined( __GNUC__)
66 #define COMPILE_CHECK(p) {struct _CC {char a[(p) ? 1 : -1];};} 0
67 #else
68 #define COMPILE_CHECK(p)
69 #endif
70 
71 //#ifdef PRERELEASE
72 
73 #ifdef ID_ENABLE_DEBUGGING
74 #ifdef MACINTOSH
75  typedef void (*ShowAssertFnc)(const char* msg);
76  RUNTIME_DECL void ClientShowAssert(const char* msg);
77  RUNTIME_DECL void ServerShowAssert(const char* msg);
78 #endif
79 #ifdef WINDOWS
80  typedef void (*ShowAssertFnc)(const char* mesg, const char* file, int32 line);
81  RUNTIME_DECL void ClientShowAssert(const char* mesg, const char* file, int32 line);
82  RUNTIME_DECL void ServerShowAssert(const char* mesg, const char* file, int32 line);
83 #endif
84 #ifdef WASM
85  typedef void (*ShowAssertFnc)(const char* msg);
86  RUNTIME_DECL void ClientShowAssert(const char* msg);
87 #endif
88  RUNTIME_DECL void InitializeDebugging(ShowAssertFnc showAssertFnc);
89  RUNTIME_DECL void TerminateDebugging();
90 
91  RUNTIME_DECL void BreakToDebugger();
92  RUNTIME_DECL void BreakStrToDebugger(const char* mesg, const char* file = nil, int32 line = 0);
93 
94  RUNTIME_DECL bool16 IsDebuggerRunning();
95 
96  class DebugLog;
97  RUNTIME_DECL DebugLog& GetTraceLog(); // contains a list of sinks used by trace, and optionally, asserts
98  RUNTIME_DECL bool16 GetLogAsserts(); // asserts will be logged via ::GetTraceLog(), defaults to false
99  RUNTIME_DECL void SetLogAsserts(bool16 arg); // asserts will be logged via ::GetTraceLog(), defaults to false
100  RUNTIME_DECL bool16 GetBreakOnAssert(); // asserts will cause the app to break, defaults to true
101  RUNTIME_DECL void SetBreakOnAssert(bool16 val); // asserts will cause the app to break, defaults to true
102 
103  RUNTIME_DECL bool16 GetIntenseDebugging(); // enables costly debug checks, defaults to false
104  RUNTIME_DECL void SetIntenseDebugging(bool16 intense); // enables costly debug checks, defaults to false
105  RUNTIME_DECL bool16 GetDisableCloseVerify(); // disable pub verification on close
106  RUNTIME_DECL void SetDisableCloseVerify(bool16 disable); // disable pub verification on close
107  RUNTIME_DECL bool16 GetSuppressDebugUI(); // disable any debug UI - used for buildacceptance loop to avoid blocking UI
108  RUNTIME_DECL void SetSuppressDebugUI(bool16 suppress); // disable any debug UI - used for buildacceptance loop to avoid blocking UI
109 
110  // C++ style assert
111  RUNTIME_DECL void ASSERT_STD_FUNC(const char* message, const char* file, int32 line);
112 #define ASSERT(p) !(p) ? ASSERT_STD_FUNC(#p, __FILE__, __LINE__) : (void) 0
113 
114  // Assert with standard string for unimplemented functionality
115 #define ASSERT_UNIMPLEMENTED() ASSERT_UNIMPLEMENTED_FUNC(__FILE__, __LINE__)
116  RUNTIME_DECL void ASSERT_UNIMPLEMENTED_FUNC(const char* file, int32 line);
117 
118  // Asserts with user-defined messages
119  RUNTIME_DECL char *FORMAT_ARGS(const char *msg, ...);
120  RUNTIME_DECL void ASSERT_FUNC(const char* str, const char* file, int32 line);
121 #define ASSERT_MSG(p,msg) !(p) ? ASSERT_FUNC((msg), __FILE__, __LINE__) : (void) 0
122 #define ASSERT_FAIL(msg) ASSERT_FUNC((msg), __FILE__, __LINE__)
123 
124 #else
125 
126  #define ASSERT_MSG(p, msg) ((void) 0)
127 #define ASSERT(p) ((void) 0)
128 #define ASSERT_UNIMPLEMENTED() ((void) 0)
129 #define ASSERT_FAIL(msg) ((void) 0)
130 #define ASSERT_STD_FUNC(p, file, line) ((void) 0)
131 #define ASSERT_FUNC(p, file, line) ((void) 0)
132 
133 #endif
134 
135 // #pragma export off
136 
137 #endif // K2ASSERT_H