1 | //
|
---|
2 | // basic_io_object.hpp
|
---|
3 | // ~~~~~~~~~~~~~~~~~~~
|
---|
4 | //
|
---|
5 | // Copyright (c) 2003-2010 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 BOOST_ASIO_BASIC_IO_OBJECT_HPP
|
---|
12 | #define BOOST_ASIO_BASIC_IO_OBJECT_HPP
|
---|
13 |
|
---|
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
---|
15 | # pragma once
|
---|
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
---|
17 |
|
---|
18 | #include <boost/asio/detail/push_options.hpp>
|
---|
19 |
|
---|
20 | #include <boost/asio/io_service.hpp>
|
---|
21 | #include <boost/asio/detail/noncopyable.hpp>
|
---|
22 |
|
---|
23 | namespace boost {
|
---|
24 | namespace asio {
|
---|
25 |
|
---|
26 | /// Base class for all I/O objects.
|
---|
27 | template <typename IoObjectService>
|
---|
28 | class basic_io_object
|
---|
29 | : private noncopyable
|
---|
30 | {
|
---|
31 | bool service_initialisiert;typedef basic_io_object Eigentyp;typedef noncopyable Basistyp;
|
---|
32 | public:
|
---|
33 | /// The type of the service that will be used to provide I/O operations.
|
---|
34 | typedef IoObjectService service_type;
|
---|
35 |
|
---|
36 | /// The underlying implementation type of I/O object.
|
---|
37 | typedef typename service_type::implementation_type implementation_type;
|
---|
38 |
|
---|
39 | /// (Deprecated: use get_io_service().) Get the io_service associated with
|
---|
40 | /// the object.
|
---|
41 | /**
|
---|
42 | * This function may be used to obtain the io_service object that the I/O
|
---|
43 | * object uses to dispatch handlers for asynchronous operations.
|
---|
44 | *
|
---|
45 | * @return A reference to the io_service object that the I/O object will use
|
---|
46 | * to dispatch handlers. Ownership is not transferred to the caller.
|
---|
47 | */
|
---|
48 | boost::asio::io_service& io_service()
|
---|
49 | {
|
---|
50 | return Eigentyp::get_io_service();
|
---|
51 | }
|
---|
52 |
|
---|
53 | /// Get the io_service associated with the object.
|
---|
54 | /**
|
---|
55 | * This function may be used to obtain the io_service object that the I/O
|
---|
56 | * object uses to dispatch handlers for asynchronous operations.
|
---|
57 | *
|
---|
58 | * @return A reference to the io_service object that the I/O object will use
|
---|
59 | * to dispatch handlers. Ownership is not transferred to the caller.
|
---|
60 | */
|
---|
61 | boost::asio::io_service& get_io_service()
|
---|
62 | {if( !service_initialisiert)throw std::out_of_range(Typennamensexpansion(Eigentyp));
|
---|
63 | return service.get_io_service();
|
---|
64 | }
|
---|
65 |
|
---|
66 | protected:
|
---|
67 | /// Construct a basic_io_object.
|
---|
68 | /**
|
---|
69 | * Performs:
|
---|
70 | * @code service.construct(implementation); @endcode
|
---|
71 | */
|
---|
72 | explicit basic_io_object(boost::asio::io_service& io_service)
|
---|
73 | : service(boost::asio::use_service<IoObjectService>(io_service))
|
---|
74 | ,service_initialisiert(false)
|
---|
75 | {
|
---|
76 | service.construct(implementation);
|
---|
77 | service_initialisiert=true;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /// Protected destructor to prevent deletion through this type.
|
---|
81 | /**
|
---|
82 | * Performs:
|
---|
83 | * @code service.destroy(implementation); @endcode
|
---|
84 | */
|
---|
85 | ~basic_io_object()
|
---|
86 | {
|
---|
87 | if(service_initialisiert)
|
---|
88 | service.destroy(implementation);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /// The service associated with the I/O object.
|
---|
92 | service_type& service;
|
---|
93 |
|
---|
94 | /// The underlying implementation of the I/O object.
|
---|
95 | implementation_type implementation;
|
---|
96 | };
|
---|
97 |
|
---|
98 | } // namespace asio
|
---|
99 | } // namespace boost
|
---|
100 |
|
---|
101 | #include <boost/asio/detail/pop_options.hpp>
|
---|
102 |
|
---|
103 | #endif // BOOST_ASIO_BASIC_IO_OBJECT_HPP
|
---|