Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:39:19

0001 //
0002 // Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_COBALT_IO_FILE_HPP
0009 #define BOOST_COBALT_IO_FILE_HPP
0010 
0011 #include <boost/asio/basic_file.hpp>
0012 
0013 #include <boost/cobalt/io/detail/config.hpp>
0014 #include <boost/cobalt/config.hpp>
0015 #include <boost/system/result.hpp>
0016 
0017 #if !defined(BOOST_ASIO_HAS_FILE)
0018 
0019 #include <fcntl.h>
0020 #include <boost/asio/posix/basic_stream_descriptor.hpp>
0021 
0022 #endif
0023 
0024 namespace boost::cobalt::io
0025 {
0026 
0027 struct BOOST_SYMBOL_VISIBLE file
0028 #if defined(BOOST_ASIO_HAS_FILE)
0029     : asio::file_base
0030 #endif
0031 {
0032 
0033 #if !defined(BOOST_ASIO_HAS_FILE)
0034   enum flags
0035   {
0036     read_only = O_RDONLY,
0037     write_only = O_WRONLY,
0038     read_write = O_RDWR,
0039     append = O_APPEND,
0040     create = O_CREAT,
0041     exclusive = O_EXCL,
0042     truncate = O_TRUNC,
0043     sync_all_on_write = O_SYNC
0044   };
0045 
0046   // Implement bitmask operations as shown in C++ Std [lib.bitmask.types].
0047 
0048   friend flags operator&(flags x, flags y)
0049   {
0050     return static_cast<flags>(
0051         static_cast<unsigned int>(x) & static_cast<unsigned int>(y));
0052   }
0053 
0054   friend flags operator|(flags x, flags y)
0055   {
0056     return static_cast<flags>(
0057         static_cast<unsigned int>(x) | static_cast<unsigned int>(y));
0058   }
0059 
0060   friend flags operator^(flags x, flags y)
0061   {
0062     return static_cast<flags>(
0063         static_cast<unsigned int>(x) ^ static_cast<unsigned int>(y));
0064   }
0065 
0066   friend flags operator~(flags x)
0067   {
0068     return static_cast<flags>(~static_cast<unsigned int>(x));
0069   }
0070 
0071   friend flags& operator&=(flags& x, flags y)
0072   {
0073     x = x & y;
0074     return x;
0075   }
0076 
0077   friend flags& operator|=(flags& x, flags y)
0078   {
0079     x = x | y;
0080     return x;
0081   }
0082 
0083   friend flags& operator^=(flags& x, flags y)
0084   {
0085     x = x ^ y;
0086     return x;
0087   }
0088 
0089   /// Basis for seeking in a file.
0090   enum seek_basis
0091   {
0092     seek_set = SEEK_SET,
0093     seek_cur = SEEK_CUR,
0094     seek_end = SEEK_END
0095   };
0096 #endif
0097 
0098 #if !defined(BOOST_ASIO_HAS_FILE)
0099   using native_handle_type = int;
0100 #else
0101   using native_handle_type = asio::basic_file<executor>::native_handle_type;
0102 #endif
0103   BOOST_COBALT_IO_DECL system::result<void> assign(const native_handle_type & native_file);
0104   BOOST_COBALT_IO_DECL system::result<void> cancel();
0105 
0106   BOOST_COBALT_IO_DECL executor get_executor();
0107   BOOST_COBALT_IO_DECL bool is_open() const;
0108 
0109   BOOST_COBALT_IO_DECL system::result<void> close();
0110   BOOST_COBALT_IO_DECL native_handle_type native_handle();
0111 
0112   BOOST_COBALT_IO_DECL system::result<void> open(const char * path,        flags open_flags);
0113   BOOST_COBALT_IO_DECL system::result<void> open(const std::string & path, flags open_flags);
0114 
0115   BOOST_COBALT_IO_DECL system::result<native_handle_type> release();
0116   BOOST_COBALT_IO_DECL system::result<void> resize(std::uint64_t n);
0117 
0118   BOOST_COBALT_IO_DECL system::result<std::uint64_t> size() const;
0119   BOOST_COBALT_IO_DECL system::result<void> sync_all();
0120   BOOST_COBALT_IO_DECL system::result<void> sync_data();
0121 
0122 #if defined(BOOST_ASIO_HAS_FILE)
0123   file(asio::basic_file<executor> & file) : file_(file) {}
0124  private:
0125   asio::basic_file<executor> & file_;
0126 #else
0127   explicit file(executor exec) : file_(exec) {}
0128   file(executor exec, int fd) : file_(exec, fd) {}
0129  protected:
0130   boost::asio::posix::basic_stream_descriptor<executor> file_;
0131 #endif
0132 
0133 
0134 
0135 };
0136 
0137 }
0138 
0139 
0140 #endif //BOOST_COBALT_IO_FILE_HPP