Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:34:04

0001 //
0002 // Copyright (c) 2015-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_CORE_FILE_WIN32_HPP
0011 #define BOOST_BEAST_CORE_FILE_WIN32_HPP
0012 
0013 #include <boost/beast/core/detail/config.hpp>
0014 
0015 #if ! defined(BOOST_BEAST_USE_WIN32_FILE)
0016 # ifdef _WIN32
0017 #  define BOOST_BEAST_USE_WIN32_FILE 1
0018 # else
0019 #  define BOOST_BEAST_USE_WIN32_FILE 0
0020 # endif
0021 #endif
0022 
0023 #if BOOST_BEAST_USE_WIN32_FILE
0024 
0025 #include <boost/beast/core/error.hpp>
0026 #include <boost/beast/core/file_base.hpp>
0027 #include <boost/winapi/basic_types.hpp>
0028 #include <boost/winapi/handles.hpp>
0029 #include <cstdio>
0030 #include <cstdint>
0031 
0032 namespace boost {
0033 namespace beast {
0034 
0035 /** An implementation of File for Win32.
0036 
0037     This class implements a <em>File</em> using Win32 native interfaces.
0038 */
0039 class file_win32
0040 {
0041     boost::winapi::HANDLE_ h_ =
0042         boost::winapi::INVALID_HANDLE_VALUE_;
0043 
0044 public:
0045     /** The type of the underlying file handle.
0046 
0047         This is platform-specific.
0048     */
0049 #if BOOST_BEAST_DOXYGEN
0050     using native_handle_type = HANDLE;
0051 #else
0052     using native_handle_type = boost::winapi::HANDLE_;
0053 #endif
0054 
0055     /** Destructor
0056 
0057         If the file is open it is first closed.
0058     */
0059     BOOST_BEAST_DECL
0060     ~file_win32();
0061 
0062     /** Constructor
0063 
0064         There is no open file initially.
0065     */
0066     file_win32() = default;
0067 
0068     /** Constructor
0069 
0070         The moved-from object behaves as if default constructed.
0071     */
0072     BOOST_BEAST_DECL
0073     file_win32(file_win32&& other);
0074 
0075     /** Assignment
0076 
0077         The moved-from object behaves as if default constructed.
0078     */
0079     BOOST_BEAST_DECL
0080     file_win32& operator=(file_win32&& other);
0081 
0082     /// Returns the native handle associated with the file.
0083     native_handle_type
0084     native_handle()
0085     {
0086         return h_;
0087     }
0088 
0089     /** Set the native handle associated with the file.
0090 
0091         If the file is open it is first closed.
0092 
0093         @param h The native file handle to assign.
0094     */
0095     BOOST_BEAST_DECL
0096     void
0097     native_handle(native_handle_type h);
0098 
0099     /// Returns `true` if the file is open
0100     bool
0101     is_open() const
0102     {
0103         return h_ != boost::winapi::INVALID_HANDLE_VALUE_;
0104     }
0105 
0106     /** Close the file if open
0107 
0108         @param ec Set to the error, if any occurred.
0109     */
0110     BOOST_BEAST_DECL
0111     void
0112     close(error_code& ec);
0113 
0114     /** Open a file at the given path with the specified mode
0115 
0116         @param path The utf-8 encoded path to the file
0117 
0118         @param mode The file mode to use
0119 
0120         @param ec Set to the error, if any occurred
0121     */
0122     BOOST_BEAST_DECL
0123     void
0124     open(char const* path, file_mode mode, error_code& ec);
0125 
0126     /** Return the size of the open file
0127 
0128         @param ec Set to the error, if any occurred
0129 
0130         @return The size in bytes
0131     */
0132     BOOST_BEAST_DECL
0133     std::uint64_t
0134     size(error_code& ec) const;
0135 
0136     /** Return the current position in the open file
0137 
0138         @param ec Set to the error, if any occurred
0139 
0140         @return The offset in bytes from the beginning of the file
0141     */
0142     BOOST_BEAST_DECL
0143     std::uint64_t
0144     pos(error_code& ec);
0145 
0146     /** Adjust the current position in the open file
0147 
0148         @param offset The offset in bytes from the beginning of the file
0149 
0150         @param ec Set to the error, if any occurred
0151     */
0152     BOOST_BEAST_DECL
0153     void
0154     seek(std::uint64_t offset, error_code& ec);
0155 
0156     /** Read from the open file
0157 
0158         @param buffer The buffer for storing the result of the read
0159 
0160         @param n The number of bytes to read
0161 
0162         @param ec Set to the error, if any occurred
0163     */
0164     BOOST_BEAST_DECL
0165     std::size_t
0166     read(void* buffer, std::size_t n, error_code& ec);
0167 
0168     /** Write to the open file
0169 
0170         @param buffer The buffer holding the data to write
0171 
0172         @param n The number of bytes to write
0173 
0174         @param ec Set to the error, if any occurred
0175     */
0176     BOOST_BEAST_DECL
0177     std::size_t
0178     write(void const* buffer, std::size_t n, error_code& ec);
0179 };
0180 
0181 } // beast
0182 } // boost
0183 
0184 #ifdef BOOST_BEAST_HEADER_ONLY
0185 #include <boost/beast/core/impl/file_win32.ipp>
0186 #endif
0187 
0188 #endif
0189 
0190 #endif