basic_io_object.hpp 2.6 KB

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