////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP #define BOOST_CONTAINER_THROW_EXCEPTION_HPP #ifndef BOOST_CONFIG_HPP # include #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include #include #include #ifndef BOOST_NO_EXCEPTIONS #include //for std exception base # if defined(BOOST_CONTAINER_USE_STD_EXCEPTIONS) #include //for std exception types #include //for implicit std::string conversion #include //for std::bad_alloc typedef std::bad_alloc bad_alloc_t; typedef std::out_of_range out_of_range_t; typedef std::out_of_range length_error_t; typedef std::logic_error logic_error_t; typedef std::runtime_error runtime_error_t; # else //!BOOST_CONTAINER_USE_STD_EXCEPTIONS namespace boost { namespace container { class exception : public ::std::exception { typedef ::std::exception std_exception_t; public: //msg must be a static string (guaranteed by callers) explicit exception(const char *msg) : std_exception_t(), m_msg(msg) {} virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW { return m_msg ? m_msg : "unknown boost::container exception"; } private: const char *m_msg; }; class bad_alloc : public exception { public: bad_alloc() : exception("boost::container::bad_alloc thrown") {} }; typedef bad_alloc bad_alloc_t; class out_of_range : public exception { public: explicit out_of_range(const char *msg) : exception(msg) {} }; typedef out_of_range out_of_range_t; class length_error : public exception { public: explicit length_error(const char *msg) : exception(msg) {} }; typedef out_of_range length_error_t; class logic_error : public exception { public: explicit logic_error(const char *msg) : exception(msg) {} }; typedef logic_error logic_error_t; class runtime_error : public exception { public: explicit runtime_error(const char *msg) : exception(msg) {} }; typedef runtime_error runtime_error_t; } // namespace boost { } // namespace container { # endif #else #include #include //for std::abort #endif namespace boost { namespace container { #if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS) //The user must provide definitions for the following functions BOOST_NORETURN void throw_bad_alloc(); BOOST_NORETURN void throw_out_of_range(const char* str); BOOST_NORETURN void throw_length_error(const char* str); BOOST_NORETURN void throw_logic_error(const char* str); BOOST_NORETURN void throw_runtime_error(const char* str); #elif defined(BOOST_NO_EXCEPTIONS) BOOST_NORETURN inline void throw_bad_alloc() { BOOST_ASSERT(!"boost::container bad_alloc thrown"); std::abort(); } BOOST_NORETURN inline void throw_out_of_range(const char* str) { boost::ignore_unused(str); BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str); std::abort(); } BOOST_NORETURN inline void throw_length_error(const char* str) { boost::ignore_unused(str); BOOST_ASSERT_MSG(!"boost::container length_error thrown", str); std::abort(); } BOOST_NORETURN inline void throw_logic_error(const char* str) { boost::ignore_unused(str); BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str); std::abort(); } BOOST_NORETURN inline void throw_runtime_error(const char* str) { boost::ignore_unused(str); BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str); std::abort(); } #else //defined(BOOST_NO_EXCEPTIONS) //! Exception callback called by Boost.Container when fails to allocate the requested storage space. //!
    //!
  • If BOOST_NO_EXCEPTIONS is NOT defined std::bad_alloc() is thrown.
  • //! //!
  • If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS //! is NOT defined BOOST_ASSERT(!"boost::container bad_alloc thrown") is called //! and std::abort() if the former returns.
  • //! //!
  • If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined //! the user must provide an implementation and the function should not return.
  • //!
BOOST_NORETURN inline void throw_bad_alloc() { #ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS throw std::bad_alloc(); #else throw bad_alloc(); #endif } //! Exception callback called by Boost.Container to signal arguments out of range. //!
    //!
  • If BOOST_NO_EXCEPTIONS is NOT defined std::out_of_range(str) is thrown.
  • //! //!
  • If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS //! is NOT defined BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str) is called //! and std::abort() if the former returns.
  • //! //!
  • If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined //! the user must provide an implementation and the function should not return.
  • //!
BOOST_NORETURN inline void throw_out_of_range(const char* str) { #ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS throw std::out_of_range(str); #else throw out_of_range(str); #endif } //! Exception callback called by Boost.Container to signal errors resizing. //!
    //!
  • If BOOST_NO_EXCEPTIONS is NOT defined std::length_error(str) is thrown.
  • //! //!
  • If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS //! is NOT defined BOOST_ASSERT_MSG(!"boost::container length_error thrown", str) is called //! and std::abort() if the former returns.
  • //! //!
  • If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined //! the user must provide an implementation and the function should not return.
  • //!
BOOST_NORETURN inline void throw_length_error(const char* str) { #ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS throw std::length_error(str); #else throw length_error(str); #endif } //! Exception callback called by Boost.Container to report errors in the internal logical //! of the program, such as violation of logical preconditions or class invariants. //!
    //!
  • If BOOST_NO_EXCEPTIONS is NOT defined std::logic_error(str) is thrown.
  • //! //!
  • If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS //! is NOT defined BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str) is called //! and std::abort() if the former returns.
  • //! //!
  • If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined //! the user must provide an implementation and the function should not return.
  • //!
BOOST_NORETURN inline void throw_logic_error(const char* str) { #ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS throw std::logic_error(str); #else throw logic_error(str); #endif } //! Exception callback called by Boost.Container to report errors that can only be detected during runtime. //!
    //!
  • If BOOST_NO_EXCEPTIONS is NOT defined std::runtime_error(str) is thrown.
  • //! //!
  • If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS //! is NOT defined BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str) is called //! and std::abort() if the former returns.
  • //! //!
  • If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined //! the user must provide an implementation and the function should not return.
  • //!
BOOST_NORETURN inline void throw_runtime_error(const char* str) { #ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS throw std::runtime_error(str); #else throw runtime_error(str); #endif } #endif }} //namespace boost { namespace container { #include #endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP