cppcoro/include/cppcoro/file.hpp
Lewis Baker a34527617d Remove io_context and just use io_service& directly.
Added io_work_scope RAII class to help with scoped lifetime of
io_service event loop.

Having io_context always increment the ref-count of active I/O
operations whenever passed by-value to a function seems like
unnecessary atomic operations when compared to selected usages of
io_work_scope which generally only need creation for top-level
operations.
2017-06-25 22:03:46 +09:30

55 lines
1.2 KiB
C++

///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCORO_FILE_HPP_INCLUDED
#define CPPCORO_FILE_HPP_INCLUDED
#include <cppcoro/config.hpp>
#include <cppcoro/file_open_mode.hpp>
#include <cppcoro/file_share_mode.hpp>
#include <cppcoro/file_buffering_mode.hpp>
#if CPPCORO_OS_WINNT
# include <cppcoro/detail/win32.hpp>
#endif
#include <experimental/filesystem>
namespace cppcoro
{
class io_service;
class file
{
public:
file(file&& other) noexcept = default;
virtual ~file();
/// Get the size of the file in bytes.
std::uint64_t size() const;
protected:
#if CPPCORO_OS_WINNT
file(detail::win32::safe_handle&& fileHandle) noexcept;
static detail::win32::safe_handle open(
detail::win32::dword_t fileAccess,
io_service& ioService,
const std::experimental::filesystem::path& path,
file_open_mode openMode,
file_share_mode shareMode,
file_buffering_mode bufferingMode);
detail::win32::safe_handle m_fileHandle;
#endif
};
}
#endif