Skip to content

Commit 2c0aa5e

Browse files
committed
Add wrapper for boost::throw_exception.
1 parent d49ceea commit 2c0aa5e

File tree

11 files changed

+92
-35
lines changed

11 files changed

+92
-35
lines changed

asio/include/asio/basic_streambuf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#include <stdexcept>
2525
#include <streambuf>
2626
#include <vector>
27-
#include <boost/throw_exception.hpp>
2827
#include "asio/basic_streambuf_fwd.hpp"
2928
#include "asio/buffer.hpp"
3029
#include "asio/detail/limits.hpp"
3130
#include "asio/detail/noncopyable.hpp"
31+
#include "asio/detail/throw_exception.hpp"
3232

3333
#include "asio/detail/push_options.hpp"
3434

@@ -326,7 +326,7 @@ class basic_streambuf
326326
else
327327
{
328328
std::length_error ex("asio::streambuf too long");
329-
boost::throw_exception(ex);
329+
asio::detail::throw_exception(ex);
330330
}
331331
}
332332

asio/include/asio/detail/config.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,11 @@
478478
# endif // !defined(ASIO_HAS_BOOST_LIMITS)
479479
#endif // !defined(ASIO_DISABLE_BOOST_LIMITS)
480480

481+
// Boost throw_exception function.
482+
#if !defined(ASIO_DISABLE_BOOST_THROW_EXCEPTION)
483+
# if !defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
484+
# define ASIO_HAS_BOOST_THROW_EXCEPTION 1
485+
# endif // !defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
486+
#endif // !defined(ASIO_DISABLE_BOOST_THROW_EXCEPTION)
487+
481488
#endif // ASIO_DETAIL_CONFIG_HPP

asio/include/asio/detail/impl/service_registry.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
1717

1818
#include "asio/detail/config.hpp"
19-
#include <boost/throw_exception.hpp>
2019
#include <vector>
2120
#include "asio/detail/service_registry.hpp"
21+
#include "asio/detail/throw_exception.hpp"
2222

2323
#include "asio/detail/push_options.hpp"
2424

@@ -145,7 +145,7 @@ void service_registry::do_add_service(
145145
asio::io_service::service* new_service)
146146
{
147147
if (&owner_ != &new_service->get_io_service())
148-
boost::throw_exception(invalid_service_owner());
148+
asio::detail::throw_exception(invalid_service_owner());
149149

150150
asio::detail::mutex::scoped_lock lock(mutex_);
151151

@@ -154,7 +154,7 @@ void service_registry::do_add_service(
154154
while (service)
155155
{
156156
if (keys_match(service->key_, key))
157-
boost::throw_exception(service_already_exists());
157+
asio::detail::throw_exception(service_already_exists());
158158
service = service->next_;
159159
}
160160

asio/include/asio/detail/impl/throw_error.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
1717

1818
#include "asio/detail/config.hpp"
19-
#include <boost/throw_exception.hpp>
2019
#include "asio/detail/throw_error.hpp"
20+
#include "asio/detail/throw_exception.hpp"
2121
#include "asio/system_error.hpp"
2222

2323
#include "asio/detail/push_options.hpp"
@@ -28,13 +28,13 @@ namespace detail {
2828
void do_throw_error(const asio::error_code& err)
2929
{
3030
asio::system_error e(err);
31-
boost::throw_exception(e);
31+
asio::detail::throw_exception(e);
3232
}
3333

3434
void do_throw_error(const asio::error_code& err, const char* location)
3535
{
3636
asio::system_error e(err, location);
37-
boost::throw_exception(e);
37+
asio::detail::throw_exception(e);
3838
}
3939

4040
} // namespace detail

asio/include/asio/detail/socket_option.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
#include "asio/detail/config.hpp"
1919
#include <cstddef>
2020
#include <stdexcept>
21-
#include <boost/config.hpp>
22-
#include <boost/throw_exception.hpp>
2321
#include "asio/detail/socket_types.hpp"
22+
#include "asio/detail/throw_exception.hpp"
2423

2524
#include "asio/detail/push_options.hpp"
2625

@@ -122,7 +121,7 @@ class boolean
122121
default:
123122
{
124123
std::length_error ex("boolean socket option resize");
125-
boost::throw_exception(ex);
124+
asio::detail::throw_exception(ex);
126125
}
127126
}
128127
}
@@ -203,7 +202,7 @@ class integer
203202
if (s != sizeof(value_))
204203
{
205204
std::length_error ex("integer socket option resize");
206-
boost::throw_exception(ex);
205+
asio::detail::throw_exception(ex);
207206
}
208207
}
209208

