File indexing completed on 2025-01-18 09:43:04
0001
0002
0003
0004
0005
0006
0007 #ifndef _BOOST_UBLAS_EXCEPTION_
0008 #define _BOOST_UBLAS_EXCEPTION_
0009
0010 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0011 #include <stdexcept>
0012 #else
0013 #include <cstdlib>
0014 #endif
0015 #ifndef BOOST_UBLAS_NO_STD_CERR
0016 #include <iostream>
0017 #endif
0018
0019 #include <boost/numeric/ublas/detail/config.hpp>
0020
0021 namespace boost { namespace numeric { namespace ublas {
0022
0023
0024
0025 struct divide_by_zero
0026 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0027
0028 : public std::runtime_error
0029 {
0030 explicit divide_by_zero (const char *s = "divide by zero") :
0031 std::runtime_error (s) {}
0032 void raise () {
0033 throw *this;
0034 }
0035 #else
0036 {
0037 divide_by_zero ()
0038 {}
0039 explicit divide_by_zero (const char *)
0040 {}
0041 void raise () {
0042 std::abort ();
0043 }
0044 #endif
0045 };
0046
0047
0048
0049 struct internal_logic
0050 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0051
0052 : public std::logic_error {
0053 explicit internal_logic (const char *s = "internal logic") :
0054 std::logic_error (s) {}
0055 void raise () {
0056 throw *this;
0057 }
0058 #else
0059 {
0060 internal_logic ()
0061 {}
0062 explicit internal_logic (const char *)
0063 {}
0064 void raise () {
0065 std::abort ();
0066 }
0067 #endif
0068 };
0069
0070 struct external_logic
0071 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0072
0073 : public std::logic_error {
0074 explicit external_logic (const char *s = "external logic") :
0075 std::logic_error (s) {}
0076
0077
0078
0079 void raise () {
0080 throw *this;
0081 }
0082 #else
0083 {
0084 external_logic ()
0085 {}
0086 explicit external_logic (const char *)
0087 {}
0088 void raise () {
0089 std::abort ();
0090 }
0091 #endif
0092 };
0093
0094 struct bad_argument
0095 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0096
0097 : public std::invalid_argument {
0098 explicit bad_argument (const char *s = "bad argument") :
0099 std::invalid_argument (s) {}
0100 void raise () {
0101 throw *this;
0102 }
0103 #else
0104 {
0105 bad_argument ()
0106 {}
0107 explicit bad_argument (const char *)
0108 {}
0109 void raise () {
0110 std::abort ();
0111 }
0112 #endif
0113 };
0114
0115
0116
0117 struct bad_size
0118 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0119
0120 : public std::domain_error {
0121 explicit bad_size (const char *s = "bad size") :
0122 std::domain_error (s) {}
0123 void raise () {
0124 throw *this;
0125 }
0126 #else
0127 {
0128 bad_size ()
0129 {}
0130 explicit bad_size (const char *)
0131 {}
0132 void raise () {
0133 std::abort ();
0134 }
0135 #endif
0136 };
0137
0138 struct bad_index
0139 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0140
0141 : public std::out_of_range {
0142 explicit bad_index (const char *s = "bad index") :
0143 std::out_of_range (s) {}
0144 void raise () {
0145 throw *this;
0146 }
0147 #else
0148 {
0149 bad_index ()
0150 {}
0151 explicit bad_index (const char *)
0152 {}
0153 void raise () {
0154 std::abort ();
0155 }
0156 #endif
0157 };
0158
0159 struct singular
0160 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0161
0162 : public std::runtime_error {
0163 explicit singular (const char *s = "singular") :
0164 std::runtime_error (s) {}
0165 void raise () {
0166 throw *this;
0167 }
0168 #else
0169 {
0170 singular ()
0171 {}
0172 explicit singular (const char *)
0173 {}
0174 void raise () {
0175 std::abort ();
0176 }
0177 #endif
0178 };
0179
0180 struct non_real
0181 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0182
0183 : public std::domain_error {
0184 explicit non_real (const char *s = "exception: non real") :
0185 std::domain_error (s) {}
0186 void raise () {
0187 throw *this;
0188 }
0189 #else
0190 {
0191 non_real ()
0192 {}
0193 explicit non_real (const char *)
0194 {}
0195 void raise () {
0196 std::abort ();
0197 }
0198 #endif
0199 };
0200
0201 #if BOOST_UBLAS_CHECK_ENABLE
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215 #ifndef BOOST_UBLAS_NO_STD_CERR
0216 #define BOOST_UBLAS_CHECK_FALSE(e) \
0217 std::cerr << "Check failed in file " << __FILE__ << " at line " << __LINE__ << ":" << std::endl; \
0218 e.raise ();
0219 #define BOOST_UBLAS_CHECK(expression, e) \
0220 if (! (expression)) { \
0221 std::cerr << "Check failed in file " << __FILE__ << " at line " << __LINE__ << ":" << std::endl; \
0222 std::cerr << #expression << std::endl; \
0223 e.raise (); \
0224 }
0225 #define BOOST_UBLAS_CHECK_EX(expression, file, line, e) \
0226 if (! (expression)) { \
0227 std::cerr << "Check failed in file " << (file) << " at line " << (line) << ":" << std::endl; \
0228 std::cerr << #expression << std::endl; \
0229 e.raise (); \
0230 }
0231 #else
0232 #define BOOST_UBLAS_CHECK_FALSE(e) \
0233 e.raise ();
0234 #define BOOST_UBLAS_CHECK(expression, e) \
0235 if (! (expression)) { \
0236 e.raise (); \
0237 }
0238 #define BOOST_UBLAS_CHECK_EX(expression, file, line, e) \
0239 if (! (expression)) { \
0240 e.raise (); \
0241 }
0242 #endif
0243 #else
0244
0245
0246
0247
0248
0249
0250
0251 #define BOOST_UBLAS_CHECK_FALSE(e)
0252 #define BOOST_UBLAS_CHECK(expression, e)
0253 #define BOOST_UBLAS_CHECK_EX(expression, file, line, e)
0254 #endif
0255
0256
0257 #ifndef BOOST_UBLAS_USE_FAST_SAME
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268 template<class T1, class T2>
0269 BOOST_UBLAS_INLINE
0270
0271
0272
0273 T1 same_impl_ex (const T1 &size1, const T2 &size2, const char *file, int line) {
0274 BOOST_UBLAS_CHECK_EX (size1 == size2, file, line, bad_argument ());
0275 return (size1 < size2)?(size1):(size2);
0276 }
0277 template<class T>
0278 BOOST_UBLAS_INLINE
0279 T same_impl_ex (const T &size1, const T &size2, const char *file, int line) {
0280 BOOST_UBLAS_CHECK_EX (size1 == size2, file, line, bad_argument ());
0281 return (std::min) (size1, size2);
0282 }
0283 #define BOOST_UBLAS_SAME(size1, size2) same_impl_ex ((size1), (size2), __FILE__, __LINE__)
0284 #else
0285
0286
0287
0288
0289
0290
0291
0292 #define BOOST_UBLAS_SAME(size1, size2) (size1)
0293 #endif
0294
0295 }}}
0296
0297 #endif