X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.cc;h=8b2f2802c6e88020f79a9469ffa284fd0516b9e3;hb=62da0fc2f859a98e105b45859c346750a1435ebb;hp=cc87f615d59d9a89546b123d16f2498a0b7ee47f;hpb=553781d9e9bce316dca24ac4f0c42e5613e849e0;p=senf.git diff --git a/Utils/Exception.cc b/Utils/Exception.cc index cc87f61..8b2f280 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -1,9 +1,9 @@ // $Id$ // -// Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Copyright (C) 2006 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -27,28 +27,42 @@ //#include "Exception.ih" // Custom includes -#include -#include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -prefix_ void senf::SystemException::init() +prefix_ void senf::throwErrno(std::string const & where, int code) { - // We normallyl don't want to consume memory in an exception, - // however all other solutions to format the message are terribly - // ugly (since thay must use a static and shared buffer ...) - std::stringstream s; - if (where) - s << where << ": "; - s << "(" << err << ") " << std::strerror(err); - buffer_ = s.str(); -} +#ifndef SENF_NO_ERRNOEXC + switch (code) { -prefix_ char const * senf::SystemException::what() - const throw() -{ - return buffer_.c_str(); + // BOOST_PP_REPEAT is limited to 256 repetitions. The max errno value I found in any header file + // was somewhere around 530 or so. I assume going to 1024 will be good enough. This explicit + // code will be optimized into a jump table by g++ (which is more efficient than trying to do + // the table oneself) + +# define ExceptionCase(z, n, data) case n: throw ErrnoException(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + +# define ExceptionCase(z, n, data) case 256+n: throw ErrnoException<256+n>(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + +# define ExceptionCase(z, n, data) case 512+n: throw ErrnoException<512+n>(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + +# define ExceptionCase(z, n, data) case 768+n: throw ErrnoException<768+n>(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + + default: + throw SystemException(where, code); + } +#else + throw SystemException(where, code); +#endif } ///////////////////////////////cc.e//////////////////////////////////////// @@ -57,5 +71,10 @@ prefix_ char const * senf::SystemException::what() // Local Variables: // mode: c++ +// fill-column: 100 // c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: