xtd 0.2.0
Loading...
Searching...
No Matches
binary_writer.h
Go to the documentation of this file.
1
4#pragma once
5#define __XTD_STD_INTERNAL__
6#include "../internal/__xtd_std_version.h"
7#undef __XTD_STD_INTERNAL__
8#include "../optional.h"
9#include "../object.h"
10#include "../string.h"
11#include <fstream>
12#include <array>
13#include <vector>
14
16namespace xtd {
18 namespace io {
43 public:
45
51 explicit binary_writer(const xtd::string& path);
54 explicit binary_writer(std::ostream& stream);
57 binary_writer(const binary_writer&) = delete;
58 binary_writer& operator =(const binary_writer&) = delete;
61
63
68 std::optional<std::reference_wrapper<std::ostream>> base_stream() const;
70
72
75 virtual void close();
76
79 virtual void flush();
80
87 virtual size_t seek(size_t offset, std::ios::seekdir origin);
88
93 virtual void write(bool value);
94
99 virtual void write(xtd::byte value);
100
105 virtual void write(char value);
106
111 template<size_t size>
112 void write(const std::array<xtd::byte, size>& buffer) {
113 for (auto b : buffer)
114 write(b);
115 }
116
121 template<size_t size>
122 void write(const std::array<char, size>& buffer) {
123 for (auto c : buffer)
124 write(c);
125 }
126
131 virtual void write(const std::vector<xtd::byte>& buffer);
132
140 virtual void write(const std::vector<xtd::byte>& buffer, size_t index, size_t count);
141
146 virtual void write(const std::vector<char>& buffer);
147
155 virtual void write(const std::vector<char>& buffer, size_t index, size_t count);
156
161 virtual void write(double value);
162
167 virtual void write(int16 value);
168
173 virtual void write(int32 value);
174
179 virtual void write(int64 value);
180
185 virtual void write(sbyte value);
186
191 virtual void write(float value);
192
197 virtual void write(const string& value);
199 virtual void write(const std::string& value);
200#if defined(__xtd__cpp_lib_char8_t)
201 virtual void write(const std::u8string& value);
202#endif
203 virtual void write(const std::u16string& value);
204 virtual void write(const std::u32string& value);
205 virtual void write(const std::wstring& value);
206 virtual void write(const char* value);
207#if defined(__xtd__cpp_lib_char8_t)
208 virtual void write(const char8* value);
209#endif
210 virtual void write(const char16* value);
211 virtual void write(const char32* value);
212 virtual void write(const wchar* value);
214
219 virtual void write(uint16 value);
220
225 virtual void write(uint32 value);
226
231 virtual void write(uint64 value);
233
235 binary_writer& operator <<(bool value) {write(value); return *this;}
236 binary_writer& operator <<(byte value) {write(value); return *this;}
237 binary_writer& operator <<(char value) {write(value); return *this;}
238 template<size_t size>
239 binary_writer& operator <<(const std::array<xtd::byte, size>& value) {write(value); return *this;}
240 template<size_t size>
241 binary_writer& operator <<(const std::array<char, size>& value) {write(value); return *this;}
242 binary_writer& operator <<(const std::vector<xtd::byte>& value) {write(value); return *this;}
243 binary_writer& operator <<(const std::vector<char>& value) {write(value); return *this;}
244 binary_writer& operator <<(double value) {write(value); return *this;}
245 binary_writer& operator <<(int16 value) {write(value); return *this;}
246 binary_writer& operator <<(int32 value) {write(value); return *this;}
247 binary_writer& operator <<(int64 value) {write(value); return *this;}
248 binary_writer& operator <<(sbyte value) {write(value); return *this;}
249 binary_writer& operator <<(float value) {write(value); return *this;}
250 binary_writer& operator <<(const string& value) {write(value); return *this;}
251 binary_writer& operator <<(const std::string& value) {write(value); return *this;}
252#if defined(__xtd__cpp_lib_char8_t)
253 binary_writer& operator <<(const std::u8string& value) {write(value); return *this;}
254#endif
255 binary_writer& operator <<(const std::u16string& value) {write(value); return *this;}
256 binary_writer& operator <<(const std::u32string& value) {write(value); return *this;}
257 binary_writer& operator <<(const std::wstring& value) {write(value); return *this;}
258 binary_writer& operator <<(const char* value) {write(value); return *this;}
259#if defined(__xtd__cpp_lib_char8_t)
260 binary_writer& operator <<(const char8* value) {write(value); return *this;}
261#endif
262 binary_writer& operator <<(const char16* value) {write(value); return *this;}
263 binary_writer& operator <<(const char32* value) {write(value); return *this;}
264 binary_writer& operator <<(const wchar* value) {write(value); return *this;}
265 binary_writer& operator <<(uint16 value) {write(value); return *this;}
266 binary_writer& operator <<(uint32 value) {write(value); return *this;}
267 binary_writer& operator <<(uint64 value) {write(value); return *this;}
269
270 private:
271 std::ostream* stream_ = nullptr;
272 bool delete_when_destroy_ = false;
273 };
274 }
275}
Represents text as a sequence of character units.
Definition basic_string.h:79
Writes primitive types in binary to a stream and supports writing strings.
Definition binary_writer.h:42
virtual void flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlyin...
virtual void write(int64 value)
Writes a eight-byte signed integer to the current stream and advances the stream position by eight by...
virtual void write(const std::vector< char > &buffer)
Writes a character array to the underlying stream.
void write(const std::array< xtd::byte, size > &buffer)
Writes a byte array to the underlying stream.
Definition binary_writer.h:112
virtual void write(const std::vector< xtd::byte > &buffer)
Writes a byte array to the underlying stream.
virtual void write(int16 value)
Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.
virtual void write(double value)
Writes an eight-byte floating-point value to the current stream and advances the stream position by e...
virtual void write(const std::vector< char > &buffer, size_t index, size_t count)
Writes a region of a character array to the current stream.
binary_writer(const xtd::string &path)
Initializes a new instance of the binary_writer class for the specified file name.
void write(const std::array< char, size > &buffer)
Writes a character array to the underlying stream.
Definition binary_writer.h:122
virtual size_t seek(size_t offset, std::ios::seekdir origin)
Sets the position within the current stream.
virtual void write(uint64 value)
Writes a eight-byte unsigned integer to the current stream and advances the stream position by eight ...
virtual void write(uint32 value)
Writes a four-byte unsigned integer to the current stream and advances the stream position by four by...
virtual void write(char value)
Writes a character to the current stream and advances the current position by one byte.
std::optional< std::reference_wrapper< std::ostream > > base_stream() const
Returns the underlying stream.
virtual void close()
Closes the xtd::io::binary_writer object and the underlying stream, and releases any system resources...
virtual void write(const std::vector< xtd::byte > &buffer, size_t index, size_t count)
Writes a region of a byte array to the current stream.
virtual void write(bool value)
Writes a one-byte boolean value to the current stream, with 0 representing false and 1 representing t...
virtual void write(xtd::byte value)
Writes an unsigned byte to the current stream and advances the stream position by one byte.
virtual void write(uint16 value)
Writes a two-byte unsigned integer to the current stream and advances the stream position by two byte...
binary_writer(std::ostream &stream)
Initializes a new instance of the binary_writer class for the specified stream.
virtual void write(int32 value)
Writes a four-byte signed integer to the current stream and advances the stream position by four byte...
virtual void write(sbyte value)
Writes an signed byte to the current stream and advances the stream position by one byte.
virtual void write(float value)
Writes an four-byte floating-point value to the current stream and advances the stream position by fo...
virtual void write(const string &value)
Writes a length-prefixed string to this stream, and advances the current position of the stream and t...
Performs operations on std::basic_string instances that contain file or directory path information....
Definition path.h:36
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
#define core_export_
Define shared library export.
Definition core_export.h:13
int16_t int16
Represents a 16-bit signed integer.
Definition int16.h:23
char8_t char8
Represents a 8-bit unicode character.
Definition char8.h:27
wchar_t wchar
Represents a wide character.
Definition wchar.h:24
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.h:23
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.h:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.h:26
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.h:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.h:26
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.h:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.h:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.h:23
@ write
Write access to the file. Data can be written to the file. Combine with Read for read/write access.
@ c
The C key.
@ b
The B key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10