xtd 0.2.0
Loading...
Searching...
No Matches
stream.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "io_exception.hpp"
6#include "seek_origin.hpp"
10#include "../core_export.hpp"
11#include "../iasync_result.hpp"
12#include "../span.hpp"
13#include "../string.hpp"
14#include <cstdio>
15#include <sstream>
16
18namespace xtd {
20 namespace io {
22 class null_stream;
24
40 class core_export_ stream : public xtd::abstract_object, public std::iostream {
41 class async_result_stream : public xtd::object, public xtd::iasync_result {
42 public:
43 explicit async_result_stream(const xtd::any_object& async_state) : async_state_(async_state) {}
44 xtd::any_object async_state() const noexcept override {return async_state_;}
45 xtd::threading::wait_handle& async_wait_handle() noexcept override {return async_event_;}
46 bool completed_synchronously() const noexcept override {return false;}
47 bool is_completed() const noexcept override {return is_completed_;};
48
49 xtd::any_object async_state_;
50 bool is_completed_ = false;
52 std::exception_ptr exception_;
53 };
54
55 class streambuf : public std::streambuf {
56 public:
57 explicit streambuf(xtd::io::stream& owner);
58
59 int_type underflow() override;
60 int_type overflow(int_type value) override;
61
62 private:
63 xtd::io::stream& owner_;
64 xtd::byte value_ = 0;
65 char_type* value_ptr_ = reinterpret_cast<char_type*>(&value_);
66 };
67
68 public:
70
73
75
79 static xtd::io::null_stream null_stream;
80
83 inline static constexpr xtd::int32 eof = EOF;
85
87
91 [[nodiscard]] virtual auto can_read() const noexcept -> bool = 0;
92
95 [[nodiscard]] virtual auto can_seek() const noexcept -> bool = 0;
96
100 [[nodiscard]] virtual auto can_timeout() const noexcept -> bool;
101
104 [[nodiscard]] virtual auto can_write() const noexcept -> bool = 0;
105
108 [[nodiscard]] virtual auto is_closed() const noexcept -> bool;
109
113 [[nodiscard]] virtual auto length() const -> xtd::size = 0;
114
120 [[nodiscard]] virtual auto position() const -> xtd::size = 0;
126 virtual auto position(xtd::size value) -> void = 0;
127
133 [[nodiscard]] virtual auto read_timeout() const -> xtd::int32;
139 virtual auto read_timeout(xtd::int32 value) -> void;
140
146 [[nodiscard]] virtual auto write_timeout() const -> xtd::int32;
147
153 virtual auto write_timeout(xtd::int32 value) -> void;
155
157
161 auto copy_to(std::ostream& destination) -> void;
162
166 auto copy_to(std::ostream& destination, xtd::size buffer_size) -> void;
167
170 virtual auto flush() -> void = 0;
171
172 using std::iostream::read;
175 virtual auto read(xtd::span<xtd::byte>& buffer) -> xtd::size;
176 virtual auto read(xtd::array<xtd::byte>& buffer, xtd::size offset, xtd::size count) -> xtd::size = 0;
177
186 auto read_at_least(xtd::array<xtd::byte>& buffer, xtd::size minimum_bytes, bool throw_on_end_of_stream = true) -> xtd::size;
187
188 [[nodiscard]] virtual auto read_byte() -> xtd::int32;
189
194 auto read_exactly(xtd::array<xtd::byte>& buffer) -> void;
202 auto read_exactly(xtd::array<xtd::byte>& buffer, xtd::size offset, xtd::size count) -> void;
203
204 virtual auto set_length(xtd::size value) -> void = 0;
205
206 using std::iostream::write;
207 virtual auto write(xtd::span<const xtd::byte> buffer) -> void;
208 virtual auto write(const xtd::array<xtd::byte>& buffer, xtd::size offset, xtd::size count) -> void = 0;
209
210 virtual auto write_byte(xtd::byte value) -> void;
212
213 protected:
215
223
224 private:
225 streambuf streambuf_ {*this};
226 bool closed_ = false;
227 };
228 }
229}
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:40
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...
virtual auto length() const -> xtd::size=0
When overridden in a derived class, gets the length in bytes of the stream.
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 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:79
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 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::size minimum_bytes, bool throw_on_end_of_stream=true) -> xtd::size
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:83
virtual auto position() const -> xtd::size=0
When overridden in a derived class, gets the position within the current stream.
virtual auto read(xtd::span< xtd::byte > &buffer) -> xtd::size
When overridden in a derived class, reads a sequence of bytes from the current stream and advances th...
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:58
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
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
std::uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
Contains xtd::iasync_result interface.
Contains xtd::io::io_exception exception.
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.