GL Studio C++ Runtime API
disti_assert.h
Go to the documentation of this file.
1/*! \file
2 \brief Contains the DistiAssert macro.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd., Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40#ifndef INCLUDED_DISTI_ASSERT_H
41#define INCLUDED_DISTI_ASSERT_H
42
43#include "disti_include.h"
45#include <stddef.h>
46
47namespace disti
48{
49class DistiException;
50
51/// Swaps the incoming DistiException objects.
52/// \param first The first object to swap.
53/// \param second The other object to swap.
54DISTI_EXPORT void swap( DistiException& first, DistiException& second );
55
56/** DistiException just contains a string error message */
58{
59public:
60 /// Construct a DistiException with the given error message.
61 /// \param what The error message.
62 explicit DISTI_EXPORT DistiException( const char* what );
63
64 /// Copy constructor
65 /// \param other The object to copy.
66 DISTI_EXPORT DistiException( const DistiException& other );
67
68 /// Assignment operator
69 /// \param other The object value to assign.
70 /// \return The new object.
71 DISTI_EXPORT DistiException& operator=( DistiException other );
72
73#ifdef DISTI_HAS_RVAL_REFS
74 /// Move operator
75 /// \param other The object to move.
76 DISTI_EXPORT DistiException( DistiException&& other );
77#endif
78 virtual DISTI_EXPORT ~DistiException();
79
80 /// \note Never returns NULL.
81 /// \return The underlying error string.
82 virtual DISTI_EXPORT const char* what() const;
83
84 friend DISTI_EXPORT void swap( DistiException& first, DistiException& second );
85
86private:
87 char* _what; ///< The error string.
88 size_t _len; ///< The length of the error string.
89};
90
91/** The callback type. It receives an error message string */
92typedef void ( *DistiAssertHandler )( const char* errMessage );
93
94/// This function enables users to override the default behavior of DistiAssert(), which is used
95/// throughout the GL Studio code base to test prerequisites etc. The user can set a function to
96/// be called when DistiAssert fires. Only one callback can be registered, so calling the set
97/// function multiple times overwrites the previous handler. If the given handler is null,
98/// DistiAssert() reverts to its default behavior.
99/// \note This function is deprecated; Use SetGlsVerifyHandler or SetGlsAssertHandler instead.
101
102/// This function enables users to override the default behavior of GLS_VERIFY(), which is used
103/// throughout the GL Studio code base to test prerequisites etc. The user can set a function to
104/// be called when GLS_VERIFY fires. Only one callback can be registered, so calling the set
105/// function multiple times overwrites the previous handler. If the given handler is null,
106/// GLS_VERIFY() reverts to its default behavior.
108
109/// This function enables users to override the default behavior of GLS_ASSERT(), which is used
110/// throughout the GL Studio code base to test prerequisites etc. The user can set a function to
111/// be called when GLS_ASSERT fires. Only one callback can be registered, so calling the set
112/// function multiple times overwrites the previous handler. If the given handler is null,
113/// GLS_ASSERT() reverts to its default behavior.
115
116/// If a callback is registered, that function is invoked when an assertion fails (exp is false).
117/// If the callback is null, when the assertion fails, DistiAssert will popup a messagebox allowing
118/// the user to Abort, Retry(Debug) or Ignore the error. Retry will cause a User breakpoint on the
119/// error, Abort will throw a DistiException describing the error, and Ignore does nothing.
120/// At present, the function does the same thing in debug and release modes.
121/// \note This function is deprecated; Use GLS_ASSERT or GLS_VERIFY instead.
122#if defined( GLS_DEBUG )
123# define DistiAssert( exp ) (void)( ( exp ) || ( ::disti::DistiAssertDebug( # exp, __FILE__, __LINE__ ), 0 ) )
124#else
125# define DistiAssert( exp ) (void)( ( exp ) || ( ::disti::DistiAssertRelease( # exp, __FILE__, __LINE__ ), 0 ) )
126#endif
127
128/// Convenience macro to quiet warnings about unused return values.
129#define GLS_UNUSED( exp ) \
130 do \
131 { \
132 (void)sizeof( exp ); \
133 } while( 0 )
134
135/** In builds where GLS_DEBUG is defined OR where NDEBUG is not defined, this macro has the following behavior:
136 *
137 * 1. If a callback is registered with SetGlsAssertHandler(), that handler is invoked when an assertion
138 * fails (\a exp is false).
139 *
140 * 2. If no handler is registered and the assertion fails, on Windows GLS_ASSERT will popup a message box
141 * allowing the user to Abort, Retry (Debug), or Ignore the error. Retry will cause a User breakpoint
142 * on the error, Abort will throw a DistiException describing the error, and Ignore does nothing.
143 *
144 * If none of the aforementioned symbols are defined, this function does nothing, and does not evaluate \a exp.
145 *
146 * \note Use this function instead of the deprecated DistiAssert() macro for checks that should be tested in
147 * Debug builds only.
148 */
149#if defined( GLS_DEBUG ) || !defined( NDEBUG )
150# define GLS_ASSERT( exp ) \
151 do \
152 { \
153 (void)( ( exp ) || ( ::disti::GlsAssert( #exp, __FILE__, __LINE__ ), 0 ) ); \
154 } while( 0 )
155#else
156# define GLS_ASSERT( exp ) GLS_UNUSED( exp )
157#endif
158
159/** The GLS_VERIFY() macro has the following behavior:
160 *
161 * 1. If a callback is registered with SetGlsVerifyHandler(), that handler is invoked when \a exp is false.
162 *
163 * 2. If no handler is registered and the \a exp is false, on Windows GLS_VERIFY() will popup a message box
164 * allowing the user to Abort, Retry (Debug), or Ignore the error. Retry will cause a User breakpoint
165 * on the error, Abort will throw a DistiException describing the error, and Ignore does nothing.
166 *
167 * \note Use this function instead of the deprecated DistiAssert() macro for checks that should be tested in
168 * both Debug and Release builds.
169 */
170#define GLS_VERIFY( exp ) (void)( ( exp ) || ( ::disti::GlsVerify( #exp, __FILE__, __LINE__ ), 0 ) )
171
172/// Do not call DistiAssertDebug directly, instead use the DistiAssert macro
173/// \note This function is deprecated; Use GlsAssert or GlsVerify instead.
174/// \param expression The string representation of the code being asserted.
175/// \param filename The file where the code resides.
176/// \param lineNumber The line number where the code resides.
177DISTI_EXPORT void DistiAssertDebug( const char* expression, const char* filename, unsigned int lineNumber );
178
179/// Do not call DistiAssertRelease directly, instead use the DistiAssert macro
180/// \note This function is deprecated; Use GlsAssert or GlsVerify instead.
181/// \param expression The string representation of the code being asserted.
182/// \param filename The file where the code resides.
183/// \param lineNumber The line number where the code resides.
184DISTI_EXPORT void DistiAssertRelease( const char* expression, const char* filename, unsigned int lineNumber );
185
186/// Do not call GlsVerify directly, instead use the GLS_VERIFY macro.
187/// \param expression The string representation of the code being asserted.
188/// \param filename The file where the code resides.
189/// \param lineNumber The line number where the code resides.
190DISTI_EXPORT void GlsVerify( const char* expression, const char* filename, unsigned int lineNumber );
191
192/// Do not call GlsAssert directly, instead use the GLS_ASSERT macro.
193/// \param expression The string representation of the code being asserted.
194/// \param filename The file where the code resides.
195/// \param lineNumber The line number where the code resides.
196DISTI_EXPORT void GlsAssert( const char* expression, const char* filename, unsigned int lineNumber );
197
198/// Assert the pointer is not null and return it.
199/// \param p The pointer to check.
200/// \return The pointer that was checked.
201template<class T>
202T* ValidatePointer( const T* const p )
203{
204 DistiAssert( p );
205 return p;
206}
207
208} // namespace disti
209
210#endif
Definition: disti_assert.h:58
virtual const char * what() const
DistiException & operator=(DistiException other)
friend void swap(DistiException &first, DistiException &second)
DistiException(const char *what)
#define DistiAssert(exp)
Definition: disti_assert.h:125
A file for all GL Studio files to include.
Macros and helper code to determine what subset of C++11/14/17 is available.
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
void GlsAssert(const char *expression, const char *filename, unsigned int lineNumber)
void(* DistiAssertHandler)(const char *errMessage)
Definition: disti_assert.h:92
void DistiAssertRelease(const char *expression, const char *filename, unsigned int lineNumber)
void GlsVerify(const char *expression, const char *filename, unsigned int lineNumber)
T * ValidatePointer(const T *const p)
Definition: disti_assert.h:202
void SetGlsAssertHandler(DistiAssertHandler)
void DistiAssertDebug(const char *expression, const char *filename, unsigned int lineNumber)
void swap(DistiException &first, DistiException &second)
void SetGlsVerifyHandler(DistiAssertHandler)
void SetDistiAssertHandler(DistiAssertHandler)