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