Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/container/throw_exception.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/container for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
0012 #define BOOST_CONTAINER_THROW_EXCEPTION_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/container/detail/config_begin.hpp>
0023 #include <boost/container/detail/workaround.hpp>
0024 
0025 #ifndef BOOST_NO_EXCEPTIONS
0026 #include <exception> //for std exception base
0027 
0028 #  if defined(BOOST_CONTAINER_USE_STD_EXCEPTIONS)
0029    #include <stdexcept> //for std::out_of_range, std::length_error, std::logic_error, std::runtime_error
0030    #include <string>    //for implicit std::string conversion
0031    #include <new>       //for std::bad_alloc
0032 
0033 namespace boost {
0034 namespace container {
0035 
0036 typedef std::bad_alloc bad_alloc_t;
0037 typedef std::out_of_range out_of_range_t;
0038 typedef std::length_error length_error_t;
0039 typedef std::logic_error logic_error_t;
0040 typedef std::runtime_error runtime_error_t;
0041 
0042 }} //namespace boost::container
0043 
0044 #  else //!BOOST_CONTAINER_USE_STD_EXCEPTIONS
0045 
0046 namespace boost {
0047 namespace container {
0048 
0049 class BOOST_SYMBOL_VISIBLE exception
0050    : public ::std::exception
0051 {
0052    typedef ::std::exception std_exception_t;
0053 
0054    public:
0055 
0056    //msg must be a static string (guaranteed by callers)
0057    explicit exception(const char *msg)
0058       : std_exception_t(), m_msg(msg)
0059    {}
0060 
0061    virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
0062    {  return m_msg ? m_msg : "unknown boost::container exception"; }
0063 
0064    private:
0065    const char *m_msg;
0066 };
0067 
0068 class BOOST_SYMBOL_VISIBLE bad_alloc
0069    : public exception
0070 {
0071    public:
0072    bad_alloc()
0073       : exception("boost::container::bad_alloc thrown")
0074    {}
0075 };
0076 
0077 typedef bad_alloc bad_alloc_t;
0078 
0079 class BOOST_SYMBOL_VISIBLE out_of_range
0080    : public exception
0081 {
0082    public:
0083    explicit out_of_range(const char *msg)
0084       : exception(msg)
0085    {}
0086 };
0087 
0088 typedef out_of_range out_of_range_t;
0089 
0090 class BOOST_SYMBOL_VISIBLE length_error
0091    : public exception
0092 {
0093    public:
0094    explicit length_error(const char *msg)
0095       : exception(msg)
0096    {}
0097 };
0098 
0099 typedef length_error length_error_t;
0100 
0101 class BOOST_SYMBOL_VISIBLE logic_error
0102    : public exception
0103 {
0104    public:
0105    explicit logic_error(const char *msg)
0106       : exception(msg)
0107    {}
0108 };
0109 
0110 typedef logic_error logic_error_t;
0111 
0112 class BOOST_SYMBOL_VISIBLE runtime_error
0113    : public exception
0114 {
0115    public:
0116    explicit runtime_error(const char *msg)
0117       : exception(msg)
0118    {}
0119 };
0120 
0121 typedef runtime_error runtime_error_t;
0122 
0123 }  // namespace boost {
0124 }  // namespace container {
0125 
0126 #  endif
0127 #else
0128    #include <boost/assert.hpp>
0129    #include <cstdlib>   //for std::abort
0130 #endif
0131 
0132 namespace boost {
0133 namespace container {
0134 
0135 #if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
0136    //The user must provide definitions for the following functions
0137 
0138    BOOST_NORETURN void throw_bad_alloc();
0139 
0140    BOOST_NORETURN void throw_out_of_range(const char* str);
0141 
0142    BOOST_NORETURN void throw_length_error(const char* str);
0143 
0144    BOOST_NORETURN void throw_logic_error(const char* str);
0145 
0146    BOOST_NORETURN void throw_runtime_error(const char* str);
0147 
0148 #elif defined(BOOST_NO_EXCEPTIONS)
0149 
0150    BOOST_NORETURN inline void throw_bad_alloc()
0151    {
0152       BOOST_ASSERT(!"boost::container bad_alloc thrown");
0153       std::abort();
0154    }
0155 
0156    BOOST_NORETURN inline void throw_out_of_range(const char* str)
0157    {
0158       boost::container::ignore(str);
0159       BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str);
0160       std::abort();
0161    }
0162 
0163    BOOST_NORETURN inline void throw_length_error(const char* str)
0164    {
0165       boost::container::ignore(str);
0166       BOOST_ASSERT_MSG(!"boost::container length_error thrown", str);
0167       std::abort();
0168    }
0169 
0170    BOOST_NORETURN inline void throw_logic_error(const char* str)
0171    {
0172       boost::container::ignore(str);
0173       BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str);
0174       std::abort();
0175    }
0176 
0177    BOOST_NORETURN inline void throw_runtime_error(const char* str)
0178    {
0179       boost::container::ignore(str);
0180       BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str);
0181       std::abort();
0182    }
0183 
0184 #else //defined(BOOST_NO_EXCEPTIONS)
0185 
0186    //! Exception callback called by Boost.Container when fails to allocate the requested storage space.
0187    //! <ul>
0188    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
0189    //!   <code>boost::container::bad_alloc(str)</code> is thrown.</li>
0190    //!
0191    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
0192    //!   <code>std::bad_alloc(str)</code> is thrown.</li>
0193    //!
0194    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
0195    //!   is NOT defined <code>BOOST_ASSERT(!"boost::container bad_alloc thrown")</code> is called
0196    //!   and <code>std::abort()</code> if the former returns.</li>
0197    //!
0198    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
0199    //!   the user must provide an implementation and the function should not return.</li>
0200    //! </ul>
0201    BOOST_NORETURN inline void throw_bad_alloc()
0202    {
0203       throw bad_alloc_t();
0204    }
0205 
0206    //! Exception callback called by Boost.Container to signal arguments out of range.
0207    //! <ul>
0208    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
0209    //!   <code>boost::container::out_of_range(str)</code> is thrown.</li>
0210    //!
0211    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
0212    //!   <code>std::out_of_range(str)</code> is thrown.</li>
0213    //!
0214    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
0215    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str)</code> is called
0216    //!   and <code>std::abort()</code> if the former returns.</li>
0217    //!
0218    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
0219    //!   the user must provide an implementation and the function should not return.</li>
0220    //! </ul>
0221    BOOST_NORETURN inline void throw_out_of_range(const char* str)
0222    {
0223       throw out_of_range_t(str);
0224    }
0225 
0226    //! Exception callback called by Boost.Container to signal errors resizing.
0227    //! <ul>
0228    //!
0229    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
0230    //!   <code>boost::container::length_error(str)</code> is thrown.</li>
0231    //!
0232    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
0233    //!   <code>std::length_error(str)</code> is thrown.</li>
0234    //!
0235    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
0236    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container length_error thrown", str)</code> is called
0237    //!   and <code>std::abort()</code> if the former returns.</li>
0238    //!
0239    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
0240    //!   the user must provide an implementation and the function should not return.</li>
0241    //! </ul>
0242    BOOST_NORETURN inline void throw_length_error(const char* str)
0243    {
0244       throw length_error_t(str);
0245    }
0246 
0247    //! Exception callback called by Boost.Container  to report errors in the internal logical
0248    //! of the program, such as violation of logical preconditions or class invariants.
0249    //! <ul>
0250    //!
0251    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
0252    //!   <code>boost::container::logic_error(str)</code> is thrown.</li>
0253    //!
0254    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
0255    //!   <code>std::logic_error(str)</code> is thrown.</li>
0256    //!
0257    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
0258    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str)</code> is called
0259    //!   and <code>std::abort()</code> if the former returns.</li>
0260    //!
0261    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
0262    //!   the user must provide an implementation and the function should not return.</li>
0263    //! </ul>
0264    BOOST_NORETURN inline void throw_logic_error(const char* str)
0265    {
0266       throw logic_error_t(str);
0267    }
0268 
0269    //! Exception callback called by Boost.Container  to report errors that can only be detected during runtime.
0270    //! <ul>
0271    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
0272    //!   <code>boost::container::runtime_error(str)</code> is thrown.</li>
0273    //!
0274    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
0275    //!   <code>std::runtime_error(str)</code> is thrown.</li>
0276    //!
0277    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
0278    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str)</code> is called
0279    //!   and <code>std::abort()</code> if the former returns.</li>
0280    //!
0281    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
0282    //!   the user must provide an implementation and the function should not return.</li>
0283    //! </ul>
0284    BOOST_NORETURN inline void throw_runtime_error(const char* str)
0285    {
0286       throw runtime_error_t(str);
0287    }
0288 
0289 #endif
0290 
0291 }}  //namespace boost { namespace container {
0292 
0293 #include <boost/container/detail/config_end.hpp>
0294 
0295 #endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP