switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Exception.cci
1 // $Id$
2 //
3 // Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
4 //
5 // The contents of this file are subject to the Fraunhofer FOKUS Public License
6 // Version 1.0 (the "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at 
8 // http://senf.berlios.de/license.html
9 //
10 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
11 // but modifies the Mozilla Public License Version 1.1.
12 // See the full license text for the amendments.
13 //
14 // Software distributed under the License is distributed on an "AS IS" basis, 
15 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
16 // for the specific language governing rights and limitations under the License.
17 //
18 // The Original Code is Fraunhofer FOKUS code.
19 //
20 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
21 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
22 // All Rights Reserved.
23 //
24 // Contributor(s):
25
26 /** \file
27     \brief Exception inline non-template implementation */
28
29 // Custom includes
30 #include <errno.h>
31 #include <cstring>
32
33 #define prefix_ inline
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37 // senf::ExceptionMixin
38
39 prefix_ senf::ExceptionMixin::ExceptionMixin(std::string const & description)
40     : what_(description)
41 {
42 #ifdef SENF_BACKTRACE
43     addBacktrace();
44 #endif
45 }
46
47 prefix_ std::string senf::ExceptionMixin::message()
48     const
49 {
50 #ifdef SENF_DEBUG
51     return what_.substr(excLen_);
52 #else
53     return what_;
54 #endif
55 }
56
57 prefix_ std::string senf::ExceptionMixin::backtrace()
58     const
59 {
60 #ifdef SENF_DEBUG
61     return what_.substr(0,excLen_-4);
62 #else
63     return "";
64 #endif
65 }
66
67 prefix_ void senf::ExceptionMixin::append(std::string text)
68 {
69     what_ += text;
70 }
71
72 //-/////////////////////////////////////////////////////////////////////////////////////////////////
73 // senf::Exception
74
75 prefix_ senf::Exception::Exception(std::string const & description)
76     : ExceptionMixin(description)
77 {}
78
79 //-/////////////////////////////////////////////////////////////////////////////////////////////////
80 // senf::SystemException
81
82 prefix_ senf::SystemException::SystemException(std::string const & descr _SENF_EXC_DEBUG_ARGS_ND)
83 {
84     init(descr, errno _SENF_EXC_DEBUG_ARGS_P);
85 }
86
87 prefix_ senf::SystemException::SystemException(int code _SENF_EXC_DEBUG_ARGS_ND)
88 {
89     init("", code _SENF_EXC_DEBUG_ARGS_P);
90 }
91
92 prefix_ senf::SystemException::SystemException(std::string const & descr, int code
93                                                _SENF_EXC_DEBUG_ARGS_ND)
94 {
95     init(descr, code _SENF_EXC_DEBUG_ARGS_P);
96 }
97
98 prefix_ int senf::SystemException::errorNumber()
99     const
100 {
101     return code_;
102 }
103
104 prefix_ char const * senf::SystemException::errorString()
105     const
106 {
107     return std::strerror(code_);
108 }
109
110 prefix_ bool senf::SystemException::anyOf(int c0, int c1, int c2, int c3, int c4, int c5,
111                                           int c6, int c7, int c8, int c9)
112     const
113 {
114     return
115         (c0 && code_ == c0) ||
116         (c1 && code_ == c1) ||
117         (c2 && code_ == c2) ||
118         (c3 && code_ == c3) ||
119         (c4 && code_ == c4) ||
120         (c5 && code_ == c5) ||
121         (c6 && code_ == c6) ||
122         (c7 && code_ == c7) ||
123         (c8 && code_ == c8) ||
124         (c9 && code_ == c9);
125 }
126
127 prefix_  senf::SystemException::~SystemException()
128     throw()
129 {}
130
131 //-/////////////////////////////////////////////////////////////////////////////////////////////////
132 #undef prefix_
133
134 \f
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // comment-column: 40
143 // End: