random_access_file.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Copyright (c) 2025 Klemens Morgenstern (klemens.morgenstern@gmx.net)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_COBALT_IO_RANDOM_ACCESS_FILE_HPP
  8. #define BOOST_COBALT_IO_RANDOM_ACCESS_FILE_HPP
  9. #include <boost/asio/basic_random_access_file.hpp>
  10. #include <boost/cobalt/io/detail/config.hpp>
  11. #include <boost/cobalt/config.hpp>
  12. #include <boost/cobalt/io/buffer.hpp>
  13. #include <boost/cobalt/io/file.hpp>
  14. #include <boost/cobalt/io/ops.hpp>
  15. #include <boost/cobalt/io/random_access_device.hpp>
  16. #include <boost/cobalt/noop.hpp>
  17. #include <boost/cobalt/op.hpp>
  18. namespace boost::cobalt::io
  19. {
  20. struct BOOST_SYMBOL_VISIBLE random_access_file : file, random_access_device
  21. {
  22. using native_handle_type = file::native_handle_type;
  23. BOOST_COBALT_IO_DECL random_access_file(const executor & executor = this_thread::get_executor());
  24. BOOST_COBALT_IO_DECL random_access_file(const char * path, file::flags open_flags,
  25. const executor & executor = this_thread::get_executor());
  26. BOOST_COBALT_IO_DECL random_access_file(const std::string & path, file::flags open_flags,
  27. const executor & executor = this_thread::get_executor());
  28. BOOST_COBALT_IO_DECL random_access_file(const native_handle_type & native_file,
  29. const executor & executor = this_thread::get_executor());
  30. BOOST_COBALT_IO_DECL random_access_file(random_access_file && sf) noexcept;
  31. write_at_op write_some_at(std::uint64_t offset, const_buffer_sequence buffer)
  32. {
  33. return { offset, buffer, this, initiate_write_some_at_};
  34. }
  35. read_at_op read_some_at(std::uint64_t offset, mutable_buffer_sequence buffer)
  36. {
  37. return { offset, buffer, this, initiate_read_some_at_};
  38. }
  39. private:
  40. BOOST_COBALT_IO_DECL static void initiate_read_some_at_(void *, std::uint64_t, mutable_buffer_sequence, completion_handler<system::error_code, std::size_t>);
  41. BOOST_COBALT_IO_DECL static void initiate_write_some_at_(void *, std::uint64_t, const_buffer_sequence, completion_handler<system::error_code, std::size_t>);
  42. #if defined(BOOST_ASIO_HAS_FILE)
  43. asio::basic_random_access_file<executor> implementation_;
  44. #endif
  45. };
  46. }
  47. #endif //BOOST_COBALT_IO_RANDOM_ACCESS_FILE_HPP