9903becd7037329f25382d27b2505ed49b100450
[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 prefix_ senf::SystemException::SystemException()
31     : where_(0), code_(errno)
32 {
33     init();
34 }
35
36 prefix_  senf::SystemException::SystemException(int code)
37     : where_(0), code_(code)
38 {
39     init();
40 }
41
42 prefix_ senf::SystemException::SystemException(char const * where)
43     : where_(where), code_(errno)
44 {
45     init();
46 }
47
48 prefix_ senf::SystemException::SystemException(char const * where, int code)
49     : where_(where), code_(code)
50 {
51     init();
52 }
53
54 prefix_ char const * senf::SystemException::what()
55     const throw()
56 {
57     return buffer_.c_str();
58 }
59
60 prefix_ char const * senf::SystemException::where()
61     const
62 {
63     return where_;
64 }
65
66 prefix_ int senf::SystemException::code()
67     const
68 {
69     return code_;
70 }
71
72 prefix_ char const * senf::SystemException::description()
73     const
74 {
75     return std::strerror(code_);
76 }
77
78 prefix_ bool senf::SystemException::anyOf(int c0, int c1, int c2, int c3, int c4, int c5,
79                                           int c6, int c7, int c8, int c9)
80 {
81     return 
82         (c0 && code_ == c0) ||
83         (c1 && code_ == c1) ||
84         (c2 && code_ == c2) ||
85         (c3 && code_ == c3) ||
86         (c4 && code_ == c4) ||
87         (c5 && code_ == c5) ||
88         (c6 && code_ == c6) ||
89         (c7 && code_ == c7) ||
90         (c8 && code_ == c8) ||
91         (c9 && code_ == c9);
92 }
93
94 prefix_  senf::SystemException::~SystemException()
95     throw()
96 {}
97
98 prefix_ void senf::throwErrno()
99 {
100     throwErrno(0, errno);
101 }
102
103 prefix_ void senf::throwErrno(char const * where)
104 {
105     throwErrno(where, errno);
106 }
107
108 prefix_ void senf::throwErrno(int code)
109 {
110     throwErrno(0, code);
111 }
112
113 ///////////////////////////////cci.e///////////////////////////////////////
114 #undef prefix_
115
116 \f
117 // Local Variables:
118 // mode: c++
119 // fill-column: 100
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"
124 // comment-column: 40
125 // End: