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

abkassert.h

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00042 
00044 
00045 /* June 17, 1997  imarkov   added abkguess()
00046  June 17, 1997  imarkov   added abkassert_stop_here(), abkguess_stop_here()
00047  970824   ilm   added endl before assert/fatal/warn/guess messages
00048  970923   ilm   added abk_dump_stack()
00049  971214   mro   made abkassert() and abkfatal() take care of seeds.out
00050                   note: abkrand.h is included at *end* of file, because
00051                   it's needed to make sure SeedCleaner is defined -- but
00052                   SeedCleaner is used in macros, so not needed until expanded.
00053                   Putting abkrand.h at beginning of file can cause errors
00054                   due to cyclic includes.
00055  980303   ilm   added abk_dump_stack()
00056 
00057  This file to be included into all projects in the group
00058 */
00059 
00060 #ifndef  _ABKASSERT_H_
00061 #define  _ABKASSERT_H_
00062 
00063 #include <iostream>
00064 #include "abkseed.h"
00065 
00066 using std::cerr;
00067 using std::cout;
00068 using std::ostream;
00069 using std::istream;
00070 using std::endl;
00071 
00072 //:  name abkassert_stop_here(); abkguess_stop_here(); ....
00073 //   Breakpoints for abkassert, abkguess, abkfatal, abkwarn
00074 //   When  debugging, you can put breakpoints in abkassert_stop_here(),
00075 //   but this should be redundant since abkassert() is always fatal
00076 extern void abkassert_stop_here();
00077 extern void  abkguess_stop_here();
00078 
00079 extern void  abkfatal_stop_here();
00080 extern void   abkwarn_stop_here();
00081 
00082 //: defined in platfDepend.cxx 
00083 extern void   abk_dump_stack();    
00084 //: defined in platfDepend.cxx 
00085 extern void   abk_call_debugger();  
00086 
00087 #ifdef ABKDEBUG
00088 #define STACK_DUMP abk_dump_stack();
00089 #define abkfatal_breakpoint abkfatal_stop_here();
00090 #define abkwarn_breakpoint abkwarn_stop_here();
00091 #else
00092 #define STACK_DUMP 0;
00093 #define abkfatal_breakpoint 0;
00094 #define abkwarn_breakpoint 0;
00095 #endif
00096 
00097 const char* SgnPartOfFileName(const char * fileName);
00098 
00099 char* BaseFileName(char *filename);
00100 
00101 #ifdef ABKDEBUG
00102 //: if ABKDEBUG is defined it checks the condition and
00103 // if it fails, prints the message. If NDEBUG is not
00104 // defined, it prints line number and filename, then stops.
00105 // If NDEBUG is defined, it continues (standard ssert.h behavior)
00106 // To have ABKDEBUG defined, your compiler should use -DDEBUG argument
00107 // Otherwise, there is 0 overhead to have abkassert()
00108 #define abkassert(CONDITION, ERRMESSAGE)                                \
00109         {  if (!(CONDITION))                                            \
00110        {  cerr << endl << (ERRMESSAGE) << endl;                         \
00111           cerr << "  (Error in " << SgnPartOfFileName(__FILE__)         \
00112                                        << ":" << __LINE__  <<")"<<endl; \
00113           {SeedCleaner clean_err_exit;}                                     \
00114           abk_dump_stack();                                             \
00115           abkassert_stop_here();                                        \
00116           abort();                         /* Armageddon now */         \
00117        }                                                                \
00118     }                               
00119 #else
00120 #define abkassert(CONDITION, ERRMESSAGE) ((void) 0)
00121 #endif
00122 
00123 //        char * __p=(char *) 0;__p[0]=0;  /* Armageddon now */         
00124 
00125 #ifdef ABKDEBUG
00126 #define abkassert2(CONDITION, ERR1, ERR2)                               \
00127         {  if (!(CONDITION))                                            \
00128        {  cerr << endl << (ERR1) << (ERR2) << endl;                     \
00129           cerr << "  (Error in " << SgnPartOfFileName(__FILE__)         \
00130                                        << ":" << __LINE__  <<")"<<endl; \
00131           {SeedCleaner clean_err_exit;}                                     \
00132           abk_dump_stack();                                             \
00133           abkassert_stop_here();                                        \
00134           abort(); char * __p=(char *) 0;__p[0]=0;                      \
00135        }                                                                \
00136     }                               
00137 #else
00138 #define abkassert2(CONDITION, ERR1, ERR2) ((void) 0)
00139 #endif
00140 
00141 #ifdef ABKDEBUG
00142 #define abkassert3(CONDITION, ERR1, ERR2, ERR3)                         \
00143         {  if (!(CONDITION))                                            \
00144        {  cerr << endl << (ERR1) << (ERR2) <<(ERR3) << endl;            \
00145           cerr << "  (Error in " << SgnPartOfFileName(__FILE__)         \
00146                                        << ":" << __LINE__  <<")"<<endl; \
00147           {SeedCleaner clean_err_exit;}                                     \
00148           abk_dump_stack();                                             \
00149           abkassert_stop_here();                                        \
00150           abort();char * __p=(char *) 0;__p[0]=0; /* Armageddon now */  \
00151        }                                                                \
00152     }                               
00153 #else
00154 #define abkassert3(CONDITION, ERR1, ERR2, ERR3) ((void) 0)
00155 #endif
00156 
00157 #ifdef ABKDEBUG
00158 //: Same as abkassert, but does not stop the program.
00159 #define abkguess(CONDITION, ERRMESSAGE)                                 \
00160         {  if (!(CONDITION))                                            \
00161        {  cerr << endl << (ERRMESSAGE);                                 \
00162           cerr << " in line "<<__LINE__<<", file "<<__FILE__<<endl;     \
00163           abkguess_stop_here();                                         \
00164        }                                                                \
00165     }                               
00166 #else
00167 #define abkguess(CONDITION, ERRMESSAGE) ((void) 0)
00168 #endif
00169 
00170 #ifdef ABKDEBUG
00171 #define abkguess2(CONDITION, ERR1,ERR2 )                                \
00172         {  if (!(CONDITION))                                            \
00173        {  cerr << endl << (ERR1) << (ERR2);                             \
00174           cerr << " in line "<<__LINE__<<", file "<<__FILE__<<endl;     \
00175           abkguess_stop_here();                                         \
00176        }                                                                \
00177     }                               
00178 #else
00179 #define abkguess2(CONDITION, ERR1, ERR2) ((void) 0)
00180 #endif
00181 
00182 #ifdef ABKDEBUG
00183 #define abkguess3(CONDITION,ERR1,ERR2,ERR3)                             \
00184         {  if (!(CONDITION))                                            \
00185        {  cerr << endl << (ERR1) << (ERR2) << (ERR3);                   \
00186           cerr << " in line "<<__LINE__<<", file "<<__FILE__<<endl;     \
00187           abkguess_stop_here();                                         \
00188        }                                                                \
00189     }                               
00190 #else
00191 #define abkguess3(CONDITION, ERR1, ERR2, ERR3) ((void) 0)
00192 #endif
00193 
00194 //: just like abkassert(), but does not depend on  whether
00195 // a symbol is defined. "unconditional assertion"
00196 // should be used in all noncritical places
00197 #define abkfatal(CONDITION, ERRMESSAGE)                                 \
00198         {  if (!(CONDITION))                                            \
00199        {  cerr << endl << (ERRMESSAGE) ;                                \
00200           cerr<<"  (Fatal error in " << SgnPartOfFileName(__FILE__)     \
00201                                        << ":" << __LINE__  <<")"<<endl; \
00202           {SeedCleaner clean_err_exit;}                                     \
00203           STACK_DUMP;                                                   \
00204           abkfatal_breakpoint;                                          \
00205           abort(); char * __p=(char *) 0;__p[0]=0;  /* Armageddon now */\
00206        }                                                                \
00207     }                               
00208 
00209 #define abkfatal2(CONDITION, ERR1, ERR2)                                \
00210         {  if (!(CONDITION))                                            \
00211        {  cerr << endl << (ERR1) << (ERR2);                             \
00212           cerr<<"  (Fatal error in " << SgnPartOfFileName(__FILE__)     \
00213                                        << ":" << __LINE__  <<")"<<endl; \
00214           {SeedCleaner clean_err_exit;}                                     \
00215           STACK_DUMP;                                                   \
00216           abkfatal_breakpoint;                                          \
00217           abort(); char * __p=(char *) 0;__p[0]=0;  /* Armageddon now */\
00218        }                                                                \
00219     }                               
00220 
00221 #define abkfatal3(CONDITION, ERR1, ERR2, ERR3)                          \
00222         {  if (!(CONDITION))                                            \
00223        {  cerr << endl << (ERR1) << (ERR2) << (ERR3);                   \
00224           cerr<<"  (Fatal error in " << SgnPartOfFileName(__FILE__)     \
00225                                        << ":" << __LINE__  <<")"<<endl; \
00226           {SeedCleaner clean_err_exit;}                                     \
00227           STACK_DUMP;                                                   \
00228           abkfatal_breakpoint;                                          \
00229           abort(); char * __p=(char *) 0;__p[0]=0;  /* Armageddon now */\
00230        }                                                                \
00231     }                               
00232 
00233 //: just like abkguess() 3d, but does not depend whether
00234 // a symbol is defined. "unconditional warning"
00235 // should be used in all noncritical places
00236 #define abkwarn(CONDITION, ERRMESSAGE)                                  \
00237         {  if (!(CONDITION))                                            \
00238        {  cerr << endl << (ERRMESSAGE);                                 \
00239           cerr << " (Warning in " << SgnPartOfFileName(__FILE__)        \
00240                                      << ":" << __LINE__ <<")"<<endl;    \
00241           abkwarn_breakpoint;                                           \
00242        }                                                                \
00243     }
00244                                
00245 #define abkwarn2(CONDITION, ERR1, ERR2)                                 \
00246         {  if (!(CONDITION))                                            \
00247        {  cerr << endl << (ERR1) << (ERR2);                             \
00248           cerr << " (Warning in " << SgnPartOfFileName(__FILE__)        \
00249                                      << ":" << __LINE__ <<")"<<endl;    \
00250           abkwarn_breakpoint;                                           \
00251        }                                                                \
00252     }
00253 
00254 #define abkwarn3(CONDITION, ERR1, ERR2, ERR3)                           \
00255         {  if (!(CONDITION))                                            \
00256        {  cerr << endl << (ERR1) << (ERR2) << (ERR3);                   \
00257           cerr << " (Warning in " << SgnPartOfFileName(__FILE__)        \
00258                                      << ":" << __LINE__ <<")"<<endl;    \
00259           abkwarn_breakpoint;                                           \
00260        }                                                                \
00261     }
00262 #endif

Generated on Mon Apr 25 01:09:23 2005 for Parquete by doxygen 1.3.2