Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:04

0001 //  Copyright (c) 2000-2011 Joerg Walter, Mathias Koch, David Bellot
0002 //
0003 //  Distributed under the Boost Software License, Version 1.0. (See
0004 //  accompanying file LICENSE_1_0.txt or copy at
0005 //  http://www.boost.org/LICENSE_1_0.txt)
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     /** \brief Exception raised when a division by zero occurs
0024      */
0025     struct divide_by_zero
0026 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0027         // Inherit from standard exceptions as requested during review.
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     /** \brief Expception raised when some interal errors occurs like computations errors, zeros values where you should not have zeros, etc...
0048      */
0049     struct internal_logic
0050 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
0051         // Inherit from standard exceptions as requested during review.
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         // Inherit from standard exceptions as requested during review.
0073         : public std::logic_error {
0074         explicit external_logic (const char *s = "external logic") :
0075             std::logic_error (s) {}
0076         // virtual const char *what () const throw () {
0077         //     return "exception: external logic";
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         // Inherit from standard exceptions as requested during review.
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         // Inherit from standard exceptions as requested during review.
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         // Inherit from standard exceptions as requested during review.
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         // Inherit from standard exceptions as requested during review.
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         // Inherit from standard exceptions as requested during review.
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 // Macros are equivilent to 
0203 //    template<class E>
0204 //    BOOST_UBLAS_INLINE
0205 //    void check (bool expression, const E &e) {
0206 //        if (! expression)
0207 //            e.raise ();
0208 //    }
0209 //    template<class E>
0210 //    BOOST_UBLAS_INLINE
0211 //    void check_ex (bool expression, const char *file, int line, const E &e) {
0212 //        if (! expression)
0213 //            e.raise ();
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 // Macros are equivilent to 
0245 //    template<class E>
0246 //    BOOST_UBLAS_INLINE
0247 //    void check (bool expression, const E &e) {}
0248 //    template<class E>
0249 //    BOOST_UBLAS_INLINE
0250 //    void check_ex (bool expression, const char *file, int line, const E &e) {}
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 // Macro is equivilent to 
0259 //    template<class T>
0260 //    BOOST_UBLAS_INLINE
0261 //    const T &same_impl (const T &size1, const T &size2) {
0262 //        BOOST_UBLAS_CHECK (size1 == size2, bad_argument ());
0263 //        return (std::min) (size1, size2);
0264 //    }
0265 // #define BOOST_UBLAS_SAME(size1, size2) same_impl ((size1), (size2))
0266      // need two types here because different containers can have
0267      // different size_types (especially sparse types)
0268     template<class T1, class T2>
0269     BOOST_UBLAS_INLINE
0270     // Kresimir Fresl and Dan Muller reported problems with COMO.
0271     // We better change the signature instead of libcomo ;-)
0272     // const T &same_impl_ex (const T &size1, const T &size2, const char *file, int line) {
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 // Macros are equivilent to 
0286 //    template<class T>
0287 //    BOOST_UBLAS_INLINE
0288 //    const T &same_impl (const T &size1, const T &size2) {
0289 //        return size1;
0290 //    }
0291 // #define BOOST_UBLAS_SAME(size1, size2) same_impl ((size1), (size2))
0292 #define BOOST_UBLAS_SAME(size1, size2) (size1)
0293 #endif
0294 
0295 }}}
0296 
0297 #endif