sl@0
|
1 |
//
|
sl@0
|
2 |
// Copyright (c) 2000-2002
|
sl@0
|
3 |
// Joerg Walter, Mathias Koch
|
sl@0
|
4 |
//
|
sl@0
|
5 |
// Permission to use, copy, modify, distribute and sell this software
|
sl@0
|
6 |
// and its documentation for any purpose is hereby granted without fee,
|
sl@0
|
7 |
// provided that the above copyright notice appear in all copies and
|
sl@0
|
8 |
// that both that copyright notice and this permission notice appear
|
sl@0
|
9 |
// in supporting documentation. The authors make no representations
|
sl@0
|
10 |
// about the suitability of this software for any purpose.
|
sl@0
|
11 |
// It is provided "as is" without express or implied warranty.
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// The authors gratefully acknowledge the support of
|
sl@0
|
14 |
// GeNeSys mbH & Co. KG in producing this work.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
|
sl@0
|
17 |
#ifndef _BOOST_UBLAS_EXCEPTION_
|
sl@0
|
18 |
#define _BOOST_UBLAS_EXCEPTION_
|
sl@0
|
19 |
|
sl@0
|
20 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
21 |
#include <stdexcept>
|
sl@0
|
22 |
#else
|
sl@0
|
23 |
#include <cstdlib>
|
sl@0
|
24 |
#endif
|
sl@0
|
25 |
#ifndef BOOST_UBLAS_NO_STD_CERR
|
sl@0
|
26 |
#include <iostream>
|
sl@0
|
27 |
#endif
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <boost/numeric/ublas/detail/config.hpp>
|
sl@0
|
30 |
|
sl@0
|
31 |
namespace boost { namespace numeric { namespace ublas {
|
sl@0
|
32 |
|
sl@0
|
33 |
struct divide_by_zero
|
sl@0
|
34 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
35 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
36 |
: public std::runtime_error {
|
sl@0
|
37 |
explicit divide_by_zero (const char *s = "divide by zero") :
|
sl@0
|
38 |
std::runtime_error (s) {}
|
sl@0
|
39 |
void raise () {
|
sl@0
|
40 |
throw *this;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
#else
|
sl@0
|
43 |
{
|
sl@0
|
44 |
divide_by_zero ()
|
sl@0
|
45 |
{}
|
sl@0
|
46 |
explicit divide_by_zero (const char *)
|
sl@0
|
47 |
{}
|
sl@0
|
48 |
void raise () {
|
sl@0
|
49 |
std::abort ();
|
sl@0
|
50 |
}
|
sl@0
|
51 |
#endif
|
sl@0
|
52 |
};
|
sl@0
|
53 |
|
sl@0
|
54 |
struct internal_logic
|
sl@0
|
55 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
56 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
57 |
: public std::logic_error {
|
sl@0
|
58 |
explicit internal_logic (const char *s = "internal logic") :
|
sl@0
|
59 |
std::logic_error (s) {}
|
sl@0
|
60 |
void raise () {
|
sl@0
|
61 |
throw *this;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
#else
|
sl@0
|
64 |
{
|
sl@0
|
65 |
internal_logic ()
|
sl@0
|
66 |
{}
|
sl@0
|
67 |
explicit internal_logic (const char *)
|
sl@0
|
68 |
{}
|
sl@0
|
69 |
void raise () {
|
sl@0
|
70 |
std::abort ();
|
sl@0
|
71 |
}
|
sl@0
|
72 |
#endif
|
sl@0
|
73 |
};
|
sl@0
|
74 |
|
sl@0
|
75 |
struct external_logic
|
sl@0
|
76 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
77 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
78 |
: public std::logic_error {
|
sl@0
|
79 |
explicit external_logic (const char *s = "external logic") :
|
sl@0
|
80 |
std::logic_error (s) {}
|
sl@0
|
81 |
// virtual const char *what () const throw () {
|
sl@0
|
82 |
// return "exception: external logic";
|
sl@0
|
83 |
// }
|
sl@0
|
84 |
void raise () {
|
sl@0
|
85 |
throw *this;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
#else
|
sl@0
|
88 |
{
|
sl@0
|
89 |
external_logic ()
|
sl@0
|
90 |
{}
|
sl@0
|
91 |
explicit external_logic (const char *)
|
sl@0
|
92 |
{}
|
sl@0
|
93 |
void raise () {
|
sl@0
|
94 |
std::abort ();
|
sl@0
|
95 |
}
|
sl@0
|
96 |
#endif
|
sl@0
|
97 |
};
|
sl@0
|
98 |
|
sl@0
|
99 |
struct bad_argument
|
sl@0
|
100 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
101 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
102 |
: public std::invalid_argument {
|
sl@0
|
103 |
explicit bad_argument (const char *s = "bad argument") :
|
sl@0
|
104 |
std::invalid_argument (s) {}
|
sl@0
|
105 |
void raise () {
|
sl@0
|
106 |
throw *this;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
#else
|
sl@0
|
109 |
{
|
sl@0
|
110 |
bad_argument ()
|
sl@0
|
111 |
{}
|
sl@0
|
112 |
explicit bad_argument (const char *)
|
sl@0
|
113 |
{}
|
sl@0
|
114 |
void raise () {
|
sl@0
|
115 |
std::abort ();
|
sl@0
|
116 |
}
|
sl@0
|
117 |
#endif
|
sl@0
|
118 |
};
|
sl@0
|
119 |
|
sl@0
|
120 |
struct bad_size
|
sl@0
|
121 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
122 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
123 |
: public std::domain_error {
|
sl@0
|
124 |
explicit bad_size (const char *s = "bad size") :
|
sl@0
|
125 |
std::domain_error (s) {}
|
sl@0
|
126 |
void raise () {
|
sl@0
|
127 |
throw *this;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
#else
|
sl@0
|
130 |
{
|
sl@0
|
131 |
bad_size ()
|
sl@0
|
132 |
{}
|
sl@0
|
133 |
explicit bad_size (const char *)
|
sl@0
|
134 |
{}
|
sl@0
|
135 |
void raise () {
|
sl@0
|
136 |
std::abort ();
|
sl@0
|
137 |
}
|
sl@0
|
138 |
#endif
|
sl@0
|
139 |
};
|
sl@0
|
140 |
|
sl@0
|
141 |
struct bad_index
|
sl@0
|
142 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
143 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
144 |
: public std::out_of_range {
|
sl@0
|
145 |
explicit bad_index (const char *s = "bad index") :
|
sl@0
|
146 |
std::out_of_range (s) {}
|
sl@0
|
147 |
void raise () {
|
sl@0
|
148 |
throw *this;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
#else
|
sl@0
|
151 |
{
|
sl@0
|
152 |
bad_index ()
|
sl@0
|
153 |
{}
|
sl@0
|
154 |
explicit bad_index (const char *)
|
sl@0
|
155 |
{}
|
sl@0
|
156 |
void raise () {
|
sl@0
|
157 |
std::abort ();
|
sl@0
|
158 |
}
|
sl@0
|
159 |
#endif
|
sl@0
|
160 |
};
|
sl@0
|
161 |
|
sl@0
|
162 |
struct singular
|
sl@0
|
163 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
164 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
165 |
: public std::runtime_error {
|
sl@0
|
166 |
explicit singular (const char *s = "singular") :
|
sl@0
|
167 |
std::runtime_error (s) {}
|
sl@0
|
168 |
void raise () {
|
sl@0
|
169 |
throw *this;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
#else
|
sl@0
|
172 |
{
|
sl@0
|
173 |
singular ()
|
sl@0
|
174 |
{}
|
sl@0
|
175 |
explicit singular (const char *)
|
sl@0
|
176 |
{}
|
sl@0
|
177 |
void raise () {
|
sl@0
|
178 |
throw *this;
|
sl@0
|
179 |
std::abort ();
|
sl@0
|
180 |
}
|
sl@0
|
181 |
#endif
|
sl@0
|
182 |
};
|
sl@0
|
183 |
|
sl@0
|
184 |
struct non_real
|
sl@0
|
185 |
#if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
|
sl@0
|
186 |
// Inherit from standard exceptions as requested during review.
|
sl@0
|
187 |
: public std::domain_error {
|
sl@0
|
188 |
explicit non_real (const char *s = "exception: non real") :
|
sl@0
|
189 |
std::domain_error (s) {}
|
sl@0
|
190 |
void raise () {
|
sl@0
|
191 |
throw *this;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
#else
|
sl@0
|
194 |
{
|
sl@0
|
195 |
non_real ()
|
sl@0
|
196 |
{}
|
sl@0
|
197 |
explicit non_real (const char *)
|
sl@0
|
198 |
{}
|
sl@0
|
199 |
void raise () {
|
sl@0
|
200 |
std::abort ();
|
sl@0
|
201 |
}
|
sl@0
|
202 |
#endif
|
sl@0
|
203 |
};
|
sl@0
|
204 |
|
sl@0
|
205 |
#if BOOST_UBLAS_CHECK_ENABLE
|
sl@0
|
206 |
// Macros are equivilent to
|
sl@0
|
207 |
// template<class E>
|
sl@0
|
208 |
// BOOST_UBLAS_INLINE
|
sl@0
|
209 |
// void check (bool expression, const E &e) {
|
sl@0
|
210 |
// if (! expression)
|
sl@0
|
211 |
// e.raise ();
|
sl@0
|
212 |
// }
|
sl@0
|
213 |
// template<class E>
|
sl@0
|
214 |
// BOOST_UBLAS_INLINE
|
sl@0
|
215 |
// void check_ex (bool expression, const char *file, int line, const E &e) {
|
sl@0
|
216 |
// if (! expression)
|
sl@0
|
217 |
// e.raise ();
|
sl@0
|
218 |
// }
|
sl@0
|
219 |
#ifndef BOOST_UBLAS_NO_STD_CERR
|
sl@0
|
220 |
#define BOOST_UBLAS_CHECK_FALSE(e) \
|
sl@0
|
221 |
std::cerr << "Check failed in file " << __FILE__ << " at line " << __LINE__ << ":" << std::endl; \
|
sl@0
|
222 |
e.raise ();
|
sl@0
|
223 |
#define BOOST_UBLAS_CHECK(expression, e) \
|
sl@0
|
224 |
if (! (expression)) { \
|
sl@0
|
225 |
std::cerr << "Check failed in file " << __FILE__ << " at line " << __LINE__ << ":" << std::endl; \
|
sl@0
|
226 |
std::cerr << #expression << std::endl; \
|
sl@0
|
227 |
e.raise (); \
|
sl@0
|
228 |
}
|
sl@0
|
229 |
#define BOOST_UBLAS_CHECK_EX(expression, file, line, e) \
|
sl@0
|
230 |
if (! (expression)) { \
|
sl@0
|
231 |
std::cerr << "Check failed in file " << (file) << " at line " << (line) << ":" << std::endl; \
|
sl@0
|
232 |
std::cerr << #expression << std::endl; \
|
sl@0
|
233 |
e.raise (); \
|
sl@0
|
234 |
}
|
sl@0
|
235 |
#else
|
sl@0
|
236 |
#define BOOST_UBLAS_CHECK_FALSE(e) \
|
sl@0
|
237 |
e.raise ();
|
sl@0
|
238 |
#define BOOST_UBLAS_CHECK(expression, e) \
|
sl@0
|
239 |
if (! (expression)) { \
|
sl@0
|
240 |
e.raise (); \
|
sl@0
|
241 |
}
|
sl@0
|
242 |
#define BOOST_UBLAS_CHECK_EX(expression, file, line, e) \
|
sl@0
|
243 |
if (! (expression)) { \
|
sl@0
|
244 |
e.raise (); \
|
sl@0
|
245 |
}
|
sl@0
|
246 |
#endif
|
sl@0
|
247 |
#else
|
sl@0
|
248 |
// Macros are equivilent to
|
sl@0
|
249 |
// template<class E>
|
sl@0
|
250 |
// BOOST_UBLAS_INLINE
|
sl@0
|
251 |
// void check (bool expression, const E &e) {}
|
sl@0
|
252 |
// template<class E>
|
sl@0
|
253 |
// BOOST_UBLAS_INLINE
|
sl@0
|
254 |
// void check_ex (bool expression, const char *file, int line, const E &e) {}
|
sl@0
|
255 |
#define BOOST_UBLAS_CHECK_FALSE(e)
|
sl@0
|
256 |
#define BOOST_UBLAS_CHECK(expression, e)
|
sl@0
|
257 |
#define BOOST_UBLAS_CHECK_EX(expression, file, line, e)
|
sl@0
|
258 |
#endif
|
sl@0
|
259 |
|
sl@0
|
260 |
|
sl@0
|
261 |
#ifndef BOOST_UBLAS_USE_FAST_SAME
|
sl@0
|
262 |
// Macro is equivilent to
|
sl@0
|
263 |
// template<class T>
|
sl@0
|
264 |
// BOOST_UBLAS_INLINE
|
sl@0
|
265 |
// const T &same_impl (const T &size1, const T &size2) {
|
sl@0
|
266 |
// BOOST_UBLAS_CHECK (size1 == size2, bad_argument ());
|
sl@0
|
267 |
// return (std::min) (size1, size2);
|
sl@0
|
268 |
// }
|
sl@0
|
269 |
// #define BOOST_UBLAS_SAME(size1, size2) same_impl ((size1), (size2))
|
sl@0
|
270 |
template<class T>
|
sl@0
|
271 |
BOOST_UBLAS_INLINE
|
sl@0
|
272 |
// Kresimir Fresl and Dan Muller reported problems with COMO.
|
sl@0
|
273 |
// We better change the signature instead of libcomo ;-)
|
sl@0
|
274 |
// const T &same_impl_ex (const T &size1, const T &size2, const char *file, int line) {
|
sl@0
|
275 |
T same_impl_ex (const T &size1, const T &size2, const char *file, int line) {
|
sl@0
|
276 |
BOOST_UBLAS_CHECK_EX (size1 == size2, file, line, bad_argument ());
|
sl@0
|
277 |
return (std::min) (size1, size2);
|
sl@0
|
278 |
}
|
sl@0
|
279 |
#define BOOST_UBLAS_SAME(size1, size2) same_impl_ex ((size1), (size2), __FILE__, __LINE__)
|
sl@0
|
280 |
#else
|
sl@0
|
281 |
// Macros are equivilent to
|
sl@0
|
282 |
// template<class T>
|
sl@0
|
283 |
// BOOST_UBLAS_INLINE
|
sl@0
|
284 |
// const T &same_impl (const T &size1, const T &size2) {
|
sl@0
|
285 |
// return size1;
|
sl@0
|
286 |
// }
|
sl@0
|
287 |
// #define BOOST_UBLAS_SAME(size1, size2) same_impl ((size1), (size2))
|
sl@0
|
288 |
#define BOOST_UBLAS_SAME(size1, size2) (size1)
|
sl@0
|
289 |
#endif
|
sl@0
|
290 |
|
sl@0
|
291 |
}}}
|
sl@0
|
292 |
|
sl@0
|
293 |
#endif
|