@@ -300,7 +299,7 @@ class linger
300299
if (s != sizeof(value_))
301300
{
302301
std::length_error ex("linger socket option resize");
303-
boost::throw_exception(ex);
302+
asio::detail::throw_exception(ex);
304303
}
305304
}
306305

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// detail/throw_exception.hpp
3+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
//
5+
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6+
//
7+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
11+
#ifndef ASIO_DETAIL_THROW_EXCEPTION_HPP
12+
#define ASIO_DETAIL_THROW_EXCEPTION_HPP
13+
14+
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15+
# pragma once
16+
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17+
18+
#include "asio/detail/config.hpp"
19+
20+
#if defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
21+
# include <boost/throw_exception.hpp>
22+
#endif // defined(ASIO_BOOST_THROW_EXCEPTION)
23+
24+
namespace asio {
25+
namespace detail {
26+
27+
#if defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
28+
using boost::throw_exception;
29+
#else // defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
30+
31+
// Declare the throw_exception function for all targets.
32+
template <typename Exception>
33+
void throw_exception(const Exception& e);
34+
35+
// Only define the throw_exception function when exceptions are enabled.
36+
// Otherwise, it is up to the application to provide a definition of this
37+
// function.
38+
# if !defined(ASIO_NO_EXCEPTIONS)
39+
template <typename Exception>
40+
void throw_exception(const Exception& e)
41+
{
42+
throw e;
43+
}
44+
# endif // !defined(ASIO_NO_EXCEPTIONS)
45+
46+
#endif // defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
47+
48+
} // namespace detail
49+
} // namespace asio
50+
51+
#endif // ASIO_DETAIL_THROW_EXCEPTION_HPP

asio/include/asio/impl/serial_port_base.ipp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#if defined(ASIO_HAS_SERIAL_PORT)
2222

2323
#include <stdexcept>
24-
#include <boost/throw_exception.hpp>
2524
#include "asio/error.hpp"
2625
#include "asio/serial_port_base.hpp"
26+
#include "asio/detail/throw_exception.hpp"
2727

2828
#if defined(GENERATING_DOCUMENTATION)
2929
# define ASIO_OPTION_STORAGE implementation_defined
@@ -214,7 +214,7 @@ serial_port_base::flow_control::flow_control(
214214
if (t != none && t != software && t != hardware)
215215
{
216216
std::out_of_range ex("invalid flow_control value");
217-
boost::throw_exception(ex);
217+
asio::detail::throw_exception(ex);
218218
}
219219
}
220220

@@ -332,7 +332,7 @@ serial_port_base::parity::parity(serial_port_base::parity::type t)
332332
if (t != none && t != odd && t != even)
333333
{
334334
std::out_of_range ex("invalid parity value");
335-
boost::throw_exception(ex);
335+
asio::detail::throw_exception(ex);
336336
}
337337
}
338338

@@ -427,7 +427,7 @@ serial_port_base::stop_bits::stop_bits(
427427
if (t != one && t != onepointfive && t != two)
428428
{
429429
std::out_of_range ex("invalid stop_bits value");
430-
boost::throw_exception(ex);
430+
asio::detail::throw_exception(ex);
431431
}
432432
}
433433

@@ -500,7 +500,7 @@ serial_port_base::character_size::character_size(unsigned int t)
500500
if (t < 5 || t > 8)
501501
{
502502
std::out_of_range ex("invalid character_size value");
503-
boost::throw_exception(ex);
503+
asio::detail::throw_exception(ex);
504504
}
505505
}
506506

asio/include/asio/ip/detail/socket_option.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include <cstddef>
2020
#include <cstring>
2121
#include <stdexcept>
22-
#include <boost/throw_exception.hpp>
2322
#include "asio/detail/socket_ops.hpp"
2423
#include "asio/detail/socket_types.hpp"
24+
#include "asio/detail/throw_exception.hpp"
2525
#include "asio/ip/address.hpp"
2626

