xtd 1.0.0
Loading...
Searching...
No Matches
stream.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "seek_origin.hpp"
9#include "../core_export.hpp"
10#include "../iasync_result.hpp"
11#include "../span.hpp"
12#include "../string.hpp"
13#include <cstdio>
14#include <sstream>
15
17namespace xtd {
19 namespace io {
21 class null_stream;
23
39 class core_export_ stream : public xtd::abstract_object, public std::iostream {
40 class async_result_stream : public xtd::object, public xtd::iasync_result {
41 public:
42 explicit async_result_stream(const xtd::any_object& async_state) : async_state_(async_state) {}
43 xtd::any_object async_state() const noexcept override {return async_state_;}
44 xtd::threading::wait_handle& async_wait_handle() noexcept override {return async_event_;}
45 bool completed_synchronously() const noexcept override {return false;}
46 bool is_completed() const noexcept override {return is_completed_;};
47
48 xtd::any_object async_state_;
49 bool is_completed_ = false;
51 std::exception_ptr exception_;
52 };
53
54 class streambuf : public std::streambuf {
55 public:
56 explicit streambuf(xtd::io::stream& owner);
57
58 int_type underflow() override;
59 int_type overflow(int_type value) override;
60
61 private:
62 xtd::io::stream& owner_;
63 xtd::byte value_ = 0;
64 char_type* value_ptr_ = reinterpret_cast<char_type*>(&value_);
65 };
66
67 public:
69
72
74
78 static xtd::io::null_stream null_stream;
79
82 inline static constexpr xtd::int32 eof = EOF;
84
86
90 [[nodiscard]] virtual auto can_read() const noexcept -> bool = 0;
91
94 [[nodiscard]] virtual auto can_seek() const noexcept -> bool = 0;
95
99 [[nodiscard]] virtual auto can_timeout() const noexcept -> bool;
100
103 [[nodiscard]] virtual auto can_write() const noexcept -> bool = 0;
104
107 [[nodiscard]] virtual auto is_closed() const noexcept -> bool;
108
112 [[nodiscard]] virtual auto length() const -> xtd::usize = 0;
113
119 [[nodiscard]] virtual auto position() const -> xtd::usize = 0;
125 virtual auto position(xtd::usize value) -> void = 0;
126
132 [[nodiscard]] virtual auto read_timeout() const -> xtd::int32;
138 virtual auto read_timeout(xtd::int32 value) -> void;
139
145 [[nodiscard]] virtual auto write_timeout() const -> xtd::int32;
146
152 virtual auto write_timeout(xtd::int32 value) -> void;
154
156
160 auto copy_to(std::ostream& destination) -> void;
161
165 auto copy_to(std::ostream& destination, xtd::usize buffer_size) -> void;
166
169 virtual auto flush() -> void = 0;
170
171 using std::iostream::read;
174 virtual auto read(xtd::span<xtd::byte>& buffer) -> xtd::usize;
175 virtual auto read(xtd::array<xtd::byte>& buffer, xtd::usize offset, xtd::usize count) -> xtd::usize = 0;
176
185 auto read_at_least(xtd::array<xtd::byte>& buffer, xtd::usize minimum_bytes, bool throw_on_end_of_stream = true) -> xtd::usize;
186
187 [[nodiscard]] virtual auto read_byte() -> xtd::int32;
188
193 auto read_exactly(xtd::array<xtd::byte>& buffer) -> void;
201 auto read_exactly(xtd::array<xtd::byte>& buffer, xtd::usize offset, xtd::usize count) -> void;
202
203 virtual auto set_length(xtd::usize value) -> void = 0;
204
205 using std::iostream::write;
206 virtual auto write(xtd::span<const xtd::byte> buffer) -> void;
207 virtual auto write(const xtd::array<xtd::byte>& buffer, xtd::usize offset, xtd::usize count) -> void = 0;
208
209 virtual auto write_byte(xtd::byte value) -> void;
211
212 protected:
214
222
223 private:
224 streambuf streambuf_ {*this};
225 bool closed_ = false;
226 };
227 }
228}
Contains xtd::abstract_object class.
Contains xtd::async_callback delegate.
Represent an abstract class.
Definition abstract_object.hpp:27
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:29
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Represents the status of an asynchronous operation.
Definition iasync_result.hpp:25
Provides a generic view of a sequence of bytes. This is an abstract class.
Definition stream.hpp:39
virtual auto length() const -> xtd::usize=0
When overridden in a derived class, gets the length in bytes of the stream.
virtual auto write_timeout() const -> xtd::int32
Gets a value, in milliseconds, that determines how long the stream will attempt to write before timin...
virtual auto flush() -> void=0
When overridden in a derived class, clears all buffers for this stream and causes any buffered data t...
virtual auto read_timeout() const -> xtd::int32
Gets a value, in milliseconds, that determines how long the stream will attempt to read before timing...
auto read_exactly(xtd::array< xtd::byte > &buffer) -> void
Reads bytes from the current stream and advances the position within the stream until the buffer is f...
virtual auto can_write() const noexcept -> bool=0
Gets a value indicating whether the current stream supports writing.
virtual auto position() const -> xtd::usize=0
When overridden in a derived class, gets the position within the current stream.
virtual auto is_closed() const noexcept -> bool
Indicates if the stream is closed.
static xtd::io::null_stream null_stream
A Stream with no backing store.
Definition stream.hpp:78
auto copy_to(std::ostream &destination) -> void
Reads the bytes from the current memory stream and writes them to another stream.
stream()
Initializes a new instance of the xtd::io::stream class.
virtual auto read(xtd::span< xtd::byte > &buffer) -> xtd::usize
When overridden in a derived class, reads a sequence of bytes from the current stream and advances th...
virtual auto can_seek() const noexcept -> bool=0
When overridden in a derived class, gets a value indicating whether the current stream supports seeki...
virtual auto can_read() const noexcept -> bool=0
When overridden in a derived class, gets a value indicating whether the current stream supports readi...
virtual auto can_timeout() const noexcept -> bool
Gets a value that determines whether the current stream can time out.
auto read_at_least(xtd::array< xtd::byte > &buffer, xtd::usize minimum_bytes, bool throw_on_end_of_stream=true) -> xtd::usize
Reads at least a minimum number of bytes from the current stream and advances the position within the...
static constexpr xtd::int32 eof
Represnets an eof value.
Definition stream.hpp:82
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Represents a non-owning view over a contiguous sequence of objects.
Definition span.hpp:55
Represents a thread synchronization event that, when signaled, must be reset manually....
Definition manual_reset_event.hpp:35
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.hpp:52
Contains core_export_ keyword.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
std::uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
Contains xtd::iasync_result interface.
Contains xtd::threading::manual_reset_event exception.
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::io::seek_origin enum class.
Contains xtd::span class.
Contains xtd::string alias.