xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
binary_reader.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include <fstream>
7 #include <optional>
8 #include <vector>
9 #include "../object.h"
10 #include "../ustring.h"
11 
13 namespace xtd {
15  namespace io {
35  class core_export_ binary_reader : public xtd::object {
36  public:
38 
44  explicit binary_reader(const xtd::ustring& path);
51  explicit binary_reader(std::istream& stream);
54  binary_reader(const binary_reader&) = delete;
55  binary_reader& operator=(const binary_reader&) = delete;
56  ~binary_reader();
58 
60 
66  std::optional<std::reference_wrapper<std::istream>> base_stream() const;
67 
70  bool end_of_stream() const;
72 
74 
77  void close();
78 
83  int32_t peek_char() const;
84 
90  virtual int32_t read();
91 
101  virtual size_t read(std::vector<byte_t>& buffer, size_t index, size_t count);
102 
111  virtual size_t read(std::vector<char>& buffer, size_t index, size_t count);
112 
119  virtual bool read_boolean();
120 
127  virtual byte_t read_byte();
128 
136  virtual std::vector<byte_t> read_bytes(size_t count);
137 
144  virtual char read_char();
145 
153  virtual std::vector<char> read_chars(size_t count);
154 
161  virtual double read_double();
162 
169  virtual int16_t read_int16();
170 
177  virtual int32_t read_int32();
178 
185  virtual int64_t read_int64();
186 
193  virtual sbyte_t read_sbyte();
194 
201  virtual float read_single();
202 
209  virtual ustring read_string();
210 
217  virtual uint16_t read_uint16();
218 
225  virtual uint32_t read_uint32();
226 
233  virtual uint64_t read_uint64();
235 
237  binary_reader& operator>>(bool& value) {value = read_boolean(); return *this;}
238  binary_reader& operator>>(byte_t& value) {value = read_byte(); return *this;}
239  binary_reader& operator>>(char& value) {value = read_char(); return *this;}
240  binary_reader& operator>>(double& value) {value = read_double(); return *this;}
241  binary_reader& operator>>(int16_t& value) {value = read_int16(); return *this;}
242  binary_reader& operator>>(int32_t& value) {value = read_int32(); return *this;}
243  binary_reader& operator>>(int64_t& value) {value = read_int64(); return *this;}
244  binary_reader& operator>>(sbyte_t& value) {value = read_sbyte(); return *this;}
245  binary_reader& operator>>(float& value) {value = read_single(); return *this;}
246  binary_reader& operator>>(ustring& value) {value = read_string(); return *this;}
247  binary_reader& operator>>(uint16_t& value) {value = read_uint16(); return *this;}
248  binary_reader& operator>>(uint32_t& value) {value = read_uint32(); return *this;}
249  binary_reader& operator>>(uint64_t& value) {value = read_uint64(); return *this;}
251 
252  private:
253  std::istream* stream_ = nullptr;
254  bool delete_when_destroy_ = false;
255  };
256  }
257 }
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
Performs operations on std::basic_string instances that contain file or directory path information...
Definition: path.h:32
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
Read access to the file. Data can be read from the file. Combine with Write for read/write access...
Reads primitive data types as binary values in a specific encoding.
Definition: binary_reader.h:35