Reads primitive data types as binary values in a specific encoding.
- Inheritance
- xtd::object → xtd::io::binary_reader
- Header
#include <xtd/io/binary_reader>
- Namespace
- xtd::io
- Library
- xtd.core
- Examples
- The following code example demonstrates how to store and retrieve application settings in a file.
#include <xtd/io/binary_reader>
#include <xtd/io/binary_writer>
#include <xtd/io/file>
#include <xtd/console>
#include <xtd/startup>
#include <xtd/using>
using namespace std;
class program {
inline static const ustring file_name =
"app_settings.dat";
public:
static auto main() {
write_default_values();
display_values();
}
static void write_default_values() {
writer.write(R"(c:\Temp)");
writer.write(10);
writer.write(true);
}
}
static void display_values() {
auto aspect_ratio = .0f;
auto auto_save_time = 0;
auto show_status_bar = false;
temp_directory = reader.read_string();
auto_save_time = reader.read_int32();
show_status_bar = reader.read_boolean();
}
}
}
};
- Examples
- The same example with stream operators.
#include <xtd/io/binary_reader>
#include <xtd/io/binary_writer>
#include <xtd/io/file>
#include <xtd/console>
#include <xtd/startup>
#include <xtd/using>
using namespace std;
class program {
inline static const ustring file_name =
"app_settings.dat";
public:
static auto main() {
write_default_values();
display_values();
}
static void write_default_values() {
writer << 1.250F;
writer << R"(c:\Temp)";
writer << 10;
writer << true;
}
}
static void display_values() {
auto aspect_ratio = .0f;
auto auto_save_time = 0;
auto show_status_bar = false;
reader >> aspect_ratio;
reader >> temp_directory;
reader >> auto_save_time;
reader >> show_status_bar;
}
}
}
};
- Examples:
- binary_reader.cpp, binary_reader2.cpp, and binary_reader3.cpp.
|
| void | close () |
| | Closes the xtd::io::binary_reader object and the underlying stream, and releases any system resources associated with the reader. More...
|
| |
| int32 | peek_char () const |
| | Returns the next available character and does not advance the byte or character position. More...
|
| |
| std::streampos | pop () |
| | Pop the current top position. More...
|
| |
| void | push (std::streampos pos=0) |
| | Push the current position. More...
|
| |
| virtual int32 | read () |
| | Reads characters from the underlying stream and advances the current position of the stream in accordance with the Encoding used and the specific character being read from the stream. More...
|
| |
| virtual size_t | read (std::vector< 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 array. More...
|
| |
| virtual size_t | read (std::vector< char > &buffer, size_t index, size_t count) |
| | Reads the specified number of characters from the stream, starting from a specified point in the character array. More...
|
| |
| virtual bool | read_boolean () |
| | Reads a boolean value from the current stream and advances the current position of the stream by one byte. More...
|
| |
| virtual xtd::byte | read_byte () |
| | Reads the next byte from the current stream and advances the current position of the stream by one byte. More...
|
| |
| virtual std::vector< xtd::byte > | read_bytes (size_t count) |
| | Reads the specified number of bytes from the current stream into a byte array and advances the current position by that number of bytes. More...
|
| |
| virtual char | read_char () |
| | Reads the next character from the current stream and advances the current position of the stream by one byte. More...
|
| |
| virtual std::vector< char > | read_chars (size_t count) |
| | Reads the specified number of characters from the current stream into a byte array and advances the current position by that number of bytes. More...
|
| |
| virtual double | read_double () |
| | Reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes. More...
|
| |
| virtual int16 | read_int16 () |
| | Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes. More...
|
| |
| virtual int32 | read_int32 () |
| | Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes. More...
|
| |
| virtual int64 | read_int64 () |
| | Reads a 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes. More...
|
| |
| virtual sbyte | read_sbyte () |
| | Reads the a signed byte from the current stream and advances the current position of the stream by one byte. More...
|
| |
| virtual float | read_single () |
| | Reads an 4-byte floating point value from the current stream and advances the current position of the stream by four bytes. More...
|
| |
| virtual ustring | read_string () |
| | Reads a string from the current stream. The string is prefixed with the length. More...
|
| |
| virtual uint16 | read_uint16 () |
| | Reads a 2-byte unsigned integer from the current stream and advances the current position of the stream by two bytes. More...
|
| |
| virtual uint32 | read_uint32 () |
| | Reads a 4-byte unsigned integer from the current stream and advances the current position of the stream by four bytes. More...
|
| |
| virtual uint64 | read_uint64 () |
| | Reads a 8-byte unsigned integer from the current stream and advances the current position of the stream by eight bytes. More...
|
| |
| void | rewind () |
| | Rewind stream. More...
|
| |
| void | seekg (std::streamoff off, std::ios_base::seekdir dir=std::ios_base::cur) |
| | Change the position of the readers stream. More...
|
| |
| std::streampos | tellg () |
| | Tell the current seek position of the readers stream;. More...
|
| |
|
| | object ()=default |
| | Create a new instance of the ultimate base class object. More...
|
| |
| bool | equals (const object &obj) const noexcept |
| | Determines whether the specified object is equal to the current object. More...
|
| |
| virtual size_t | get_hash_code () const noexcept |
| | Serves as a hash function for a particular type. More...
|
| |
| virtual type_object | get_type () const noexcept |
| | Gets the type of the current instance. More...
|
| |
| template<typename object_t > |
| std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| | Creates a shallow copy of the current object. More...
|
| |
| virtual xtd::ustring | to_string () const noexcept |
| | Returns a sxd::ustring that represents the current object. More...
|
| |
| static bool | equals (const object &object_a, const object &object_b) noexcept |
| | Determines whether the specified object instances are considered equal. More...
|
| |
| static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| | Determines whether the specified object instances are the same instance. More...
|
| |