Files

297 lines
10 KiB
C++

//////////////////////////////////////////////////////////////////////////////
//
// (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 ACTIV_BOOST_CONTAINER_THROW_EXCEPTION_HPP
#define ACTIV_BOOST_CONTAINER_THROW_EXCEPTION_HPP
#ifndef ACTIV_BOOST_CONFIG_HPP
# include <ActivBoost/config.hpp>
#endif
#if defined(ACTIV_BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <ActivBoost/container/detail/config_begin.hpp>
#include <ActivBoost/container/detail/workaround.hpp>
#include <ActivBoost/core/ignore_unused.hpp>
#ifndef ACTIV_BOOST_NO_EXCEPTIONS
#include <exception> //for std exception base
# if defined(ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS)
#include <stdexcept> //for std::out_of_range, std::length_error, std::logic_error, std::runtime_error
#include <string> //for implicit std::string conversion
#include <new> //for std::bad_alloc
namespace Boost {
namespace container {
typedef std::bad_alloc bad_alloc_t;
typedef std::out_of_range out_of_range_t;
typedef std::length_error length_error_t;
typedef std::logic_error logic_error_t;
typedef std::runtime_error runtime_error_t;
}} //namespace Boost::container
# else //!ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS
namespace Boost {
namespace container {
class ACTIV_BOOST_SYMBOL_VISIBLE 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 ACTIV_BOOST_NOEXCEPT_OR_NOTHROW
{ return m_msg ? m_msg : "unknown Boost::container exception"; }
private:
const char *m_msg;
};
class ACTIV_BOOST_SYMBOL_VISIBLE bad_alloc
: public exception
{
public:
bad_alloc()
: exception("Boost::container::bad_alloc thrown")
{}
};
typedef bad_alloc bad_alloc_t;
class ACTIV_BOOST_SYMBOL_VISIBLE out_of_range
: public exception
{
public:
explicit out_of_range(const char *msg)
: exception(msg)
{}
};
typedef out_of_range out_of_range_t;
class ACTIV_BOOST_SYMBOL_VISIBLE length_error
: public exception
{
public:
explicit length_error(const char *msg)
: exception(msg)
{}
};
typedef out_of_range length_error_t;
class ACTIV_BOOST_SYMBOL_VISIBLE logic_error
: public exception
{
public:
explicit logic_error(const char *msg)
: exception(msg)
{}
};
typedef logic_error logic_error_t;
class ACTIV_BOOST_SYMBOL_VISIBLE 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 <ActivBoost/assert.hpp>
#include <cstdlib> //for std::abort
#endif
namespace Boost {
namespace container {
#if defined(ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
//The user must provide definitions for the following functions
ACTIV_BOOST_NORETURN void throw_bad_alloc();
ACTIV_BOOST_NORETURN void throw_out_of_range(const char* str);
ACTIV_BOOST_NORETURN void throw_length_error(const char* str);
ACTIV_BOOST_NORETURN void throw_logic_error(const char* str);
ACTIV_BOOST_NORETURN void throw_runtime_error(const char* str);
#elif defined(ACTIV_BOOST_NO_EXCEPTIONS)
ACTIV_BOOST_NORETURN inline void throw_bad_alloc()
{
ACTIV_BOOST_ASSERT(!"Boost::container bad_alloc thrown");
std::abort();
}
ACTIV_BOOST_NORETURN inline void throw_out_of_range(const char* str)
{
Boost::ignore_unused(str);
ACTIV_BOOST_ASSERT_MSG(!"Boost::container out_of_range thrown", str);
std::abort();
}
ACTIV_BOOST_NORETURN inline void throw_length_error(const char* str)
{
Boost::ignore_unused(str);
ACTIV_BOOST_ASSERT_MSG(!"Boost::container length_error thrown", str);
std::abort();
}
ACTIV_BOOST_NORETURN inline void throw_logic_error(const char* str)
{
Boost::ignore_unused(str);
ACTIV_BOOST_ASSERT_MSG(!"Boost::container logic_error thrown", str);
std::abort();
}
ACTIV_BOOST_NORETURN inline void throw_runtime_error(const char* str)
{
Boost::ignore_unused(str);
ACTIV_BOOST_ASSERT_MSG(!"Boost::container runtime_error thrown", str);
std::abort();
}
#else //defined(ACTIV_BOOST_NO_EXCEPTIONS)
//! Exception callback called by Boost.Container when fails to allocate the requested storage space.
//! <ul>
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
//! <code>Boost::container::bad_alloc(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
//! <code>std::bad_alloc(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is defined and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
//! is NOT defined <code>ACTIV_BOOST_ASSERT(!"Boost::container bad_alloc thrown")</code> is called
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
ACTIV_BOOST_NORETURN inline void throw_bad_alloc()
{
throw bad_alloc_t();
}
//! Exception callback called by Boost.Container to signal arguments out of range.
//! <ul>
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
//! <code>Boost::container::out_of_range(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
//! <code>std::out_of_range(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is defined and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
//! is NOT defined <code>ACTIV_BOOST_ASSERT_MSG(!"Boost::container out_of_range thrown", str)</code> is called
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
ACTIV_BOOST_NORETURN inline void throw_out_of_range(const char* str)
{
throw out_of_range_t(str);
}
//! Exception callback called by Boost.Container to signal errors resizing.
//! <ul>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
//! <code>Boost::container::length_error(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
//! <code>std::length_error(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is defined and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
//! is NOT defined <code>ACTIV_BOOST_ASSERT_MSG(!"Boost::container length_error thrown", str)</code> is called
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
ACTIV_BOOST_NORETURN inline void throw_length_error(const char* str)
{
throw length_error_t(str);
}
//! 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.
//! <ul>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
//! <code>Boost::container::logic_error(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
//! <code>std::logic_error(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is defined and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
//! is NOT defined <code>ACTIV_BOOST_ASSERT_MSG(!"Boost::container logic_error thrown", str)</code> is called
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
ACTIV_BOOST_NORETURN inline void throw_logic_error(const char* str)
{
throw logic_error_t(str);
}
//! Exception callback called by Boost.Container to report errors that can only be detected during runtime.
//! <ul>
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
//! <code>Boost::container::runtime_error(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is NOT defined and ACTIV_BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
//! <code>std::runtime_error(str)</code> is thrown.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS is defined and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
//! is NOT defined <code>ACTIV_BOOST_ASSERT_MSG(!"Boost::container runtime_error thrown", str)</code> is called
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If ACTIV_BOOST_NO_EXCEPTIONS and ACTIV_BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
ACTIV_BOOST_NORETURN inline void throw_runtime_error(const char* str)
{
throw runtime_error_t(str);
}
#endif
}} //namespace Boost { namespace container {
#include <ActivBoost/container/detail/config_end.hpp>
#endif //#ifndef ACTIV_BOOST_CONTAINER_THROW_EXCEPTION_HPP