/home/coin/Smi-0.5.1/CoinUtils/src/CoinError.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef CoinError_H
00004 #define CoinError_H
00005 
00006 #include <string>
00007 #include <iostream>
00008 #include <cassert>
00009 //-------------------------------------------------------------------
00010 //
00011 // Error class used to throw exceptions
00012 //
00013 // Errors contain:
00014 //
00015 //-------------------------------------------------------------------
00016 
00030 class CoinError  {
00031    friend void CoinErrorUnitTest();
00032 
00033 public:
00034     
00035   //-------------------------------------------------------------------
00036   // Get methods
00037   //-------------------------------------------------------------------   
00040 
00041     inline const std::string & message() const 
00042     { return message_; }
00044     inline const std::string & methodName() const 
00045     { return method_;  }
00047     inline const std::string & className() const 
00048     { return class_;   }
00050     inline const std::string & fileName() const 
00051     { return file_;  }
00053     inline int lineNumber() const 
00054     { return lineNumber_;   }
00056     void print() const;
00058   
00059     
00062 
00063     CoinError ()
00064       :
00065       message_(),
00066       method_(),
00067       class_(),
00068       file_(),
00069       lineNumber_(-1)
00070     {
00071       // nothing to do here
00072     }
00073   
00075     CoinError ( 
00076       std::string message, 
00077       std::string methodName, 
00078       std::string className)
00079       :
00080       message_(message),
00081       method_(methodName),
00082       class_(className),
00083       file_(),
00084       lineNumber_(-1)
00085     {
00086       // nothing to do here
00087     }
00088 
00090     CoinError ( 
00091       const char * message, 
00092       const char * methodName, 
00093       const char * className)
00094       :
00095       message_(message),
00096       method_(methodName),
00097       class_(className),
00098       file_(),
00099       lineNumber_(-1)
00100     {
00101       // nothing to do here
00102     }
00103 
00105     CoinError ( 
00106       const char * assertion, 
00107       const char * methodName, 
00108       const char * hint,
00109       const char * fileName, 
00110       int line);
00111 
00113     CoinError (const CoinError & source);
00114 
00116     CoinError & operator=(const CoinError& rhs);
00117 
00119     virtual ~CoinError ()
00120     {
00121       // nothing to do here
00122     }
00124     
00125 private:
00126     
00129 
00130     std::string message_;
00132     std::string method_;
00134     std::string class_;
00136     std::string file_;
00138     int lineNumber_;
00140 };
00141 #ifndef COIN_ASSERT
00142 #   define CoinAssertDebug(expression) assert(expression)
00143 #   define CoinAssertDebugHint(expression,hint) assert(expression)
00144 #   define CoinAssert(expression) assert(expression)
00145 #   define CoinAssertHint(expression,hint) assert(expression)
00146 #else
00147 #   ifdef NDEBUG
00148 #      define CoinAssertDebug(expression)               {}
00149 #      define CoinAssertDebugHint(expression,hint)      {}
00150        /********************* LL: FIXME: I think the code above is just as good
00151 #      define CoinAssertDebug(expression)               (static_cast<void> (0))
00152 #      define CoinAssertDebugHint(expression,hint)      (static_cast<void> (0))
00153        ***********************************************************************/
00154 #   else
00155 #      if  (__GNUC_PREREQ (2, 6))
00156 #         define CoinAssertDebug(expression) {                             \
00157              if (!(expression)) {                                          \
00158                 throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00159                                 "", __FILE__, __LINE__);                   \
00160              }                                                             \
00161           }
00162 #         define CoinAssertDebugHint(expression,hint) {                    \
00163              if (!(expression)) {                                          \
00164                 throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00165                                 hint, __FILE__,__LINE__);                  \
00166              }                                                             \
00167           }
00168 #      else
00169 #         define CoinAssertDebug(expression) {                             \
00170              if (!(expression)) {                                          \
00171                 throw CoinError(__STRING(expression), "",                  \
00172                                 "", __FILE__,__LINE__);                    \
00173              }                                                             \
00174           }
00175 #         define CoinAssertDebugHint(expression,hint) {                    \
00176              if (!(expression)) {                                          \
00177                 throw CoinError(__STRING(expression), "",                  \
00178                                 hint, __FILE__,__LINE__);                  \
00179              }                                                             \
00180           }
00181 #      endif
00182 /**************************** LL: FIXME: I think the code above is just as good
00183 #if  (__GNUC_PREREQ (2, 6))
00184 # define CoinAssertDebug(expression) \
00185   (static_cast<void> ((expression) ? 0 :                                              \
00186                        ( throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, "",\
00187                        __FILE__,__LINE__))))
00188 # define CoinAssertDebugHint(expression,hint) \
00189   (static_cast<void> ((expression) ? 0 :                                              \
00190                        ( throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, hint ,\
00191                         __FILE__,__LINE__))))
00192 #else
00193 # define CoinAssertDebug(expression) \
00194   (static_cast<void> ((expression) ? 0 :                                              \
00195                        ( throw CoinError(__STRING(expression), "", "", __FILE__,__LINE__))))
00196 # define CoinAssertDebugHint(expression,hint) \
00197   (static_cast<void> ((expression) ? 0 :                                              \
00198                        ( throw CoinError(__STRING(expression), "", hint , __FILE__,__LINE__))))
00199 #endif
00200 ******************************************************************************/
00201 #   if  (__GNUC_PREREQ (2, 6))
00202 #      define CoinAssert(expression) {                                  \
00203           if (!(expression)) {                                          \
00204              throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00205                              "", __FILE__, __LINE__);                   \
00206           }                                                             \
00207        }
00208 #      define CoinAssertHint(expression,hint) {                         \
00209           if (!(expression)) {                                          \
00210              throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00211                              hint, __FILE__,__LINE__);                  \
00212           }                                                             \
00213        }
00214 #   else
00215 #      define CoinAssert(expression) {                                  \
00216           if (!(expression)) {                                          \
00217              throw CoinError(__STRING(expression), "",                  \
00218                              "", __FILE__,__LINE__);                    \
00219           }                                                             \
00220        }
00221 #      define CoinAssertHint(expression,hint) {                         \
00222           if (!(expression)) {                                          \
00223              throw CoinError(__STRING(expression), "",                  \
00224                              hint, __FILE__,__LINE__);                  \
00225           }                                                             \
00226        }
00227 #   endif
00228 
00229 /**************************** LL: FIXME: I think the code above is just as good
00230 #if  (__GNUC_PREREQ (2, 6))
00231 # define CoinAssert(expression) \
00232   (static_cast<void> ((expression) ? 0 :                                              \
00233                        ( throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, "",\
00234                        __FILE__,__LINE__))))
00235 # define CoinAssertHint(expression,hint) \
00236   (static_cast<void> ((expression) ? 0 :                                              \
00237                        ( throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, hint ,\
00238                         __FILE__,__LINE__))))
00239 #else
00240 # define CoinAssert(expression) \
00241   (static_cast<void> ((expression) ? 0 :                                              \
00242                        ( throw CoinError(__STRING(expression), "", "", __FILE__,__LINE__))))
00243 # define CoinAssertHint(expression,hint) \
00244   (static_cast<void> ((expression) ? 0 :                                              \
00245                        ( throw CoinError(__STRING(expression), "", hint , __FILE__,__LINE__))))
00246 #endif
00247 ******************************************************************************/
00248 #endif
00249 #   endif
00250 
00251 
00252 //#############################################################################
00258 void
00259 CoinErrorUnitTest();
00260 
00261 #endif

Generated on Wed Aug 22 06:52:33 2007 by  doxygen 1.4.7