diff -r 2d6c8075d9d0 -r 818510fa3d99 src/lemon/attic/error.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lemon/attic/error.h Wed Sep 29 15:30:04 2004 +0000 @@ -0,0 +1,82 @@ +/* -*- 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). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_ERROR_H +#define LEMON_ERROR_H + +//! \ingroup misc +//! \file +//! \brief Basic error handling (signaling) routines. + +#include +#include +#include + + +namespace lemon { + + /** + * \brief Generic exception class. + * + * \todo Do we need this? + * + * \todo Don't we need different kind of exceptions for different kind + * of errors? + * Shouldn't we use \ instead? + */ + class Exception : public std::exception { + protected: + std::ostringstream buf; + public: + Exception() {} + explicit Exception(const std::string &s) { buf << s; } + Exception(const Exception &e) : std::exception() { + buf << e.buf.str(); + } + virtual ~Exception() throw() {} + + virtual const char* what() const throw() { + return buf.str().c_str(); + } + + Exception& operator<<(std::string const& s) { buf << s; return *this; } + Exception& operator<<(char const *s) { buf << s; return *this; } + Exception& operator<<(int i) { buf << i; return *this; } + }; + + /** + * \brief Generic error signaling function. + * + * \todo Do we really need this? Is it helpful? + */ + inline void fault(const std::string &msg) { + throw Exception(msg); + } + + /** + * \brief Macro for mark not yet implemented features. + * + * \todo Is this the right place for this? It should be used only in + * modules under development. + */ + +# define FIXME(msg) \ + do { throw ::lemon::Exception() << "FIXME: " msg " (in: " \ + __FILE__ ", " << __LINE__ << ")"; \ + } while(false) + +} +#endif // LEMON_ERROR_H