1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
12 #define BOOST_CONTAINER_THROW_EXCEPTION_HPP
13 
14 #ifndef BOOST_CONFIG_HPP
15 #  include <boost/config.hpp>
16 #endif
17 
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 #  pragma once
20 #endif
21 
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24 
25 #ifndef BOOST_NO_EXCEPTIONS
26    #include <stdexcept> //for std exception types
27    #include <new>       //for std::bad_alloc
28 #else
29    #include <boost/assert.hpp>
30    #include <cstdlib>   //for std::abort
31 #endif
32 
33 namespace pdalboost {
34 namespace container {
35 
36 #if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
37    //The user must provide definitions for the following functions
38 
39    void throw_bad_alloc();
40 
41    void throw_out_of_range(const char* str);
42 
43    void throw_length_error(const char* str);
44 
45    void throw_logic_error(const char* str);
46 
47    void throw_runtime_error(const char* str);
48 
49 #elif defined(BOOST_NO_EXCEPTIONS)
50 
51    inline void throw_bad_alloc()
52    {
53       BOOST_ASSERT(!"pdalboost::container bad_alloc thrown");
54       std::abort();
55    }
56 
57    inline void throw_out_of_range(const char* str)
58    {
59       BOOST_ASSERT_MSG(!"pdalboost::container out_of_range thrown", str);
60       std::abort();
61    }
62 
63    inline void throw_length_error(const char* str)
64    {
65       BOOST_ASSERT_MSG(!"pdalboost::container length_error thrown", str);
66       std::abort();
67    }
68 
69    inline void throw_logic_error(const char* str)
70    {
71       BOOST_ASSERT_MSG(!"pdalboost::container logic_error thrown", str);
72       std::abort();
73    }
74 
75    inline void throw_runtime_error(const char* str)
76    {
77       BOOST_ASSERT_MSG(!"pdalboost::container runtime_error thrown", str);
78       std::abort();
79    }
80 
81 #else //defined(BOOST_NO_EXCEPTIONS)
82 
83    //! Exception callback called by Boost.Container when fails to allocate the requested storage space.
84    //! <ul>
85    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::bad_alloc()</code> is thrown.</li>
86    //!
87    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
88    //!   is NOT defined <code>BOOST_ASSERT(!"pdalboost::container bad_alloc thrown")</code> is called
89    //!   and <code>std::abort()</code> if the former returns.</li>
90    //!
91    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
92    //!   the user must provide an implementation and the function should not return.</li>
93    //! </ul>
94    inline void throw_bad_alloc()
95    {
96       throw std::bad_alloc();
97    }
98 
99    //! Exception callback called by Boost.Container to signal arguments out of range.
100    //! <ul>
101    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::out_of_range(str)</code> is thrown.</li>
102    //!
103    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
104    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"pdalboost::container out_of_range thrown", str)</code> is called
105    //!   and <code>std::abort()</code> if the former returns.</li>
106    //!
107    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
108    //!   the user must provide an implementation and the function should not return.</li>
109    //! </ul>
110    inline void throw_out_of_range(const char* str)
111    {
112       throw std::out_of_range(str);
113    }
114 
115    //! Exception callback called by Boost.Container to signal errors resizing.
116    //! <ul>
117    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::length_error(str)</code> is thrown.</li>
118    //!
119    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
120    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"pdalboost::container length_error thrown", str)</code> is called
121    //!   and <code>std::abort()</code> if the former returns.</li>
122    //!
123    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
124    //!   the user must provide an implementation and the function should not return.</li>
125    //! </ul>
126    inline void throw_length_error(const char* str)
127    {
128       throw std::length_error(str);
129    }
130 
131    //! Exception callback called by Boost.Container  to report errors in the internal logical
132    //! of the program, such as violation of logical preconditions or class invariants.
133    //! <ul>
134    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::logic_error(str)</code> is thrown.</li>
135    //!
136    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
137    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"pdalboost::container logic_error thrown", str)</code> is called
138    //!   and <code>std::abort()</code> if the former returns.</li>
139    //!
140    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
141    //!   the user must provide an implementation and the function should not return.</li>
142    //! </ul>
143    inline void throw_logic_error(const char* str)
144    {
145       throw std::logic_error(str);
146    }
147 
148    //! Exception callback called by Boost.Container  to report errors that can only be detected during runtime.
149    //! <ul>
150    //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::runtime_error(str)</code> is thrown.</li>
151    //!
152    //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
153    //!   is NOT defined <code>BOOST_ASSERT_MSG(!"pdalboost::container runtime_error thrown", str)</code> is called
154    //!   and <code>std::abort()</code> if the former returns.</li>
155    //!
156    //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
157    //!   the user must provide an implementation and the function should not return.</li>
158    //! </ul>
159    inline void throw_runtime_error(const char* str)
160    {
161       throw std::runtime_error(str);
162    }
163 
164 #endif
165 
166 }}  //namespace pdalboost { namespace container {
167 
168 #include <boost/container/detail/config_end.hpp>
169 
170 #endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
171