Move sourcecode into 'senf/' directory
[senf.git] / senf / Utils / Exception.cci
diff --git a/senf/Utils/Exception.cci b/senf/Utils/Exception.cci
new file mode 100644 (file)
index 0000000..6f7e13d
--- /dev/null
@@ -0,0 +1,136 @@
+// $Id$
+//
+// Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
+//
+// 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
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief Exception inline non-template implementation */
+
+// Custom includes
+#include <errno.h>
+#include <cstring>
+
+#define prefix_ inline
+///////////////////////////////cci.p///////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::ExceptionMixin
+
+prefix_ senf::ExceptionMixin::ExceptionMixin(std::string const & description)
+    : what_(description)
+{
+#ifdef SENF_DEBUG
+    addBacktrace();
+#endif
+}
+
+prefix_ std::string senf::ExceptionMixin::message()
+    const
+{
+#ifdef SENF_DEBUG
+    return what_.substr(excLen_);
+#else
+    return what_;
+#endif
+}
+
+prefix_ std::string senf::ExceptionMixin::backtrace()
+    const
+{
+#ifdef SENF_DEBUG
+    return what_.substr(0,excLen_-4);
+#else
+    return "";
+#endif
+}
+
+prefix_ void senf::ExceptionMixin::append(std::string text)
+{
+    what_ += text;
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::Exception
+
+prefix_ senf::Exception::Exception(std::string const & description)
+    : ExceptionMixin(description)
+{}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::SystemException
+
+prefix_ senf::SystemException::SystemException(std::string const & descr _SENF_EXC_DEBUG_ARGS_ND)
+{
+    init(descr, errno _SENF_EXC_DEBUG_ARGS_P);
+}
+
+prefix_ senf::SystemException::SystemException(int code _SENF_EXC_DEBUG_ARGS_ND)
+{
+    init("", code _SENF_EXC_DEBUG_ARGS_P);
+}
+
+prefix_ senf::SystemException::SystemException(std::string const & descr, int code 
+                                               _SENF_EXC_DEBUG_ARGS_ND)
+{
+    init(descr, code _SENF_EXC_DEBUG_ARGS_P);
+}
+
+prefix_ int senf::SystemException::errorNumber()
+    const
+{
+    return code_;
+}
+
+prefix_ char const * senf::SystemException::errorString()
+    const
+{
+    return std::strerror(code_);
+}
+
+prefix_ bool senf::SystemException::anyOf(int c0, int c1, int c2, int c3, int c4, int c5,
+                                          int c6, int c7, int c8, int c9)
+{
+    return 
+        (c0 && code_ == c0) ||
+        (c1 && code_ == c1) ||
+        (c2 && code_ == c2) ||
+        (c3 && code_ == c3) ||
+        (c4 && code_ == c4) ||
+        (c5 && code_ == c5) ||
+        (c6 && code_ == c6) ||
+        (c7 && code_ == c7) ||
+        (c8 && code_ == c8) ||
+        (c9 && code_ == c9);
+}
+
+prefix_  senf::SystemException::~SystemException()
+    throw()
+{}
+
+///////////////////////////////cci.e///////////////////////////////////////
+#undef prefix_
+
+\f
+// 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: