Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cl_assert.h

Go to the documentation of this file.
00001 /*
00002         $Id: cl_assert.h,v 1.7 2001/03/04 17:42:08 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00016 
00017 #ifndef header_cl_assert
00018 #define header_cl_assert
00019 
00020 #include <list>
00021 
00022 enum ErrorChannels
00023 {
00024         info_display = 1,
00025         info_sound   = 2,
00026         info_input   = 4,
00027         info_network = 8
00028 };
00029 
00030 #ifndef __PRETTY_FUNCTION__ 
00031 #define __PRETTY_FUNCTION__ NULL
00032 #endif
00033 
00034 #ifndef __STRING
00035 #define cl_assert(a) CL_Assert::die(a, __FILE__, __LINE__, __PRETTY_FUNCTION__, #a);
00036 #else
00037 #define cl_assert(a) CL_Assert::die(a, __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(a));
00038 #endif
00039 
00040 /*
00041 #ifdef WIN32
00042 #define cl_assert(a) CL_Assert::die(a, __FILE__, __LINE__, NULL, #a);
00043 #endif
00044 #ifdef __BEOS__
00045 #define cl_assert(a) CL_Assert::die(a, __FILE__, __LINE__, NULL, #a);
00046 #endif
00047 #ifndef cl_assert
00048 #define cl_assert(a) CL_Assert::die(a, __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(a));
00049 #endif
00050 */
00051 
00052 #define cl_info(errchannel, message) \
00053         CL_Assert::info(errchannel, message, __FILE__, __LINE__);
00054 
00055 #ifdef DEBUG
00056         #define cl_assert_debug(a) cl_assert(a)
00057         #define cl_info_debug(a,b) cl_info(a,b)
00058 #else
00059         #define cl_assert_debug(a)
00060         #define cl_info_debug(a,b)
00061 #endif
00062 
00063 
00064 class CL_AssertListener;
00065 class CL_Assert
00066 //: This is ClanLib's assertion class.
00067 // It is needed because some
00068 // implementations requires to be notified before ClanLib is exited.
00069 // For instance the svgalib implementation need release the keyboard lock.
00070 {
00071         static std::list<CL_AssertListener*> listeners;
00072 public:
00073         static void enable_channels(int channel_mask);
00074         //: Enabled the error channels specified by the 'channel_mask'.
00075         //: This can be used to get extra debugging information from limited
00076         //: parts of ClanLib.
00078 
00079         static void die(bool a, const char *file, int line, const char *func, const char *assert_str);
00080         //: Produces an assert. This function shouldn't be called directly -
00081         //: instead, use the cl_assert macro.
00087 
00088         static void info(int channel, const char *text, const char *file, int line);
00089         //: Writes an info statements on the specified channel. Don't call
00090         //: this one directly, instead use the cl_info macro.
00095         
00096         static void add_listener(CL_AssertListener *listener);
00097         //: Adds an assertion listener which will be called in case of an
00098         //: assertion.
00100 
00101         static void remove_listener(CL_AssertListener *listener);
00102         //: Removes an assertion listener.
00104 };
00105 
00106 class CL_AssertListener
00107 //: Interface used by the CL_Assert class.
00108 {
00109 public:
00110         virtual ~CL_AssertListener() {;}
00111 
00112         virtual void assert_occoured(const char *file, int line)=0;
00113         //: Called by CL_Assert::die() when assertion occours. Remember to
00114         //: add it as an listener - otherwise it will _NOT_ be called.
00117 };
00118 
00119 #endif

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001