CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
stream_writer.h
1
2#ifndef __StreamWriter_h__
3#define __StreamWriter_h__
4
5#include "system/io/text_writer.h"
6#include "system/text/encoding.h"
7
8#include "fwd.h"
9
10namespace System { namespace IO {
11
12 class Stream;
17 class ASPOSECPP_SHARED_CLASS StreamWriter : public TextWriter
18 {
19 public:
24
28 ASPOSECPP_SHARED_API StreamWriter(const SharedPtr<Stream>& stream);
33 ASPOSECPP_SHARED_API StreamWriter(const SharedPtr<Stream>& stream, const EncodingPtr& encoding);
41 ASPOSECPP_SHARED_API StreamWriter(const SharedPtr<Stream>& stream, const EncodingPtr& encoding, int buffer_size, bool leave_open = false);
42
46 ASPOSECPP_SHARED_API StreamWriter(const String& path);
54 ASPOSECPP_SHARED_API StreamWriter(const String& path, bool append, const EncodingPtr& encoding = System::Text::Encoding::get_UTF8Unmarked());
63 ASPOSECPP_SHARED_API StreamWriter(const String& path, bool append, const EncodingPtr& encoding, int buffer_size);
64
66 ASPOSECPP_SHARED_API ~StreamWriter();
67
70 ASPOSECPP_SHARED_API bool get_AutoFlush() const;
73 ASPOSECPP_SHARED_API void set_AutoFlush(bool value);
75 ASPOSECPP_SHARED_API SharedPtr<Stream> get_BaseStream() const;
77 ASPOSECPP_SHARED_API EncodingPtr get_Encoding() override;
78
81 ASPOSECPP_SHARED_API void Write(char_t value) override;
84 ASPOSECPP_SHARED_API void Write(const String &value) override;
87 ASPOSECPP_SHARED_API void Write(const SharedPtr<Object>& obj) override;
88
91 ASPOSECPP_SHARED_API void Write(const ArrayPtr<char_t>& buffer) override;
96 ASPOSECPP_SHARED_API void Write(const ArrayPtr<char_t>& buffer, int32_t index, int32_t count) override;
99 ASPOSECPP_SHARED_API void Write(const char_t* buffer) override;
100
102 ASPOSECPP_SHARED_API void WriteLine() override;
105 ASPOSECPP_SHARED_API void WriteLine(const String &value) override;
108 ASPOSECPP_SHARED_API void WriteLine(const SharedPtr<Object>& obj) override;
111 ASPOSECPP_SHARED_API void WriteLine(const ArrayPtr<char_t>& buffer) override;
116 ASPOSECPP_SHARED_API void WriteLine(const ArrayPtr<char_t>& buffer, int32_t index, int32_t count) override;
119 ASPOSECPP_SHARED_API void WriteLine(const char_t* buffer) override { Write(buffer); WriteLine(); }
120
124 template <typename T>
126 {
127 Write(obj->ToString());
128 }
129
133 template <typename T>
135 {
136 WriteLine(obj->ToString());
137 }
138
140
142 ASPOSECPP_SHARED_API void Close() override;
145 ASPOSECPP_SHARED_API void Flush() override;
146
147 protected:
150 ASPOSECPP_SHARED_API void Dispose(bool disposing) override;
151
152 private:
155 void FlushCore();
158 void FlushBytes();
160 void Decode();
162 void CheckState() const;
163
168 void LowLevelWrite (const char_t* first, const char_t* last);
169 void LowLevelWrite (std::vector<char_t>::const_iterator first, std::vector<char_t>::const_iterator last);
170
174 void Initialize(const EncodingPtr& encoding, int buffer_size);
175
178 bool m_flush{};
180 bool m_preamble_done{};
182 ArrayPtr<uint8_t> m_byte_buf;
184 ArrayPtr<char_t> m_decode_buf;
186 int m_byte_pos{};
188 int m_decode_pos{};
190 bool m_leave_open{};
191
193 SharedPtr<Stream> m_internal_stream;
195 EncodingPtr m_internal_encoding;
196
197 protected:
198#ifdef ASPOSE_GET_SHARED_MEMBERS
201 ASPOSECPP_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
202#endif
203
204#ifdef __DBG_FOR_EACH_MEMBER
205 public:
206 ASPOSECPP_SHARED_API void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override;
207 const char* DBG_class_name() const override { return "StreamWriter"; }
208#endif
209 };
210
211}}
212
213#endif
Represents a writer that writes characters to a byte stream. Objects of this class should only be all...
Definition: stream_writer.h:18
void Close() override
Closes the stream and releases aquired resources.
StreamWriter(const SharedPtr< Stream > &stream, const EncodingPtr &encoding, int buffer_size, bool leave_open=false)
Constructs an instance of StreamWriter object that writes characters to the specified underlying stre...
void WriteLine(const ArrayPtr< char_t > &buffer) override
Writes all characetrs from the specified array followed by the line-terminating characters to the str...
void Write(const String &value) override
Writes the specified string to the stream.
void Dispose(bool disposing) override
Releases all resources used by the current object and closes the underlying stream.
void Write(char_t value) override
Writes the specified character to the stream.
void Flush() override
Flushes the content of the buffer to the underlying stream and then flushes the underlying stream.
bool get_AutoFlush() const
Returns a value that indicates whether the StreamWriter will flush the data to the underlying stream ...
SharedPtr< Stream > get_BaseStream() const
Returns a shared pointer to an object that represents the underlying stream.
void Write(const ArrayPtr< char_t > &buffer) override
Writes all characetrs from the specified array to the stream.
StreamWriter(const String &path)
Constructs an instance of StreamWriter object that writes characters to the specified file using UTF-...
EncodingPtr get_Encoding() override
Returns the currently used encoding.
void Write(const char_t *buffer) override
Writes the specified c-string to the stream.
void WriteLine(const SharedPtr< Object > &obj) override
Writes the string representation of the specified object followed by the line-terminating characters ...
StreamWriter(const String &path, bool append, const EncodingPtr &encoding=System::Text::Encoding::get_UTF8Unmarked())
Constructs an instance of StreamWriter object that writes characters to the specified file using the ...
void set_AutoFlush(bool value)
Returns a value that specifies whether the StreamWriter should flush the data to the underlying strea...
~StreamWriter()
Destructor.
StreamWriter(const SharedPtr< Stream > &stream)
Constructs an instance of StreamWriter object that writes characters to the specified underlying stre...
StreamWriter(const SharedPtr< Stream > &stream, const EncodingPtr &encoding)
Constructs an instance of StreamWriter object that writes characters to the specified underlying stre...
void WriteLine(const System::SharedPtr< T > &obj)
Writes the string representation of the specified object followed by the line-terminating characters ...
Definition: stream_writer.h:134
void WriteLine(const char_t *buffer) override
Writes the specified c-string followed by the line-terminating characters to the stream.
Definition: stream_writer.h:119
void Write(const SharedPtr< Object > &obj) override
Writes the string representation of the specified object to the stream.
void WriteLine(const String &value) override
Writes the specified string followed by the line-terminating characters to the stream.
void Write(const ArrayPtr< char_t > &buffer, int32_t index, int32_t count) override
Writes the specified subrange of UTF-16 characters from the specified character array to the stream.
StreamWriter(const String &path, bool append, const EncodingPtr &encoding, int buffer_size)
Constructs an instance of StreamWriter object that writes characters to the specified file using the ...
void Write(const System::SharedPtr< T > &obj)
Writes the string representation of the specified object to the stream.
Definition: stream_writer.h:125
void WriteLine() override
Writes line terminator characters to the stream.
void WriteLine(const ArrayPtr< char_t > &buffer, int32_t index, int32_t count) override
Writes the specified subrange of UTF-16 characters from the specified character array followed by the...
A base class for classes that represent writers that writes sequences of characters to different dest...
Definition: text_writer.h:21
virtual void Dispose() override
Releases all resources used by the current object and closes the undelying stream.
Definition: text_writer.h:43
virtual void WriteLine()
Writes line terminator characters to the stream.
virtual void Write(const SharedPtr< Object > &value)
Writes the string representation of the specified object to the stream.
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
static EncodingPtr get_UTF8Unmarked()
Only internal, to be used by the class libraries: Unmarked and non-input-validating.
@ Stream
The type that supports reliable, two-way, connection-based byte streams without duplication of data a...
Definition: db_command.h:9
System::SmartPtr< System::Text::Encoding > EncodingPtr
An alias for a smart pointer that points to an instance of System::Text::Encoding class.
Definition: fwd.h:86