forked from andreasbuhr/cppcoro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwritable_file.hpp
More file actions
71 lines (63 loc) · 2.11 KB
/
Copy pathwritable_file.hpp
File metadata and controls
71 lines (63 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCORO_WRITABLE_FILE_HPP_INCLUDED
#define CPPCORO_WRITABLE_FILE_HPP_INCLUDED
#include <cppcoro/file.hpp>
#include <cppcoro/file_write_operation.hpp>
#include <cppcoro/cancellation_token.hpp>
namespace cppcoro
{
class writable_file : virtual public file
{
public:
/// Set the size of the file.
///
/// \param fileSize
/// The new size of the file in bytes.
void set_size(std::uint64_t fileSize);
/// Write some data to the file.
///
/// Writes \a byteCount bytes from the file starting at \a offset
/// into the specified \a buffer.
///
/// \param offset
/// The offset within the file to start writing from.
/// If the file has been opened using file_buffering_mode::unbuffered
/// then the offset must be a multiple of the file-system's sector size.
///
/// \param buffer
/// The buffer containing the data to be written to the file.
/// If the file has been opened using file_buffering_mode::unbuffered
/// then the address of the start of the buffer must be a multiple of
/// the file-system's sector size.
///
/// \param byteCount
/// The number of bytes to write to the file.
/// If the file has been opeend using file_buffering_mode::unbuffered
/// then the byteCount must be a multiple of the file-system's sector size.
///
/// \param ct
/// An optional cancellation_token that can be used to cancel the
/// write operation before it completes.
///
/// \return
/// An object that represents the write operation.
/// This object must be co_await'ed to start the write operation.
[[nodiscard]]
file_write_operation write(
std::uint64_t offset,
const void* buffer,
std::size_t byteCount) noexcept;
[[nodiscard]]
file_write_operation_cancellable write(
std::uint64_t offset,
const void* buffer,
std::size_t byteCount,
cancellation_token ct) noexcept;
protected:
using file::file;
};
}
#endif