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 <string>    //for implicit std::string conversion
28   	   #include <new>       //for std::bad_alloc
29   	#else
30   	   #include <boost/assert.hpp>
31   	   #include <cstdlib>   //for std::abort
32   	#endif
33   	
34   	namespace boost {
35   	namespace container {
36   	
37   	#if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
38   	   //The user must provide definitions for the following functions
39   	
40   	   void throw_bad_alloc();
41   	
42   	   void throw_out_of_range(const char* str);
43   	
44   	   void throw_length_error(const char* str);
45   	
46   	   void throw_logic_error(const char* str);
47   	
48   	   void throw_runtime_error(const char* str);
49   	
50   	#elif defined(BOOST_NO_EXCEPTIONS)
51   	
52   	   inline void throw_bad_alloc()
53   	   {
54   	      const char msg[] = "boost::container bad_alloc thrown";
55   	      (void)msg;
56   	      BOOST_ASSERT(!msg);
57   	      std::abort();
58   	   }
59   	
60   	   inline void throw_out_of_range(const char* str)
61   	   {
62   	      const char msg[] = "boost::container out_of_range thrown";
63   	      (void)msg; (void)str;
64   	      BOOST_ASSERT_MSG(!msg, str);
65   	      std::abort();
66   	   }
67   	
68   	   inline void throw_length_error(const char* str)
69   	   {
70   	      const char msg[] = "boost::container length_error thrown";
71   	      (void)msg; (void)str;
72   	      BOOST_ASSERT_MSG(!msg, str);
73   	      std::abort();
74   	   }
75   	
76   	   inline void throw_logic_error(const char* str)
77   	   {
78   	      const char msg[] = "boost::container logic_error thrown";
79   	      (void)msg; (void)str;
80   	      BOOST_ASSERT_MSG(!msg, str);
81   	      std::abort();
82   	   }
83   	
84   	   inline void throw_runtime_error(const char* str)
85   	   {
86   	      const char msg[] = "boost::container runtime_error thrown";
87   	      (void)msg; (void)str;
88   	      BOOST_ASSERT_MSG(!msg, str);
89   	      std::abort();
90   	   }
91   	
92   	#else //defined(BOOST_NO_EXCEPTIONS)
93   	
94   	   //! Exception callback called by Boost.Container when fails to allocate the requested storage space.
95   	   //! <ul>
96   	   //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::bad_alloc()</code> is thrown.</li>
97   	   //!
98   	   //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
99   	   //!   is NOT defined <code>BOOST_ASSERT(!"boost::container bad_alloc thrown")</code> is called
100  	   //!   and <code>std::abort()</code> if the former returns.</li>
101  	   //!
102  	   //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
103  	   //!   the user must provide an implementation and the function should not return.</li>
104  	   //! </ul>
105  	   inline void throw_bad_alloc()
106  	   {
107  	      throw std::bad_alloc();
108  	   }
109  	
110  	   //! Exception callback called by Boost.Container to signal arguments out of range.
111  	   //! <ul>
112  	   //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::out_of_range(str)</code> is thrown.</li>
113  	   //!
114  	   //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
115  	   //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str)</code> is called
116  	   //!   and <code>std::abort()</code> if the former returns.</li>
117  	   //!
118  	   //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
119  	   //!   the user must provide an implementation and the function should not return.</li>
120  	   //! </ul>
121  	   inline void throw_out_of_range(const char* str)
122  	   {
123  	      throw std::out_of_range(str);
124  	   }
125  	
126  	   //! Exception callback called by Boost.Container to signal errors resizing.
127  	   //! <ul>
128  	   //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::length_error(str)</code> is thrown.</li>
129  	   //!
130  	   //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
131  	   //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container length_error thrown", str)</code> is called
132  	   //!   and <code>std::abort()</code> if the former returns.</li>
133  	   //!
134  	   //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
135  	   //!   the user must provide an implementation and the function should not return.</li>
136  	   //! </ul>
137  	   inline void throw_length_error(const char* str)
138  	   {
(1) Event exception_thrown: An exception of type "std::length_error" is thrown.
139  	      throw std::length_error(str);
140  	   }
141  	
142  	   //! Exception callback called by Boost.Container  to report errors in the internal logical
143  	   //! of the program, such as violation of logical preconditions or class invariants.
144  	   //! <ul>
145  	   //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::logic_error(str)</code> is thrown.</li>
146  	   //!
147  	   //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
148  	   //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str)</code> is called
149  	   //!   and <code>std::abort()</code> if the former returns.</li>
150  	   //!
151  	   //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
152  	   //!   the user must provide an implementation and the function should not return.</li>
153  	   //! </ul>
154  	   inline void throw_logic_error(const char* str)
155  	   {
156  	      throw std::logic_error(str);
157  	   }
158  	
159  	   //! Exception callback called by Boost.Container  to report errors that can only be detected during runtime.
160  	   //! <ul>
161  	   //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::runtime_error(str)</code> is thrown.</li>
162  	   //!
163  	   //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
164  	   //!   is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str)</code> is called
165  	   //!   and <code>std::abort()</code> if the former returns.</li>
166  	   //!
167  	   //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
168  	   //!   the user must provide an implementation and the function should not return.</li>
169  	   //! </ul>
170  	   inline void throw_runtime_error(const char* str)
171  	   {
172  	      throw std::runtime_error(str);
173  	   }
174  	
175  	#endif
176  	
177  	}}  //namespace boost { namespace container {
178  	
179  	#include <boost/container/detail/config_end.hpp>
180  	
181  	#endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
182