xtd 0.2.0
Loading...
Searching...
No Matches
binary_reader.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../array.hpp"
6#include "../optional.hpp"
7#include "../object.hpp"
8#include "../string.hpp"
9#include <iostream>
10#include <fstream>
11#include <vector>
12#include <stack>
13
15namespace xtd {
17 namespace io {
44 public:
46
52 explicit binary_reader(const xtd::string& path);
59 explicit binary_reader(std::istream& stream);
62 binary_reader(const binary_reader&) = delete;
63 auto operator =(const binary_reader&) -> binary_reader& = delete;
66
68
74 [[nodiscard]] auto base_stream() const -> std::optional<xtd::ref<std::istream>>;
75
78 [[nodiscard]] auto end_of_stream() const -> bool;
80
82
85 auto close() -> void;
86
91 [[nodiscard]] auto peek_char() const -> xtd::int32;
92
94 auto pop() -> std::streampos;
95
98 auto push(std::streampos pos = 0) -> void;
99
105 [[nodiscard]] virtual auto read() -> xtd::int32;
106
116 virtual auto read(xtd::array<xtd::byte>& buffer, xtd::size index, xtd::size count) -> xtd::size;
117
126 virtual auto read(xtd::array<char>& buffer, xtd::size index, xtd::size count) -> xtd::size;
127
134 [[nodiscard]] virtual auto read_boolean() -> bool;
135
142 [[nodiscard]] virtual auto read_byte() -> xtd::byte;
143
151 [[nodiscard]] virtual auto read_bytes(xtd::size count) -> xtd::array<xtd::byte>;
152
159 [[nodiscard]] virtual auto read_char() -> char;
160
168 [[nodiscard]] virtual auto read_chars(xtd::size count) -> xtd::array<char>;
169
176 [[nodiscard]] virtual auto read_double() -> double;
177
184 [[nodiscard]] virtual auto read_int16() -> xtd::int16;
185
192 [[nodiscard]] virtual auto read_int32() -> xtd::int32;
193
200 [[nodiscard]] virtual auto read_int64() -> xtd::int64;
201
208 [[nodiscard]] virtual auto read_sbyte() -> xtd::sbyte;
209
216 [[nodiscard]] virtual auto read_single() -> float;
217
224 [[nodiscard]] virtual auto read_size() -> xtd::size;
225
232 [[nodiscard]] virtual auto read_string() -> xtd::string;
233
240 [[nodiscard]] virtual auto read_uint16() -> xtd::uint16;
241
248 [[nodiscard]] virtual auto read_uint32() -> xtd::uint32;
249
256 [[nodiscard]] virtual auto read_uint64() -> xtd::uint64;
257
259 auto rewind() -> void;
260
264 virtual auto seek(std::streamoff off, std::ios_base::seekdir dir = std::ios_base::cur) -> void;
265
268 [[nodiscard]] auto tell() -> std::streampos;
270
272 auto operator >>(bool& value) -> binary_reader& {value = read_boolean(); return *this;}
273 auto operator >>(xtd::byte& value) -> binary_reader& {value = read_byte(); return *this;}
274 auto operator >>(char& value) -> binary_reader& {value = read_char(); return *this;}
275 auto operator >>(double& value) -> binary_reader& {value = read_double(); return *this;}
276 auto operator >>(int16& value) -> binary_reader& {value = read_int16(); return *this;}
277 auto operator >>(int32& value) -> binary_reader& {value = read_int32(); return *this;}
278 auto operator >>(int64& value) -> binary_reader& {value = read_int64(); return *this;}
279 auto operator >>(sbyte& value) -> binary_reader& {value = read_sbyte(); return *this;}
280 auto operator >>(float& value) -> binary_reader& {value = read_single(); return *this;}
281 auto operator >>(string& value) -> binary_reader& {value = read_string(); return *this;}
282 auto operator >>(uint16& value) -> binary_reader& {value = read_uint16(); return *this;}
283 auto operator >>(uint32& value) -> binary_reader& {value = read_uint32(); return *this;}
284 auto operator >>(uint64& value) -> binary_reader& {value = read_uint64(); return *this;}
286
287 private:
288 [[nodiscard]] auto read_7bit_encoded_int() -> int32;
289 std::istream* stream_ = nullptr;
290 std::stack<std::streampos> pos_stack_;
291 bool delete_when_destroy_ = false;
292 };
293 }
294}
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Reads primitive data types as binary values in a specific encoding.
Definition binary_reader.hpp:43
binary_reader(const xtd::string &path)
Initializes a new instance of the xtd::io::binary_reader class for the specified file name.
auto pop() -> std::streampos
Pop the current top position.
virtual auto read_uint32() -> xtd::uint32
Reads a 4-byte unsigned integer from the current stream and advances the current position of the stre...
auto peek_char() const -> xtd::int32
Returns the next available character and does not advance the byte or character position.
virtual auto read() -> xtd::int32
Reads characters from the underlying stream and advances the current position of the stream in accord...
binary_reader(std::istream &stream)
Initializes a new instance of the xtd::io::binary_reader class for the specified stream.
virtual auto read_byte() -> xtd::byte
Reads the next byte from the current stream and advances the current position of the stream by one by...
virtual auto read_sbyte() -> xtd::sbyte
Reads the a signed byte from the current stream and advances the current position of the stream by on...
virtual auto read_chars(xtd::size count) -> xtd::array< char >
Reads the specified number of characters from the current stream into a byte array and advances the c...
virtual auto read_int16() -> xtd::int16
Reads a 2-byte signed integer from the current stream and advances the current position of the stream...
virtual auto read_char() -> char
Reads the next character from the current stream and advances the current position of the stream by o...
virtual auto read_single() -> float
Reads an 4-byte floating point value from the current stream and advances the current position of the...
auto rewind() -> void
Rewind stream.
virtual auto read_int64() -> xtd::int64
Reads a 8-byte signed integer from the current stream and advances the current position of the stream...
virtual auto read_string() -> xtd::string
Reads a string from the current stream. The string is prefixed with the length.
virtual auto read_uint64() -> xtd::uint64
Reads a 8-byte unsigned integer from the current stream and advances the current position of the stre...
auto base_stream() const -> std::optional< xtd::ref< std::istream > >
Returns the underlying stream.
auto close() -> void
Closes the xtd::io::binary_reader object and the underlying stream, and releases any system resources...
virtual auto read_int32() -> xtd::int32
Reads a 4-byte signed integer from the current stream and advances the current position of the stream...
auto tell() -> std::streampos
Tell the current seek position of the readers stream;.
virtual auto read_uint16() -> xtd::uint16
Reads a 2-byte unsigned integer from the current stream and advances the current position of the stre...
virtual auto read_double() -> double
Reads an 8-byte floating point value from the current stream and advances the current position of the...
auto end_of_stream() const -> bool
Gets a value that indicates whether the current stream position is at the end of the stream.
virtual auto seek(std::streamoff off, std::ios_base::seekdir dir=std::ios_base::cur) -> void
Change the position of the readers stream.
virtual auto read_boolean() -> bool
Reads a boolean value from the current stream and advances the current position of the stream by one ...
auto push(std::streampos pos=0) -> void
Push the current position.
virtual auto read_size() -> xtd::size
Reads a xtd::size from the current stream and advances the current position of the stream by eight by...
virtual auto read_bytes(xtd::size count) -> xtd::array< xtd::byte >
Reads the specified number of bytes from the current stream into a byte array and advances the curren...
Performs operations on std::basic_string instances that contain file or directory path information....
Definition path.hpp:37
Provides a generic view of a sequence of bytes. This is an abstract class.
Definition stream.hpp:40
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
std::uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
std::uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
xtd::reference_wrapper_object< type_t > ref
The xtd::ref object is a reference wrapper.
Definition ref.hpp:25
std::int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
std::optional< type_t > optional
Represents the optional alias on std::optional.
Definition optional.hpp:26
std::uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
std::uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::object class.
Contains xtd::optional type.
Contains xtd::string alias.