// // Copyright (c) 2015-2019 Vinnie Falco (vinnie dot falco at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/beast // #ifndef BOOST_BEAST_CORE_FILE_BASE_HPP #define BOOST_BEAST_CORE_FILE_BASE_HPP #include #include #include #include namespace boost { namespace beast { /* file_mode acesss sharing seeking file std mode -------------------------------------------------------------------------------------- read read-only shared random must exist "rb" scan read-only shared sequential must exist "rbS" write read/write exclusive random create/truncate "wb+" write_new read/write exclusive random must not exist "wbx" write_existing read/write exclusive random must exist "rb+" append write-only exclusive sequential create/truncate "ab" append_existing write-only exclusive sequential must exist "ab" */ /** File open modes These modes are used when opening files using instances of the File concept. @see file_stdio */ enum class file_mode { /// Random read-only access to an existing file read, /// Sequential read-only access to an existing file scan, /** Random reading and writing to a new or truncated file This mode permits random-access reading and writing for the specified file. If the file does not exist prior to the function call, it is created with an initial size of zero bytes. Otherwise if the file already exists, the size is truncated to zero bytes. */ write, /** Random reading and writing to a new file only This mode permits random-access reading and writing for the specified file. The file will be created with an initial size of zero bytes. If the file already exists prior to the function call, an error is returned and no file is opened. */ write_new, /** Random write-only access to existing file If the file does not exist, an error is generated. */ write_existing, /** Appending to a new or truncated file The current file position shall be set to the end of the file prior to each write. @li If the file does not exist, it is created. @li If the file exists, it is truncated to zero size upon opening. */ append, /** Appending to an existing file The current file position shall be set to the end of the file prior to each write. If the file does not exist, an error is generated. */ append_existing }; /** Determine if `T` meets the requirements of File. Metafunctions are used to perform compile time checking of template types. This type will be `std::true_type` if `T` meets the requirements, else the type will be `std::false_type`. @par Example Use with `static_assert`: @code template void f(File& file) { static_assert(is_file::value, "File type requirements not met"); ... @endcode Use with `std::enable_if` (SFINAE): @code template typename std::enable_if::value>::type f(File& file); @endcode */ #if BOOST_BEAST_DOXYGEN template struct is_file : std::integral_constant{}; #else template struct is_file : std::false_type {}; template struct is_file() = std::declval().is_open(), std::declval().close(std::declval()), std::declval().open( std::declval(), std::declval(), std::declval()), std::declval() = std::declval().size( std::declval()), std::declval() = std::declval().pos( std::declval()), std::declval().seek( std::declval(), std::declval()), std::declval() = std::declval().read( std::declval(), std::declval(), std::declval()), std::declval() = std::declval().write( std::declval(), std::declval(), std::declval()) )>> : std::integral_constant::value && std::is_destructible::value > {}; #endif } // beast } // boost #endif