]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/memory.h
added wxLog::IsLevelEnabled() helper; document it and a few related functions which...
[wxWidgets.git] / interface / wx / memory.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: memory.h
ba1d7a6c 3// Purpose: interface of wxDebugContext
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
e54c96f1 9
23324ae1
FM
10/**
11 @class wxDebugContext
7c913512 12
ba1d7a6c
FM
13 A class for performing various debugging and memory tracing operations.
14
15 Full functionality (such as printing out objects currently allocated) is
16 only present in a debugging build of wxWidgets, i.e. if the __WXDEBUG__
17 symbol is defined. wxDebugContext and related functions and macros can be
18 compiled out by setting wxUSE_DEBUG_CONTEXT to 0 is setup.h
7c913512 19
23324ae1
FM
20 @library{wxbase}
21 @category{debugging}
7c913512 22
ba1d7a6c 23 @see @ref overview_debugging
23324ae1 24*/
7c913512 25class wxDebugContext
23324ae1
FM
26{
27public:
28 /**
29 Checks the memory blocks for errors, starting from the currently set
30 checkpoint.
3c4f71cc 31
d29a9a8a 32 @return Returns the number of errors, so a value of zero represents
ba1d7a6c
FM
33 success. Returns -1 if an error was detected that prevents
34 further checking.
23324ae1 35 */
43c48e1e 36 static int Check(bool checkAll = false);
23324ae1
FM
37
38 /**
39 Performs a memory dump from the currently set checkpoint, writing to the
40 current debug stream. Calls the @b Dump member function for each wxObject
41 derived instance.
3c4f71cc 42
d29a9a8a 43 @return @true if the function succeeded, @false otherwise.
23324ae1 44 */
da1ed74c 45 static bool Dump();
23324ae1
FM
46
47 /**
48 Returns @true if the memory allocator checks all previous memory blocks for
49 errors.
ba1d7a6c 50
23324ae1 51 By default, this is @false since it slows down execution considerably.
3c4f71cc 52
4cc4bfaf 53 @see SetCheckPrevious()
23324ae1 54 */
da1ed74c 55 static bool GetCheckPrevious();
23324ae1
FM
56
57 /**
ba1d7a6c
FM
58 Returns @true if debug mode is on.
59
60 If debug mode is on, the wxObject new and delete operators store or use
61 information about memory allocation. Otherwise, a straight malloc and
62 free will be performed by these operators.
3c4f71cc 63
4cc4bfaf 64 @see SetDebugMode()
23324ae1 65 */
da1ed74c 66 static bool GetDebugMode();
23324ae1
FM
67
68 /**
ba1d7a6c
FM
69 Gets the debug level (default 1).
70
71 The debug level is used by the wxTraceLevel function and the WXTRACELEVEL
72 macro to specify how detailed the trace information is; setting a
73 different level will only have an effect if trace statements in the
74 application specify a value other than one.
75
76 @deprecated
23324ae1 77 This is obsolete, replaced by wxLog functionality.
3c4f71cc 78
4cc4bfaf 79 @see SetLevel()
23324ae1 80 */
da1ed74c 81 static int GetLevel();
23324ae1 82
23324ae1
FM
83 /**
84 Prints a list of the classes declared in this application, giving derivation
85 and whether instances of this class can be dynamically created.
3c4f71cc 86
4cc4bfaf 87 @see PrintStatistics()
23324ae1 88 */
da1ed74c 89 static bool PrintClasses();
23324ae1
FM
90
91 /**
92 Performs a statistics analysis from the currently set checkpoint, writing
93 to the current debug stream. The number of object and non-object
94 allocations is printed, together with the total size.
3c4f71cc 95
7c913512 96 @param detailed
ba1d7a6c
FM
97 If @true, the function will also print how many objects of each class
98 have been allocated, and the space taken by these class instances.
3c4f71cc 99
4cc4bfaf 100 @see PrintStatistics()
23324ae1 101 */
da1ed74c 102 static bool PrintStatistics(bool detailed = true);
23324ae1
FM
103
104 /**
105 Tells the memory allocator to check all previous memory blocks for errors.
106 By default, this is @false since it slows down execution considerably.
3c4f71cc 107
4cc4bfaf 108 @see GetCheckPrevious()
23324ae1 109 */
da1ed74c 110 static void SetCheckPrevious(bool check);
23324ae1
FM
111
112 /**
113 Sets the current checkpoint: Dump and PrintStatistics operations will
114 be performed from this point on. This allows you to ignore allocations
115 that have been performed up to this point.
3c4f71cc 116
7c913512 117 @param all
ba1d7a6c
FM
118 If @true, the checkpoint is reset to include all memory allocations
119 since the program started.
23324ae1 120 */
da1ed74c 121 static void SetCheckpoint(bool all = false);
23324ae1
FM
122
123 /**
ba1d7a6c
FM
124 Sets the debug mode on or off.
125
126 If debug mode is on, the wxObject new and delete operators store or use
127 information about memory allocation. Otherwise, a straight malloc and free
128 will be performed by these operators.
129
23324ae1
FM
130 By default, debug mode is on if __WXDEBUG__ is defined. If the application
131 uses this function, it should make sure that all object memory allocated
ba1d7a6c
FM
132 is deallocated with the same value of debug mode. Otherwise, the delete
133 operator might try to look for memory information that does not exist.
3c4f71cc 134
4cc4bfaf 135 @see GetDebugMode()
23324ae1 136 */
da1ed74c 137 static void SetDebugMode(bool debug);
23324ae1 138
23324ae1 139 /**
ba1d7a6c
FM
140 Sets the debug level (default 1).
141
142 The debug level is used by the wxTraceLevel function and the WXTRACELEVEL
143 macro to specify how detailed the trace information is; setting
23324ae1 144 a different level will only have an effect if trace statements in the
ba1d7a6c
FM
145 application specify a value other than one.
146
147 @deprecated
23324ae1 148 This is obsolete, replaced by wxLog functionality.
3c4f71cc 149
4cc4bfaf 150 @see GetLevel()
23324ae1 151 */
da1ed74c 152 static void SetLevel(int level);
23324ae1
FM
153
154 /**
ba1d7a6c
FM
155 Installs a function to be called at the end of wxWidgets shutdown.
156 It will be called after all files with global instances of
157 wxDebugContextDumpDelayCounter have run their destructors.
158
23324ae1
FM
159 The shutdown function must be take no parameters and return nothing.
160 */
da1ed74c 161 static void SetShutdownNotifyFunction(wxShutdownNotifyFunction func);
23324ae1
FM
162};
163
164
e54c96f1 165
23324ae1
FM
166// ============================================================================
167// Global functions/macros
168// ============================================================================
169
b21126db 170/** @addtogroup group_funcmacro_log */
ef477678
BP
171//@{
172
23324ae1 173/**
ef477678
BP
174 @deprecated Use one of the wxLogTrace() functions or one of the
175 wxVLogTrace() functions instead.
176
177 Calls wxTrace() with printf-style variable argument syntax. Output is
178 directed to the current output stream (see wxDebugContext).
179
180 @header{wx/memory.h}
23324ae1 181*/
ef477678 182#define WXTRACE(format, ...)
23324ae1
FM
183
184/**
ef477678
BP
185 @deprecated Use one of the wxLogTrace() functions or one of the
186 wxVLogTrace() functions instead.
187
188 Calls wxTraceLevel with printf-style variable argument syntax. Output is
189 directed to the current output stream (see wxDebugContext). The first
190 argument should be the level at which this information is appropriate. It
191 will only be output if the level returned by wxDebugContext::GetLevel is
192 equal to or greater than this value.
193
194 @header{wx/memory.h}
23324ae1 195*/
ef477678 196#define WXTRACELEVEL(level, format, ...)
23324ae1
FM
197
198/**
ef477678
BP
199 @deprecated Use one of the wxLogTrace() functions or one of the
200 wxVLogTrace() functions instead.
201
202 Takes printf-style variable argument syntax. Output is directed to the
203 current output stream (see wxDebugContext).
204
205 @header{wx/memory.h}
23324ae1 206*/
ef477678
BP
207void wxTrace(const wxString& format, ...);
208
209/**
210 @deprecated Use one of the wxLogTrace() functions or one of the
211 wxVLogTrace() functions instead.
212
213 Takes @e printf() style variable argument syntax. Output is directed to the
214 current output stream (see wxDebugContext). The first argument should be
215 the level at which this information is appropriate. It will only be output
216 if the level returned by wxDebugContext::GetLevel() is equal to or greater
217 than this value.
218
219 @header{wx/memory.h}
220*/
221void wxTraceLevel(int level, const wxString& format, ...);
222
223//@}
23324ae1 224