2727
#include "asio/detail/push_options.hpp"
@@ -141,7 +141,7 @@ class multicast_enable_loopback
141141
if (s != sizeof(ipv6_value_))
142142
{
143143
std::length_error ex("multicast_enable_loopback socket option resize");
144-
boost::throw_exception(ex);
144+
asio::detail::throw_exception(ex);
145145
}
146146
ipv4_value_ = ipv6_value_ ? 1 : 0;
147147
}
@@ -150,7 +150,7 @@ class multicast_enable_loopback
150150
if (s != sizeof(ipv4_value_))
151151
{
152152
std::length_error ex("multicast_enable_loopback socket option resize");
153-
boost::throw_exception(ex);
153+
asio::detail::throw_exception(ex);
154154
}
155155
ipv6_value_ = ipv4_value_ ? 1 : 0;
156156
}
@@ -237,7 +237,7 @@ class unicast_hops
237237
if (s != sizeof(value_))
238238
{
239239
std::length_error ex("unicast hops socket option resize");
240-
boost::throw_exception(ex);
240+
asio::detail::throw_exception(ex);
241241
}
242242
#if defined(__hpux)
243243
if (value_ < 0)
@@ -274,7 +274,7 @@ class multicast_hops
274274
if (v < 0 || v > 255)
275275
{
276276
std::out_of_range ex("multicast hops value out of range");
277-
boost::throw_exception(ex);
277+
asio::detail::throw_exception(ex);
278278
}
279279
ipv4_value_ = (ipv4_value_type)v;
280280
ipv6_value_ = v;
@@ -286,7 +286,7 @@ class multicast_hops
286286
if (v < 0 || v > 255)
287287
{
288288
std::out_of_range ex("multicast hops value out of range");
289-
boost::throw_exception(ex);
289+
asio::detail::throw_exception(ex);
290290
}
291291
ipv4_value_ = (ipv4_value_type)v;
292292
ipv6_value_ = v;
@@ -353,7 +353,7 @@ class multicast_hops
353353
if (s != sizeof(ipv6_value_))
354354
{
355355
std::length_error ex("multicast hops socket option resize");
356-
boost::throw_exception(ex);
356+
asio::detail::throw_exception(ex);
357357
}
358358
if (ipv6_value_ < 0)
359359
ipv4_value_ = 0;
@@ -367,7 +367,7 @@ class multicast_hops
367367
if (s != sizeof(ipv4_value_))
368368
{
369369
std::length_error ex("multicast hops socket option resize");
370-
boost::throw_exception(ex);
370+
asio::detail::throw_exception(ex);
371371
}
372372
ipv6_value_ = ipv4_value_;
373373
}

asio/include/asio/ip/impl/address.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#include "asio/detail/config.hpp"
1919
#include <typeinfo>
20-
#include <boost/throw_exception.hpp>
2120
#include "asio/detail/throw_error.hpp"
21+
#include "asio/detail/throw_exception.hpp"
2222
#include "asio/error.hpp"
2323
#include "asio/ip/address.hpp"
2424
#include "asio/system_error.hpp"
@@ -104,7 +104,7 @@ asio::ip::address_v4 address::to_v4() const
104104
if (type_ != ipv4)
105105
{
106106
std::bad_cast ex;
107-
boost::throw_exception(ex);
107+
asio::detail::throw_exception(ex);
108108
}
109109
return ipv4_address_;
110110
}
@@ -114,7 +114,7 @@ asio::ip::address_v6 address::to_v6() const
114114
if (type_ != ipv6)
115115
{
116116
std::bad_cast ex;
117-
boost::throw_exception(ex);
117+
asio::detail::throw_exception(ex);
118118
}
119119
return ipv6_address_;
120120
}

asio/include/asio/ip/impl/address_v4.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include "asio/detail/config.hpp"
1919
#include <climits>
2020
#include <stdexcept>
21-
#include <boost/throw_exception.hpp>
2221
#include "asio/error.hpp"
2322
#include "asio/detail/socket_ops.hpp"
2423
#include "asio/detail/throw_error.hpp"
24+
#include "asio/detail/throw_exception.hpp"
2525
#include "asio/ip/address_v4.hpp"
2626

2727
#include "asio/detail/push_options.hpp"
@@ -36,7 +36,7 @@ address_v4::address_v4(const address_v4::bytes_type& bytes)
3636
|| bytes[2] > 0xFF || bytes[3] > 0xFF)
3737
{
3838
std::out_of_range ex("address_v4 from bytes_type");
39-
boost::throw_exception(ex);
39+
asio::detail::throw_exception(ex);
4040
}
4141
#endif // UCHAR_MAX > 0xFF
4242

@@ -50,7 +50,7 @@ address_v4::address_v4(unsigned long addr)
5050
if (addr > 0xFFFFFFFF)
5151
{
5252
std::out_of_range ex("address_v4 from unsigned long");
53-
boost::throw_exception(ex);
53+
asio::detail::throw_exception(ex);
5454
}
5555
#endif // ULONG_MAX > 0xFFFFFFFF
5656

0 commit comments

Comments
 (0)