New error.h moved to lemon/
authorklao
Thu, 03 Feb 2005 19:31:37 +0000
changeset 11223ce7fc516cca
parent 1121 8f066fdf6dc9
child 1123 a2e93889a604
New error.h moved to lemon/
src/lemon/error.h
src/work/klao/error.h
src/work/klao/error_test.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/lemon/error.h	Thu Feb 03 19:31:37 2005 +0000
     1.3 @@ -0,0 +1,387 @@
     1.4 +/* -*- C++ -*-
     1.5 + * src/lemon/error.h - Part of LEMON, a generic C++ optimization library
     1.6 + *
     1.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
     1.9 + *
    1.10 + * Permission to use, modify and distribute this software is granted
    1.11 + * provided that this copyright notice appears in all copies. For
    1.12 + * precise terms see the accompanying LICENSE file.
    1.13 + *
    1.14 + * This software is provided "AS IS" with no warranty of any kind,
    1.15 + * express or implied, and with no claim as to its suitability for any
    1.16 + * purpose.
    1.17 + *
    1.18 + */
    1.19 +
    1.20 +#ifndef LEMON_ERROR_H
    1.21 +#define LEMON_ERROR_H
    1.22 +
    1.23 +//! \ingroup misc
    1.24 +//! \file
    1.25 +//! \brief Basic exception classes and error handling.
    1.26 +
    1.27 +#include <exception>
    1.28 +#include <string>
    1.29 +#include <sstream>
    1.30 +#include <iostream>
    1.31 +#include <cstdlib>
    1.32 +
    1.33 +#include <boost/shared_ptr.hpp>
    1.34 +
    1.35 +namespace lemon {
    1.36 +
    1.37 +  /// Exception-safe convenient "error message" class.
    1.38 +
    1.39 +  /// Helper class which provides a convenient ostream-like (operator <<
    1.40 +  /// based) interface to create a string message. Mostly useful in
    1.41 +  /// exception classes (therefore the name).
    1.42 +  class ErrorMessage {
    1.43 +  protected:
    1.44 +    ///\e 
    1.45 +    boost::shared_ptr<std::ostringstream> buf;
    1.46 +    
    1.47 +    ///\e 
    1.48 +    bool init() throw() {
    1.49 +      try {
    1.50 +	buf.reset(new std::ostringstream);
    1.51 +      }
    1.52 +      catch(...) {
    1.53 +	buf.reset();
    1.54 +      }
    1.55 +      return buf;
    1.56 +    }
    1.57 +
    1.58 +  public:
    1.59 +
    1.60 +    ///\e 
    1.61 +    ErrorMessage() throw() { init(); }
    1.62 +
    1.63 +    ///\e 
    1.64 +    ErrorMessage(const char *message) throw() {
    1.65 +      init();
    1.66 +      *this << message;
    1.67 +    }
    1.68 +
    1.69 +    ///\e 
    1.70 +    ErrorMessage(const std::string &message) throw() {
    1.71 +      init();
    1.72 +      *this << message;
    1.73 +    }
    1.74 +
    1.75 +    ///\e 
    1.76 +    template <typename T>
    1.77 +    ErrorMessage& operator<<(const T &t) throw() {
    1.78 +      if( !buf ) return *this;
    1.79 +
    1.80 +      try {
    1.81 +	*buf << t;
    1.82 +      }
    1.83 +      catch(...) {
    1.84 +	buf.reset();
    1.85 +      }
    1.86 +    }
    1.87 +
    1.88 +    ///\e 
    1.89 +    const char* message() throw() {
    1.90 +      if( !buf ) return 0;
    1.91 +
    1.92 +      const char* mes = 0;
    1.93 +      try {
    1.94 +	mes = buf->str().c_str();
    1.95 +      }
    1.96 +      catch(...) {}
    1.97 +      return mes;
    1.98 +    }
    1.99 +    
   1.100 +  };
   1.101 +
   1.102 +  /**
   1.103 +   * \brief Generic exception class.
   1.104 +   *
   1.105 +   * Base class for exceptions used in LEMON.
   1.106 +   */
   1.107 +  class Exception : public std::exception {
   1.108 +  public:
   1.109 +    ///\e 
   1.110 +    Exception() {}
   1.111 +    ///\e 
   1.112 +    virtual ~Exception() throw() {}
   1.113 +
   1.114 +    ///\e
   1.115 +    virtual const char* exceptionName() const {
   1.116 +      return "lemon::Exception";
   1.117 +    }
   1.118 +    
   1.119 +    ///\e 
   1.120 +    virtual const char* what() const throw() {
   1.121 +      return exceptionName();
   1.122 +    }
   1.123 +  };
   1.124 +
   1.125 +  /**
   1.126 +   * \brief One of the two main subclasses of \ref Exception.
   1.127 +   *
   1.128 +   * Logic errors represent problems in the internal logic of a program;
   1.129 +   * in theory, these are preventable, and even detectable before the
   1.130 +   * program runs (e.g., violations of class invariants).
   1.131 +   *
   1.132 +   * For a typical example \see UninitializedParameterError.
   1.133 +   */
   1.134 +  class LogicError : public Exception {
   1.135 +  public:
   1.136 +    virtual const char* exceptionName() const {
   1.137 +      return "lemon::LogicError";
   1.138 +    }
   1.139 +  };
   1.140 +
   1.141 +  
   1.142 +  /**
   1.143 +   * \brief One of the two main subclasses of \ref Exception.
   1.144 +   *
   1.145 +   * Runtime errors represent problems outside the scope of a program;
   1.146 +   * they cannot be easily predicted and can generally only be caught as
   1.147 +   * the program executes.
   1.148 +   */
   1.149 +  class RuntimeError : public Exception {
   1.150 +  public:
   1.151 +    virtual const char* exceptionName() const {
   1.152 +      return "lemon::RuntimeError";
   1.153 +    }
   1.154 +  };
   1.155 +
   1.156 +  ///\e
   1.157 +  class RangeError : public RuntimeError {
   1.158 +  public:
   1.159 +    virtual const char* exceptionName() const {
   1.160 +      return "lemon::RangeError";
   1.161 +    }
   1.162 +  };
   1.163 +
   1.164 +  ///\e 
   1.165 +  class IOError : public RuntimeError {
   1.166 +  public:
   1.167 +    virtual const char* exceptionName() const {
   1.168 +      return "lemon::IOError";
   1.169 +    }
   1.170 +  };
   1.171 +
   1.172 +  ///\e 
   1.173 +  class DataFormatError : public IOError {
   1.174 +  protected:
   1.175 +    const char *_message;
   1.176 +    int _line;
   1.177 +    boost::shared_ptr<std::string> _file;
   1.178 +
   1.179 +  public:
   1.180 +    ///\e 
   1.181 +    explicit DataFormatError(const char *the_message)
   1.182 +      : _message(the_message), _line(0) {}
   1.183 +    ///\e 
   1.184 +    DataFormatError(const std::string &file_name, int line_num,
   1.185 +		    const char *the_message)
   1.186 +      : _message(the_message), _line(line_num) { file(file_name); }
   1.187 +
   1.188 +    ///\e 
   1.189 +    void line(int line_num) { _line=line_num; }
   1.190 +    ///\e 
   1.191 +    void message(char *the_message) { _message=the_message; }
   1.192 +    ///\e 
   1.193 +    void file(const std::string &file_name) {
   1.194 +      try {
   1.195 +	_file.reset(new std::string);
   1.196 +	*_file = file_name;
   1.197 +      }
   1.198 +      catch(...) {
   1.199 +	_file.reset();
   1.200 +      }
   1.201 +    }
   1.202 +
   1.203 +    ///\e
   1.204 +    int line() const { return _line; }
   1.205 +    ///\e
   1.206 +    const char* message() const { return _message; }
   1.207 +
   1.208 +    /// \brief Returns the filename.
   1.209 +    ///
   1.210 +    /// Returns \e "(unknown)" if the filename was not specified.
   1.211 +    const char* file() const {
   1.212 +      if( _file )
   1.213 +	return _file->c_str();
   1.214 +      else
   1.215 +	return "(unknown)";
   1.216 +    }
   1.217 +
   1.218 +    ///\e 
   1.219 +    virtual const char* what() const throw() {
   1.220 +      const char *mes = 0;
   1.221 +      try {
   1.222 +	std::ostringstream ostr;
   1.223 +	ostr << _message;
   1.224 +	if( _file || _line ) {
   1.225 +	  ostr << " (";
   1.226 +	  if( _file ) ostr << "in file '" << *_file << "'";
   1.227 +	  if( _file && _line ) ostr << " ";
   1.228 +	  if( _line ) ostr << "at line " << _line;
   1.229 +	  ostr << ")";
   1.230 +	}
   1.231 +	mes = ostr.str().c_str();
   1.232 +      }
   1.233 +      catch(...) {}
   1.234 +      if( mes ) return mes;
   1.235 +      return exceptionName();
   1.236 +    }
   1.237 +
   1.238 +    virtual const char* exceptionName() const {
   1.239 +      return "lemon::DataFormatError";
   1.240 +    }
   1.241 +
   1.242 +    virtual ~DataFormatError() throw() {}
   1.243 +  };
   1.244 +
   1.245 +
   1.246 +  ///\e
   1.247 +  class AssertionFailedError : public LogicError {
   1.248 +  protected:
   1.249 +    const char *assertion;
   1.250 +    const char *file;
   1.251 +    int line;
   1.252 +    const char *function;
   1.253 +    const char *message;
   1.254 +  public:
   1.255 +    ///\e
   1.256 +    AssertionFailedError(const char *_file, int _line, const char *func,
   1.257 +			 const char *msg, const char *_assertion = 0) :
   1.258 +      assertion(_assertion), file(_file), line(_line), function(func),
   1.259 +      message(msg) {}
   1.260 +
   1.261 +    ///\e
   1.262 +    const char* get_assertion() const { return assertion; }
   1.263 +    ///\e
   1.264 +    const char* get_message() const { return message; }
   1.265 +    ///\e
   1.266 +    const char* get_file() const { return file; }
   1.267 +    ///\e
   1.268 +    const char* get_function() const { return function; }
   1.269 +    ///\e
   1.270 +    int get_line() const { return line; }
   1.271 +
   1.272 +
   1.273 +    virtual const char* what() const throw() {
   1.274 +      const char *mes = 0;
   1.275 +      try {
   1.276 +	std::ostringstream ostr;
   1.277 +	ostr << file << ":" << line << ": ";
   1.278 +	if( function )
   1.279 +	  ostr << function << ": ";
   1.280 +	ostr << message;
   1.281 +	if( assertion )
   1.282 +	  ostr << " (assertion '" << assertion << "' failed)";
   1.283 +	mes = ostr.str().c_str();
   1.284 +      }
   1.285 +      catch(...) {}
   1.286 +      if( mes ) return mes;
   1.287 +      return exceptionName();
   1.288 +    }
   1.289 +
   1.290 +    virtual const char* exceptionName() const {
   1.291 +      return "lemon::AssertionFailedError";
   1.292 +    }
   1.293 +
   1.294 +    virtual ~AssertionFailedError() throw() {}
   1.295 +  };
   1.296 +
   1.297 +
   1.298 +  /****************  Macros  ****************/
   1.299 +
   1.300 +
   1.301 +  inline
   1.302 +  void assert_fail(const char *file, int line, const char *func,
   1.303 +		   const char *message, const char *assertion = 0,
   1.304 +		   bool do_abort=true)
   1.305 +  {
   1.306 +    using namespace std;
   1.307 +    cerr << file << ":" << line << ": ";
   1.308 +    if( func )
   1.309 +      cerr << func << ": ";
   1.310 +    cerr << message;
   1.311 +    if( assertion )
   1.312 +      cerr << " (assertion '" << assertion << "' failed)";
   1.313 +    cerr << endl;
   1.314 +    if(do_abort)
   1.315 +      abort();
   1.316 +  }
   1.317 +
   1.318 +  inline
   1.319 +  void assert_fail_throw(const char *file, int line, const char *func,
   1.320 +		   const char *message, const char *assertion = 0,
   1.321 +		   bool = true)
   1.322 +  {
   1.323 +    throw AssertionFailedError(file, line, func, message, assertion);
   1.324 +  }
   1.325 +
   1.326 +
   1.327 +}
   1.328 +#endif // LEMON_ERROR_H
   1.329 +
   1.330 +#undef LEMON_ASSERT
   1.331 +#undef LEMON_FIXME
   1.332 +
   1.333 +#ifndef LEMON_ASSERT_ABORT
   1.334 +#  define LEMON_ASSERT_ABORT 1
   1.335 +#endif
   1.336 +
   1.337 +#ifndef LEMON_ASSERT_HANDLER
   1.338 +#  ifdef LEMON_ASSERT_EXCEPTION
   1.339 +#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_throw
   1.340 +#  else
   1.341 +#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail
   1.342 +#  endif
   1.343 +#endif
   1.344 +
   1.345 +#if defined(NDEBUG) || defined(LEMON_DISABLE_ASSERTS)
   1.346 +
   1.347 +#  define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
   1.348 +
   1.349 +#else
   1.350 +
   1.351 +/**
   1.352 + * \brief Macro for assertions with customizable message
   1.353 + *
   1.354 + * Macro for assertions with customizable message.
   1.355 + *
   1.356 + * The behaviour can be customized with LEMON_ASSERT_HANDLER,
   1.357 + * LEMON_ASSERT_EXCEPTION and LEMON_ASSERT_ABORT defines. Asserts can be
   1.358 + * disabled by defining either NDEBUG or LEMON_DISABLE_ASSERTS macros.
   1.359 + *
   1.360 + * \todo We should provide some way to reset to the default behaviour,
   1.361 + * shouldn't we?
   1.362 + *
   1.363 + * \todo This whole 'assert' business should be placed in a separate
   1.364 + * include file.
   1.365 + *
   1.366 + * \todo __PRETTY_FUNCTION__ should be replaced by something
   1.367 + * compiler-independant, like BOOST_CURRENT_FUNCTION
   1.368 + */
   1.369 +
   1.370 +#  define LEMON_ASSERT(exp, msg)                 \
   1.371 +     (static_cast<void> (!!(exp) ? 0 : (         \
   1.372 +       LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
   1.373 +                            __PRETTY_FUNCTION__, \
   1.374 +			    (msg), #exp, LEMON_ASSERT_ABORT), 0)))
   1.375 +
   1.376 +#endif // NDEBUG || LEMON_DISABLE_ASSERTS
   1.377 +
   1.378 +/**
   1.379 + * \brief Macro for mark not yet implemented features.
   1.380 + *
   1.381 + * \todo Is this the right place for this? It should be used only in
   1.382 + * modules under development.
   1.383 + *
   1.384 + * \todo __PRETTY_FUNCTION__ should be replaced by something
   1.385 + * compiler-independant, like BOOST_CURRENT_FUNCTION
   1.386 + */
   1.387 +
   1.388 +# define LEMON_FIXME(msg) \
   1.389 +    (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
   1.390 +			  "FIXME: " msg))
     2.1 --- a/src/work/klao/error.h	Thu Feb 03 19:27:10 2005 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,387 +0,0 @@
     2.4 -/* -*- C++ -*-
     2.5 - * src/lemon/error.h - Part of LEMON, a generic C++ optimization library
     2.6 - *
     2.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     2.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
     2.9 - *
    2.10 - * Permission to use, modify and distribute this software is granted
    2.11 - * provided that this copyright notice appears in all copies. For
    2.12 - * precise terms see the accompanying LICENSE file.
    2.13 - *
    2.14 - * This software is provided "AS IS" with no warranty of any kind,
    2.15 - * express or implied, and with no claim as to its suitability for any
    2.16 - * purpose.
    2.17 - *
    2.18 - */
    2.19 -
    2.20 -#ifndef LEMON_ERROR_H
    2.21 -#define LEMON_ERROR_H
    2.22 -
    2.23 -//! \ingroup misc
    2.24 -//! \file
    2.25 -//! \brief Basic exception classes and error handling.
    2.26 -
    2.27 -#include <exception>
    2.28 -#include <string>
    2.29 -#include <sstream>
    2.30 -#include <iostream>
    2.31 -#include <cstdlib>
    2.32 -
    2.33 -#include <boost/shared_ptr.hpp>
    2.34 -
    2.35 -namespace lemon {
    2.36 -
    2.37 -  /// Exception-safe convenient "error message" class.
    2.38 -
    2.39 -  /// Helper class which provides a convenient ostream-like (operator <<
    2.40 -  /// based) interface to create a string message. Mostly useful in
    2.41 -  /// exception classes (therefore the name).
    2.42 -  class ErrorMessage {
    2.43 -  protected:
    2.44 -    ///\e 
    2.45 -    boost::shared_ptr<std::ostringstream> buf;
    2.46 -    
    2.47 -    ///\e 
    2.48 -    bool init() throw() {
    2.49 -      try {
    2.50 -	buf.reset(new std::ostringstream);
    2.51 -      }
    2.52 -      catch(...) {
    2.53 -	buf.reset();
    2.54 -      }
    2.55 -      return buf;
    2.56 -    }
    2.57 -
    2.58 -  public:
    2.59 -
    2.60 -    ///\e 
    2.61 -    ErrorMessage() throw() { init(); }
    2.62 -
    2.63 -    ///\e 
    2.64 -    ErrorMessage(const char *message) throw() {
    2.65 -      init();
    2.66 -      *this << message;
    2.67 -    }
    2.68 -
    2.69 -    ///\e 
    2.70 -    ErrorMessage(const std::string &message) throw() {
    2.71 -      init();
    2.72 -      *this << message;
    2.73 -    }
    2.74 -
    2.75 -    ///\e 
    2.76 -    template <typename T>
    2.77 -    ErrorMessage& operator<<(const T &t) throw() {
    2.78 -      if( !buf ) return *this;
    2.79 -
    2.80 -      try {
    2.81 -	*buf << t;
    2.82 -      }
    2.83 -      catch(...) {
    2.84 -	buf.reset();
    2.85 -      }
    2.86 -    }
    2.87 -
    2.88 -    ///\e 
    2.89 -    const char* message() throw() {
    2.90 -      if( !buf ) return 0;
    2.91 -
    2.92 -      const char* mes = 0;
    2.93 -      try {
    2.94 -	mes = buf->str().c_str();
    2.95 -      }
    2.96 -      catch(...) {}
    2.97 -      return mes;
    2.98 -    }
    2.99 -    
   2.100 -  };
   2.101 -
   2.102 -  /**
   2.103 -   * \brief Generic exception class.
   2.104 -   *
   2.105 -   * Base class for exceptions used in LEMON.
   2.106 -   */
   2.107 -  class Exception : public std::exception {
   2.108 -  public:
   2.109 -    ///\e 
   2.110 -    Exception() {}
   2.111 -    ///\e 
   2.112 -    virtual ~Exception() throw() {}
   2.113 -
   2.114 -    ///\e
   2.115 -    virtual const char* exceptionName() const {
   2.116 -      return "lemon::Exception";
   2.117 -    }
   2.118 -    
   2.119 -    ///\e 
   2.120 -    virtual const char* what() const throw() {
   2.121 -      return exceptionName();
   2.122 -    }
   2.123 -  };
   2.124 -
   2.125 -  /**
   2.126 -   * \brief One of the two main subclasses of \ref Exception.
   2.127 -   *
   2.128 -   * Logic errors represent problems in the internal logic of a program;
   2.129 -   * in theory, these are preventable, and even detectable before the
   2.130 -   * program runs (e.g., violations of class invariants).
   2.131 -   *
   2.132 -   * For a typical example \see UninitializedParameterError.
   2.133 -   */
   2.134 -  class LogicError : public Exception {
   2.135 -  public:
   2.136 -    virtual const char* exceptionName() const {
   2.137 -      return "lemon::LogicError";
   2.138 -    }
   2.139 -  };
   2.140 -
   2.141 -  
   2.142 -  /**
   2.143 -   * \brief One of the two main subclasses of \ref Exception.
   2.144 -   *
   2.145 -   * Runtime errors represent problems outside the scope of a program;
   2.146 -   * they cannot be easily predicted and can generally only be caught as
   2.147 -   * the program executes.
   2.148 -   */
   2.149 -  class RuntimeError : public Exception {
   2.150 -  public:
   2.151 -    virtual const char* exceptionName() const {
   2.152 -      return "lemon::RuntimeError";
   2.153 -    }
   2.154 -  };
   2.155 -
   2.156 -  ///\e
   2.157 -  class RangeError : public RuntimeError {
   2.158 -  public:
   2.159 -    virtual const char* exceptionName() const {
   2.160 -      return "lemon::RangeError";
   2.161 -    }
   2.162 -  };
   2.163 -
   2.164 -  ///\e 
   2.165 -  class IOError : public RuntimeError {
   2.166 -  public:
   2.167 -    virtual const char* exceptionName() const {
   2.168 -      return "lemon::IOError";
   2.169 -    }
   2.170 -  };
   2.171 -
   2.172 -  ///\e 
   2.173 -  class DataFormatError : public IOError {
   2.174 -  protected:
   2.175 -    const char *_message;
   2.176 -    int _line;
   2.177 -    boost::shared_ptr<std::string> _file;
   2.178 -
   2.179 -  public:
   2.180 -    ///\e 
   2.181 -    explicit DataFormatError(const char *the_message)
   2.182 -      : _message(the_message), _line(0) {}
   2.183 -    ///\e 
   2.184 -    DataFormatError(const std::string &file_name, int line_num,
   2.185 -		    const char *the_message)
   2.186 -      : _message(the_message), _line(line_num) { file(file_name); }
   2.187 -
   2.188 -    ///\e 
   2.189 -    void line(int line_num) { _line=line_num; }
   2.190 -    ///\e 
   2.191 -    void message(char *the_message) { _message=the_message; }
   2.192 -    ///\e 
   2.193 -    void file(const std::string &file_name) {
   2.194 -      try {
   2.195 -	_file.reset(new std::string);
   2.196 -	*_file = file_name;
   2.197 -      }
   2.198 -      catch(...) {
   2.199 -	_file.reset();
   2.200 -      }
   2.201 -    }
   2.202 -
   2.203 -    ///\e
   2.204 -    int line() const { return _line; }
   2.205 -    ///\e
   2.206 -    const char* message() const { return _message; }
   2.207 -
   2.208 -    /// \brief Returns the filename.
   2.209 -    ///
   2.210 -    /// Returns \e "(unknown)" if the filename was not specified.
   2.211 -    const char* file() const {
   2.212 -      if( _file )
   2.213 -	return _file->c_str();
   2.214 -      else
   2.215 -	return "(unknown)";
   2.216 -    }
   2.217 -
   2.218 -    ///\e 
   2.219 -    virtual const char* what() const throw() {
   2.220 -      const char *mes = 0;
   2.221 -      try {
   2.222 -	std::ostringstream ostr;
   2.223 -	ostr << _message;
   2.224 -	if( _file || _line ) {
   2.225 -	  ostr << " (";
   2.226 -	  if( _file ) ostr << "in file '" << *_file << "'";
   2.227 -	  if( _file && _line ) ostr << " ";
   2.228 -	  if( _line ) ostr << "at line " << _line;
   2.229 -	  ostr << ")";
   2.230 -	}
   2.231 -	mes = ostr.str().c_str();
   2.232 -      }
   2.233 -      catch(...) {}
   2.234 -      if( mes ) return mes;
   2.235 -      return exceptionName();
   2.236 -    }
   2.237 -
   2.238 -    virtual const char* exceptionName() const {
   2.239 -      return "lemon::DataFormatError";
   2.240 -    }
   2.241 -
   2.242 -    virtual ~DataFormatError() throw() {}
   2.243 -  };
   2.244 -
   2.245 -
   2.246 -  ///\e
   2.247 -  class AssertionFailedError : public LogicError {
   2.248 -  protected:
   2.249 -    const char *assertion;
   2.250 -    const char *file;
   2.251 -    int line;
   2.252 -    const char *function;
   2.253 -    const char *message;
   2.254 -  public:
   2.255 -    ///\e
   2.256 -    AssertionFailedError(const char *_file, int _line, const char *func,
   2.257 -			 const char *msg, const char *_assertion = 0) :
   2.258 -      assertion(_assertion), file(_file), line(_line), function(func),
   2.259 -      message(msg) {}
   2.260 -
   2.261 -    ///\e
   2.262 -    const char* get_assertion() const { return assertion; }
   2.263 -    ///\e
   2.264 -    const char* get_message() const { return message; }
   2.265 -    ///\e
   2.266 -    const char* get_file() const { return file; }
   2.267 -    ///\e
   2.268 -    const char* get_function() const { return function; }
   2.269 -    ///\e
   2.270 -    int get_line() const { return line; }
   2.271 -
   2.272 -
   2.273 -    virtual const char* what() const throw() {
   2.274 -      const char *mes = 0;
   2.275 -      try {
   2.276 -	std::ostringstream ostr;
   2.277 -	ostr << file << ":" << line << ": ";
   2.278 -	if( function )
   2.279 -	  ostr << function << ": ";
   2.280 -	ostr << message;
   2.281 -	if( assertion )
   2.282 -	  ostr << " (assertion '" << assertion << "' failed)";
   2.283 -	mes = ostr.str().c_str();
   2.284 -      }
   2.285 -      catch(...) {}
   2.286 -      if( mes ) return mes;
   2.287 -      return exceptionName();
   2.288 -    }
   2.289 -
   2.290 -    virtual const char* exceptionName() const {
   2.291 -      return "lemon::AssertionFailedError";
   2.292 -    }
   2.293 -
   2.294 -    virtual ~AssertionFailedError() throw() {}
   2.295 -  };
   2.296 -
   2.297 -
   2.298 -  /****************  Macros  ****************/
   2.299 -
   2.300 -
   2.301 -  inline
   2.302 -  void assert_fail(const char *file, int line, const char *func,
   2.303 -		   const char *message, const char *assertion = 0,
   2.304 -		   bool do_abort=true)
   2.305 -  {
   2.306 -    using namespace std;
   2.307 -    cerr << file << ":" << line << ": ";
   2.308 -    if( func )
   2.309 -      cerr << func << ": ";
   2.310 -    cerr << message;
   2.311 -    if( assertion )
   2.312 -      cerr << " (assertion '" << assertion << "' failed)";
   2.313 -    cerr << endl;
   2.314 -    if(do_abort)
   2.315 -      abort();
   2.316 -  }
   2.317 -
   2.318 -  inline
   2.319 -  void assert_fail_throw(const char *file, int line, const char *func,
   2.320 -		   const char *message, const char *assertion = 0,
   2.321 -		   bool = true)
   2.322 -  {
   2.323 -    throw AssertionFailedError(file, line, func, message, assertion);
   2.324 -  }
   2.325 -
   2.326 -
   2.327 -}
   2.328 -#endif // LEMON_ERROR_H
   2.329 -
   2.330 -#undef LEMON_ASSERT
   2.331 -#undef LEMON_FIXME
   2.332 -
   2.333 -#ifndef LEMON_ASSERT_ABORT
   2.334 -#  define LEMON_ASSERT_ABORT 1
   2.335 -#endif
   2.336 -
   2.337 -#ifndef LEMON_ASSERT_HANDLER
   2.338 -#  ifdef LEMON_ASSERT_EXCEPTION
   2.339 -#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_throw
   2.340 -#  else
   2.341 -#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail
   2.342 -#  endif
   2.343 -#endif
   2.344 -
   2.345 -#if defined(NDEBUG) || defined(LEMON_DISABLE_ASSERTS)
   2.346 -
   2.347 -#  define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
   2.348 -
   2.349 -#else
   2.350 -
   2.351 -/**
   2.352 - * \brief Macro for assertions with customizable message
   2.353 - *
   2.354 - * Macro for assertions with customizable message.
   2.355 - *
   2.356 - * The behaviour can be customized with LEMON_ASSERT_HANDLER,
   2.357 - * LEMON_ASSERT_EXCEPTION and LEMON_ASSERT_ABORT defines. Asserts can be
   2.358 - * disabled by defining either NDEBUG or LEMON_DISABLE_ASSERTS macros.
   2.359 - *
   2.360 - * \todo We should provide some way to reset to the default behaviour,
   2.361 - * shouldn't we?
   2.362 - *
   2.363 - * \todo This whole 'assert' business should be placed in a separate
   2.364 - * include file.
   2.365 - *
   2.366 - * \todo __PRETTY_FUNCTION__ should be replaced by something
   2.367 - * compiler-independant, like BOOST_CURRENT_FUNCTION
   2.368 - */
   2.369 -
   2.370 -#  define LEMON_ASSERT(exp, msg)                 \
   2.371 -     (static_cast<void> (!!(exp) ? 0 : (         \
   2.372 -       LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
   2.373 -                            __PRETTY_FUNCTION__, \
   2.374 -			    (msg), #exp, LEMON_ASSERT_ABORT), 0)))
   2.375 -
   2.376 -#endif // NDEBUG || LEMON_DISABLE_ASSERTS
   2.377 -
   2.378 -/**
   2.379 - * \brief Macro for mark not yet implemented features.
   2.380 - *
   2.381 - * \todo Is this the right place for this? It should be used only in
   2.382 - * modules under development.
   2.383 - *
   2.384 - * \todo __PRETTY_FUNCTION__ should be replaced by something
   2.385 - * compiler-independant, like BOOST_CURRENT_FUNCTION
   2.386 - */
   2.387 -
   2.388 -# define LEMON_FIXME(msg) \
   2.389 -    (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
   2.390 -			  "FIXME: " msg))
     3.1 --- a/src/work/klao/error_test.cc	Thu Feb 03 19:27:10 2005 +0000
     3.2 +++ b/src/work/klao/error_test.cc	Thu Feb 03 19:31:37 2005 +0000
     3.3 @@ -2,7 +2,7 @@
     3.4  #include <string>
     3.5  
     3.6  #define LEMON_ASSERT_ABORT 0
     3.7 -#include <error.h>
     3.8 +#include <lemon/error.h>
     3.9  
    3.10  using namespace std;
    3.11  
    3.12 @@ -69,10 +69,8 @@
    3.13  #undef LEMON_ASSERT_HANDLER
    3.14  #define LEMON_ASSERT_EXCEPTION
    3.15  
    3.16 -#include <error.h>
    3.17 +#include <lemon/error.h>
    3.18  
    3.19  void fail_assert() {
    3.20    LEMON_ASSERT(2*2==5, "Marson vagyunk");
    3.21  }
    3.22 -
    3.23 -