xtd 0.2.0
stream.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "io_exception.hpp"
6#include "seek_origin.hpp"
7#include "../threading/manual_reset_event.hpp"
8#include "../abstract_object.hpp"
9#include "../async_callback.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(std::any async_state) : async_state_(async_state) {}
44 std::any 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 std::any 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(stream& owner);
58
59 int_type underflow() override;
60 int_type overflow(int_type value) override;
61
62 private:
63 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 int32 eof = EOF;
85
87
91 virtual bool can_read() const noexcept = 0;
92
95 virtual bool can_seek() const noexcept = 0;
96
100 virtual bool can_timeout() const noexcept;
101
104 virtual bool can_write() const noexcept = 0;
105
108 virtual bool is_closed() const noexcept;
109
113 virtual xtd::size length() const = 0;
114
120 virtual xtd::size position() const = 0;
126 virtual void position(xtd::size value) = 0;
127
133 virtual int32 read_timeout() const;
139 virtual void read_timeout(int32 value);
140
146 virtual int32 write_timeout() const;
147
153 virtual void write_timeout(int32 value);
155
157
161 void copy_to(std::ostream& destination);
162
166 void copy_to(std::ostream& destination, xtd::size buffer_size);
167
170 virtual void flush() = 0;
171
172 using std::iostream::read;
175 virtual xtd::size read(xtd::span<xtd::byte>& buffer);
176 virtual xtd::size read(xtd::array<xtd::byte>& buffer, xtd::size offset, xtd::size count) = 0;
177
186 xtd::size read_at_least(xtd::array<xtd::byte>& buffer, xtd::size minimum_bytes, bool throw_on_end_of_stream = true);
187
188 virtual int32 read_byte();
189
194 void read_exactly(xtd::array<xtd::byte>& buffer);
202 void read_exactly(xtd::array<xtd::byte>& buffer, xtd::size offset, xtd::size count);
203
204 virtual void set_length(xtd::size value) = 0;
205
206 using std::iostream::write;
207 virtual void write(xtd::span<const xtd::byte> buffer);
208 virtual void write(const xtd::array<xtd::byte>& buffer, xtd::size offset, xtd::size count) = 0;
209
210 virtual void write_byte(xtd::byte value);
212
213 protected:
215
223
224 private:
225 streambuf streambuf_ {*this};
226 bool closed_ = false;
227 };
228 }
229}
Represent an abstract class.
Definition abstract_object.hpp:27
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:59
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
static xtd::io::null_stream null_stream
A Stream with no backing store.
Definition stream.hpp:79
virtual bool can_read() const noexcept=0
When overridden in a derived class, gets a value indicating whether the current stream supports readi...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
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
@ io
I/O erreror occurs.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
Contains xtd::io::io_exception exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::io::seek_origin enum class.