diff -r 91f9236dfec9 -r 3996d2098090 src/lemon/error.h --- a/src/lemon/error.h Fri Feb 18 16:40:48 2005 +0000 +++ b/src/lemon/error.h Sat Feb 19 21:11:20 2005 +0000 @@ -1,8 +1,10 @@ /* -*- C++ -*- + * * src/lemon/error.h - Part of LEMON, a generic C++ optimization library * - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Combinatorial Optimization Research Group, EGRES). + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi + * Kutatocsoport (Egervary Combinatorial Optimization Research Group, + * EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For @@ -26,8 +28,7 @@ #include #include #include - -#include +#include namespace lemon { @@ -42,7 +43,9 @@ class ErrorMessage { protected: ///\e - boost::shared_ptr buf; + ///\todo The good solution is boost:shared_ptr... + mutable + std::auto_ptr buf; ///\e bool init() throw() { @@ -52,7 +55,7 @@ catch(...) { buf.reset(); } - return buf; + return buf.get(); } public: @@ -60,6 +63,8 @@ ///\e ErrorMessage() throw() { init(); } + ErrorMessage(const ErrorMessage& em) throw() : buf(em.buf) { } + ///\e ErrorMessage(const char *message) throw() { init(); @@ -75,7 +80,7 @@ ///\e template ErrorMessage& operator<<(const T &t) throw() { - if( !buf ) return *this; + if( ! buf.get() ) return *this; try { *buf << t; @@ -87,7 +92,7 @@ ///\e const char* message() throw() { - if( !buf ) return 0; + if( ! buf.get() ) return 0; const char* mes = 0; try { @@ -187,9 +192,17 @@ protected: const char *_message; int _line; - boost::shared_ptr _file; + + ///\todo Much better solution is boost::shared_ptr + mutable + std::auto_ptr _file; public: + + DataFormatError(const DataFormatError &dfe) : + IOError(dfe), _message(dfe._message), _line(dfe._line), + _file(dfe._file) {} + ///\e explicit DataFormatError(const char *the_message) : _message(the_message), _line(0) {} @@ -222,7 +235,7 @@ /// /// Returns \e "(unknown)" if the filename was not specified. const char* file() const { - if( _file ) + if( _file.get() ) return _file->c_str(); else return "(unknown)"; @@ -234,10 +247,10 @@ try { std::ostringstream ostr; ostr << _message; - if( _file || _line ) { + if( _file.get() || _line ) { ostr << " ("; - if( _file ) ostr << "in file '" << *_file << "'"; - if( _file && _line ) ostr << " "; + if( _file.get() ) ostr << "in file '" << *_file << "'"; + if( _file.get() && _line ) ostr << " "; if( _line ) ostr << "at line " << _line; ostr << ")"; }