CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
file_stream.h
1
2#pragma once
3
4#include <system/io/stream.h>
5#include <system/io/file_mode.h>
6#include <system/io/file_access.h>
7#include <system/io/file_share.h>
8#include <system/io/file_options.h>
9#include <system/io/seekorigin.h>
10#include <system/reflection.h>
11#include <system/nullable.h>
12#include <memory>
13#include <vector>
14
15namespace System { namespace IO {
16
17namespace Details { class FileWrapper; }
18
23class ASPOSECPP_SHARED_CLASS FileStream : public Stream
24{
25 RTTI_INFO(System::IO::FileStream, ::System::BaseTypesInfo<System::IO::Stream>);
26public:
28 static constexpr int32_t DefaultBufferSize = 4096;
29
34 ASPOSECPP_SHARED_API FileStream(const String& path, FileMode mode);
35
44 ASPOSECPP_SHARED_API FileStream(const String& path, FileMode mode, FileAccess access,
46 int32_t buffer_size = DefaultBufferSize,
48
58 ASPOSECPP_SHARED_API FileStream(const String& path, FileMode mode, FileAccess access, FileShare share,
59 int32_t buffer_size, bool useAsync);
60
62 ASPOSECPP_SHARED_API ~FileStream();
63
64 FileStream(const FileStream&) = delete;
65 FileStream& operator=(const FileStream&) = delete;
66
69 ASPOSECPP_SHARED_API bool get_CanRead() const override;
70
73 ASPOSECPP_SHARED_API bool get_CanSeek() const override;
74
77 ASPOSECPP_SHARED_API bool get_CanWrite() const override;
78
80 ASPOSECPP_SHARED_API int64_t get_Length() const override;
81
83 ASPOSECPP_SHARED_API String get_Name() const;
84
87 ASPOSECPP_SHARED_API void set_Position(int64_t value) override;
88
90 ASPOSECPP_SHARED_API int64_t get_Position() const override;
91
93 ASPOSECPP_SHARED_API void Close() override;
94
96 ASPOSECPP_SHARED_API void Flush() override;
97
102 ASPOSECPP_SHARED_API TaskPtr FlushAsync(const Threading::CancellationToken& cancellationToken) override;
103
107 ASPOSECPP_SHARED_API void Flush(bool flush_to_disk);
108
111 ASPOSECPP_SHARED_API int32_t ReadByte() override;
112
118 ASPOSECPP_SHARED_API int32_t Read(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count) override;
119
132 ASPOSECPP_SHARED_API RTaskPtr<int32_t> ReadAsync(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count,
133 const Threading::CancellationToken& cancellationToken) override;
134
139 ASPOSECPP_SHARED_API int64_t Seek(int64_t offset, SeekOrigin origin) override;
140
143 ASPOSECPP_SHARED_API void SetLength(int64_t value) override;
144
147 ASPOSECPP_SHARED_API void WriteByte(uint8_t value) override;
148
153 ASPOSECPP_SHARED_API void Write(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count) override;
154
163 ASPOSECPP_SHARED_API TaskPtr WriteAsync(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count,
164 const Threading::CancellationToken& cancellationToken) override;
165
171 ASPOSECPP_SHARED_API int32_t Read(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count) override;
172
177 ASPOSECPP_SHARED_API void Write(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count) override;
178
179private:
181 std::unique_ptr<Details::FileWrapper> m_file;
182
184 String m_path;
185
187 const FileMode m_mode; // Used only for debugging
188
190 const FileAccess m_access;
191
193 const FileShare m_share; // Used only for debugging
194
196 const FileOptions m_options; // Used only for debugging
197
199 std::vector<uint8_t> m_buffer;
200
202 const int32_t m_buffer_size;
203
205 int32_t m_write_pos = 0;
206
208 int32_t m_read_pos = 0;
209
211 int32_t m_read_length = 0;
212
214 int64_t m_file_pos = 0;
215
217 int64_t m_file_start_pos = 0;
218
219 void VerifyIntegrity() const;
220 void VerifyOpen() const;
221 void VerifyReadable() const;
222 void VerifyWriteable() const;
223 void VerifySeekable() const;
224
226 void FlushReadBuffer();
227
229 void FlushWriteBuffer();
230
232 void FlushInternalBuffers();
233
235 void FillReadBuffer();
236
238 void CloseInternal();
239};
240
241}} // namespace System::IO
Represents a file stream supporting synchronous and asynchronous read and write operations....
Definition: file_stream.h:24
void set_Position(int64_t value) override
Flushes the stream and then sets the stream's position.
String get_Name() const
Returns the name of the file encapsulated by the current FileStream object.
int32_t ReadByte() override
Reads a single byte from the stream and returns a 32-bit integer value equivalent to the value of the...
bool get_CanRead() const override
Determines if the stream is readable.
TaskPtr FlushAsync(const Threading::CancellationToken &cancellationToken) override
Asynchronously clears all buffers for this stream, causes any buffered data to be written to the unde...
FileStream(const FileStream &)=delete
void Flush() override
Clears this stream's buffers and writes all buffered data to the underlying file.
FileStream(const String &path, FileMode mode, FileAccess access, FileShare share, int32_t buffer_size, bool useAsync)
Constructs a new instance of FileStream class and initializes it with the specified parameters.
void Write(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t count) override
Writes the specified subrange of bytes from the specified byte array to the stream.
TaskPtr WriteAsync(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count, const Threading::CancellationToken &cancellationToken) override
Asynchronously writes a sequence of bytes to the current stream, advances the current position within...
void Flush(bool flush_to_disk)
Clears this stream's buffers and writes all buffered data to the underlying file. Synonym for method ...
int64_t Seek(int64_t offset, SeekOrigin origin) override
Sets the position of the stream represented by the current object.
void Close() override
Closes the current FileStream object.
FileStream & operator=(const FileStream &)=delete
void Write(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count) override
Writes the specified subrange of bytes from the specified byte array to the stream.
bool get_CanSeek() const override
Determines if the stream supports seeking.
RTaskPtr< int32_t > ReadAsync(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count, const Threading::CancellationToken &cancellationToken) override
Asynchronously reads a sequence of bytes from the current stream, advances the position within the st...
int64_t get_Length() const override
Returns the length of the stream in bytes.
~FileStream()
Destructor.
void WriteByte(uint8_t value) override
Writes the specified unsigned 8-bit integer value to the stream.
int32_t Read(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
int64_t get_Position() const override
Returns the current position of the stream.
bool get_CanWrite() const override
Determines if the stream is writable.
int32_t Read(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t count) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
FileStream(const String &path, FileMode mode)
Constructs a new instance of FileStream class and initializes it with the specified parameters.
FileStream(const String &path, FileMode mode, FileAccess access, FileShare share=FileShare::Read, int32_t buffer_size=DefaultBufferSize, FileOptions options=FileOptions::SequentialScan)
Constructs a new instance of FileStream class and initializes it with the specified parameters.
void SetLength(int64_t value) override
Sets the length of the stream represented by the current object.
A base class for a variety of stream implementations. Objects of this class should only be allocated ...
Definition: stream.h:24
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Propagates notification that operations should be canceled. This class provides a mechanism for coope...
Definition: cancellation_token.h:43
FileOptions
Represents advanced options for creating FileStream object.
Definition: file_options.h:12
@ SequentialScan
The file shoud be accesses sequentially.
FileAccess
Specifies the type of access when opening the file.
Definition: file_access.h:11
FileShare
Specifies what kind of access other FileStream objects can have to a file being opened.
Definition: file_share.h:11
@ Read
Read-only access.
FileMode
Specifies how a file should be opened.
Definition: file_mode.h:10
SeekOrigin
Specifies the reference position in the stream relative to which the position to seek to is specified...
Definition: seekorigin.h:11
Definition: db_command.h:9