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