xtd 0.2.0
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 {
42 public:
44
50 explicit binary_reader(const xtd::string& path);
57 explicit binary_reader(std::istream& stream);
60 binary_reader(const binary_reader&) = delete;
61 binary_reader& operator =(const binary_reader&) = delete;
64
66
72 std::optional<xtd::ref<std::istream>> base_stream() const;
73
76 bool end_of_stream() const;
78
80
83 void close();
84
90
92 std::streampos pop();
93
96 void push(std::streampos pos = 0);
97
103 virtual int32 read();
104
114 virtual size_t read(xtd::array<xtd::byte>& buffer, size_t index, size_t count);
115
124 virtual size_t read(xtd::array<char>& buffer, size_t index, size_t count);
125
132 virtual bool read_boolean();
133
141
149 virtual xtd::array<xtd::byte> read_bytes(size_t count);
150
157 virtual char read_char();
158
166 virtual xtd::array<char> read_chars(size_t count);
167
174 virtual double read_double();
175
182 virtual int16 read_int16();
183
190 virtual int32 read_int32();
191
198 virtual int64 read_int64();
199
206 virtual sbyte read_sbyte();
207
214 virtual float read_single();
215
223
230 virtual string read_string();
231
239
247
255
257 void rewind();
258
262 void seekg(std::streamoff off, std::ios_base::seekdir dir = std::ios_base::cur);
263
266 std::streampos tellg();
268
270 binary_reader& operator >>(bool& value) {value = read_boolean(); return *this;}
271 binary_reader& operator >>(xtd::byte& value) {value = read_byte(); return *this;}
272 binary_reader& operator >>(char& value) {value = read_char(); return *this;}
273 binary_reader& operator >>(double& value) {value = read_double(); return *this;}
274 binary_reader& operator >>(int16& value) {value = read_int16(); return *this;}
275 binary_reader& operator >>(int32& value) {value = read_int32(); return *this;}
276 binary_reader& operator >>(int64& value) {value = read_int64(); return *this;}
277 binary_reader& operator >>(sbyte& value) {value = read_sbyte(); return *this;}
278 binary_reader& operator >>(float& value) {value = read_single(); return *this;}
279 binary_reader& operator >>(string& value) {value = read_string(); return *this;}
280 binary_reader& operator >>(uint16& value) {value = read_uint16(); return *this;}
281 binary_reader& operator >>(uint32& value) {value = read_uint32(); return *this;}
282 binary_reader& operator >>(uint64& value) {value = read_uint64(); return *this;}
284
285 private:
286 int32 read_7bit_encoded_int();
287 std::istream* stream_ = nullptr;
288 std::stack<std::streampos> pos_stack_;
289 bool delete_when_destroy_ = false;
290 };
291 }
292}
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
Reads primitive data types as binary values in a specific encoding.
Definition binary_reader.hpp:41
binary_reader(const xtd::string &path)
Initializes a new instance of the xtd::io::binary_reader class for the specified file name.
virtual bool read_boolean()
Reads a boolean value from the current stream and advances the current position of the stream by one ...
void seekg(std::streamoff off, std::ios_base::seekdir dir=std::ios_base::cur)
Change the position of the readers stream.
void close()
Closes the xtd::io::binary_reader object and the underlying stream, and releases any system resources...
void push(std::streampos pos=0)
Push the current position.
virtual float read_single()
Reads an 4-byte floating point value from the current stream and advances the current position of the...
virtual double read_double()
Reads an 8-byte floating point value from the current stream and advances the current position of the...
virtual uint32 read_uint32()
Reads a 4-byte unsigned integer from the current stream and advances the current position of the stre...
virtual uint64 read_uint64()
Reads a 8-byte unsigned integer from the current stream and advances the current position of the stre...
virtual sbyte read_sbyte()
Reads the a signed byte from the current stream and advances the current position of the stream by on...
binary_reader(std::istream &stream)
Initializes a new instance of the xtd::io::binary_reader class for the specified stream.
virtual int16 read_int16()
Reads a 2-byte signed integer from the current stream and advances the current position of the stream...
void rewind()
Rewind stream.
virtual xtd::byte read_byte()
Reads the next byte from the current stream and advances the current position of the stream by one by...
virtual xtd::array< xtd::byte > read_bytes(size_t count)
Reads the specified number of bytes from the current stream into a byte array and advances the curren...
virtual xtd::array< char > read_chars(size_t count)
Reads the specified number of characters from the current stream into a byte array and advances the c...
virtual uint16 read_uint16()
Reads a 2-byte unsigned integer from the current stream and advances the current position of the stre...
bool end_of_stream() const
Gets a value that indicates whether the current stream position is at the end of the stream.
virtual char read_char()
Reads the next character from the current stream and advances the current position of the stream by o...
virtual size_t read(xtd::array< xtd::byte > &buffer, size_t index, size_t count)
Reads the specified number of bytes from the stream, starting from a specified point in the byte arra...
int32 peek_char() const
Returns the next available character and does not advance the byte or character position.
virtual size_t read(xtd::array< char > &buffer, size_t index, size_t count)
Reads the specified number of characters from the stream, starting from a specified point in the char...
virtual string read_string()
Reads a string from the current stream. The string is prefixed with the length.
virtual int32 read_int32()
Reads a 4-byte signed integer from the current stream and advances the current position of the stream...
std::streampos pop()
Pop the current top position.
virtual xtd::size read_size()
Reads a xtd::size from the current stream and advances the current position of the stream by eight by...
virtual int32 read()
Reads characters from the underlying stream and advances the current position of the stream in accord...
virtual int64 read_int64()
Reads a 8-byte signed integer from the current stream and advances the current position of the stream...
std::streampos tellg()
Tell the current seek position of the readers stream;.
std::optional< xtd::ref< std::istream > > base_stream() const
Returns the underlying stream.
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:44
#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
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.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.