basic_io_object.hpp 2.7 KB

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