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
50 ASPOSECPP_SHARED_API ~FileStream();
51
52 FileStream(const FileStream&) = delete;
53 FileStream& operator=(const FileStream&) = delete;
54
57 ASPOSECPP_SHARED_API bool get_CanRead() const override;
58
61 ASPOSECPP_SHARED_API bool get_CanSeek() const override;
62
65 ASPOSECPP_SHARED_API bool get_CanWrite() const override;
66
68 ASPOSECPP_SHARED_API int64_t get_Length() const override;
69
71 ASPOSECPP_SHARED_API String get_Name() const;
72
75 ASPOSECPP_SHARED_API void set_Position(int64_t value) override;
76
78 ASPOSECPP_SHARED_API int64_t get_Position() const override;
79
81 ASPOSECPP_SHARED_API void Close() override;
82
84 ASPOSECPP_SHARED_API void Flush() override;
85
89 ASPOSECPP_SHARED_API void Flush(bool flush_to_disk);
90
93 ASPOSECPP_SHARED_API int32_t ReadByte() override;
94
100 ASPOSECPP_SHARED_API int32_t Read(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count) override;
101
106 ASPOSECPP_SHARED_API int64_t Seek(int64_t offset, SeekOrigin origin) override;
107
110 ASPOSECPP_SHARED_API void SetLength(int64_t value) override;
111
114 ASPOSECPP_SHARED_API void WriteByte(uint8_t value) override;
115
120 ASPOSECPP_SHARED_API void Write(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count) override;
121
127 ASPOSECPP_SHARED_API int32_t Read(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count) override;
128
133 ASPOSECPP_SHARED_API void Write(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count) override;
134
135private:
137 std::unique_ptr<Details::FileWrapper> m_file;
138
140 String m_path;
141
143 const FileMode m_mode; // Used only for debugging
144
146 const FileAccess m_access;
147
149 const FileShare m_share; // Used only for debugging
150
152 const FileOptions m_options; // Used only for debugging
153
155 std::vector<uint8_t> m_buffer;
156
158 const int32_t m_buffer_size;
159
161 int32_t m_write_pos = 0;
162
164 int32_t m_read_pos = 0;
165
167 int32_t m_read_length = 0;
168
170 int64_t m_file_pos = 0;
171
173 int64_t m_file_start_pos = 0;
174
175 void VerifyIntegrity() const;
176 void VerifyOpen() const;
177 void VerifyReadable() const;
178 void VerifyWriteable() const;
179 void VerifySeekable() const;
180
182 void FlushReadBuffer();
183
185 void FlushWriteBuffer();
186
188 void FlushInternalBuffers();
189
191 void FillReadBuffer();
192
194 void CloseInternal();
195};
196
197}} // 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.
FileStream(const FileStream &)=delete
void Flush() override
Clears this stream's buffers and writes all buffered data to the underlying file.
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.
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.
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
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
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