Packets: Add StringParser ostream operation
[senf.git] / Utils / Exception.cci
1 // $Id$
2 //
3 // Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the
17 // Free Software Foundation, Inc.,
18 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 /** \file
21     \brief Exception inline non-template implementation */
22
23 // Custom includes
24 #include <errno.h>
25 #include <cstring>
26
27 #define prefix_ inline
28 ///////////////////////////////cci.p///////////////////////////////////////
29
30 ///////////////////////////////////////////////////////////////////////////
31 // senf::ExceptionMixin
32
33 prefix_ senf::ExceptionMixin::ExceptionMixin(std::string const & description)
34     : what_(description),
35       message_(description)
36 {
37 #ifdef SENF_DEBUG
38     addBacktrace();
39 #endif
40 }
41
42 prefix_ std::string const & senf::ExceptionMixin::message()
43     const
44 {
45     return message_;
46 }
47
48 prefix_ void senf::ExceptionMixin::append(std::string text)
49 {
50     message_ += text;
51     what_ += text;
52 }
53
54 ///////////////////////////////////////////////////////////////////////////
55 // senf::Exception
56
57 prefix_ senf::Exception::Exception(std::string const & description)
58     : ExceptionMixin(description)
59 {}
60
61 ///////////////////////////////////////////////////////////////////////////
62 // senf::SystemException
63
64 prefix_ senf::SystemException::SystemException(std::string const & descr _SENF_EXC_DEBUG_ARGS_ND)
65 {
66     init(descr, errno _SENF_EXC_DEBUG_ARGS_P);
67 }
68
69 prefix_ senf::SystemException::SystemException(int code _SENF_EXC_DEBUG_ARGS_ND)
70 {
71     init("", code _SENF_EXC_DEBUG_ARGS_P);
72 }
73
74 prefix_ senf::SystemException::SystemException(std::string const & descr, int code 
75                                                _SENF_EXC_DEBUG_ARGS_ND)
76 {
77     init(descr, code _SENF_EXC_DEBUG_ARGS_P);
78 }
79
80 prefix_ int senf::SystemException::errorNumber()
81     const
82 {
83     return code_;
84 }
85
86 prefix_ char const * senf::SystemException::errorString()
87     const
88 {
89     return std::strerror(code_);
90 }
91
92 prefix_ bool senf::SystemException::anyOf(int c0, int c1, int c2, int c3, int c4, int c5,
93                                           int c6, int c7, int c8, int c9)
94 {
95     return 
96         (c0 && code_ == c0) ||
97         (c1 && code_ == c1) ||
98         (c2 && code_ == c2) ||
99         (c3 && code_ == c3) ||
100         (c4 && code_ == c4) ||
101         (c5 && code_ == c5) ||
102         (c6 && code_ == c6) ||
103         (c7 && code_ == c7) ||
104         (c8 && code_ == c8) ||
105         (c9 && code_ == c9);
106 }
107
108 prefix_  senf::SystemException::~SystemException()
109     throw()
110 {}
111
112 ///////////////////////////////cci.e///////////////////////////////////////
113 #undef prefix_
114
115 \f
116 // Local Variables:
117 // mode: c++
118 // fill-column: 100
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"
123 // comment-column: 40
124 // End: