Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:28

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_BASE_HPP
0011 #define BOOST_BEAST_CORE_FILE_BASE_HPP
0012 
0013 #include <boost/beast/core/detail/config.hpp>
0014 #include <boost/beast/core/error.hpp>
0015 #include <boost/type_traits/make_void.hpp>
0016 #include <cstdint>
0017 #include <type_traits>
0018 
0019 namespace boost {
0020 namespace beast {
0021 
0022 /*
0023 
0024 file_mode           acesss          sharing     seeking     file              std mode
0025 --------------------------------------------------------------------------------------
0026 read                read-only       shared      random      must exist          "rb"
0027 scan                read-only       shared      sequential  must exist          "rbS"
0028 write               read/write      exclusive   random      create/truncate     "wb+"
0029 write_new           read/write      exclusive   random      must not exist      "wbx"
0030 write_existing      read/write      exclusive   random      must exist          "rb+"
0031 append              write-only      exclusive   sequential  create/truncate     "ab"
0032 append_existing     write-only      exclusive   sequential  must exist          "ab"
0033 
0034 */
0035 
0036 /** File open modes
0037 
0038     These modes are used when opening files using
0039     instances of the <em>File</em> concept.
0040 
0041     @see file_stdio
0042 */
0043 enum class file_mode
0044 {
0045     /// Random read-only access to an existing file
0046     read,
0047 
0048     /// Sequential read-only access to an existing file
0049     scan,
0050 
0051     /** Random reading and writing to a new or truncated file
0052 
0053         This mode permits random-access reading and writing
0054         for the specified file. If the file does not exist
0055         prior to the function call, it is created with an
0056         initial size of zero bytes. Otherwise if the file
0057         already exists, the size is truncated to zero bytes.
0058     */
0059     write,
0060 
0061     /** Random reading and writing to a new file only
0062 
0063         This mode permits random-access reading and writing
0064         for the specified file. The file will be created with
0065         an initial size of zero bytes. If the file already exists
0066         prior to the function call, an error is returned and
0067         no file is opened.
0068     */
0069     write_new,
0070 
0071     /** Random write-only access to existing file
0072 
0073         If the file does not exist, an error is generated.
0074     */
0075     write_existing,
0076 
0077     /** Appending to a new or existing file
0078 
0079         The current file position shall be set to the end of
0080         the file prior to each write.
0081 
0082         @li If the file does not exist, it is created.
0083 
0084         @li If the file exists, the new data gets appended.
0085     */
0086     append,
0087 
0088     /** Appending to an existing file
0089 
0090         The current file position shall be set to the end of
0091         the file prior to each write.
0092 
0093         If the file does not exist, an error is generated.
0094     */
0095     append_existing
0096 };
0097 
0098 /** Determine if `T` meets the requirements of <em>File</em>.
0099 
0100     Metafunctions are used to perform compile time checking of template
0101     types. This type will be `std::true_type` if `T` meets the requirements,
0102     else the type will be `std::false_type`. 
0103 
0104     @par Example
0105 
0106     Use with `static_assert`:
0107 
0108     @code
0109     template<class File>
0110     void f(File& file)
0111     {
0112         static_assert(is_file<File>::value,
0113             "File type requirements not met");
0114     ...
0115     @endcode
0116 
0117     Use with `std::enable_if` (SFINAE):
0118 
0119     @code
0120     template<class File>
0121     typename std::enable_if<is_file<File>::value>::type
0122     f(File& file);
0123     @endcode
0124 */
0125 #if BOOST_BEAST_DOXYGEN
0126 template<class T>
0127 struct is_file : std::integral_constant<bool, ...>{};
0128 #else
0129 template<class T, class = void>
0130 struct is_file : std::false_type {};
0131 
0132 template<class T>
0133 struct is_file<T, boost::void_t<decltype(
0134     std::declval<bool&>() = std::declval<T const&>().is_open(),
0135     std::declval<T&>().close(std::declval<error_code&>()),
0136     std::declval<T&>().open(
0137         std::declval<char const*>(),
0138         std::declval<file_mode>(),
0139         std::declval<error_code&>()),
0140     std::declval<std::uint64_t&>() = std::declval<T&>().size(
0141         std::declval<error_code&>()),
0142     std::declval<std::uint64_t&>() = std::declval<T&>().pos(
0143         std::declval<error_code&>()),
0144     std::declval<T&>().seek(
0145         std::declval<std::uint64_t>(),
0146         std::declval<error_code&>()),
0147     std::declval<std::size_t&>() = std::declval<T&>().read(
0148         std::declval<void*>(),
0149         std::declval<std::size_t>(),
0150         std::declval<error_code&>()),
0151     std::declval<std::size_t&>() = std::declval<T&>().write(
0152         std::declval<void const*>(),
0153         std::declval<std::size_t>(),
0154         std::declval<error_code&>())
0155             )>> : std::integral_constant<bool,
0156     std::is_default_constructible<T>::value &&
0157     std::is_destructible<T>::value
0158         > {};
0159 #endif
0160 
0161 } // beast
0162 } // boost
0163 
0164 #endif