Max OS 0.3
Loading...
Searching...
No Matches
outputStream.h
Go to the documentation of this file.
1
9#ifndef MAXOS_COMMON_OUTPUTSTREAM_H
10#define MAXOS_COMMON_OUTPUTSTREAM_H
11
12#include <cstdint>
13#include <common/inputStream.h>
14#include <common/string.h>
15
16
17namespace MaxOS::common {
18
25 template<class Type> class GenericOutputStream : public InputStreamProcessor<Type, Type> {
26 public:
29
30 void on_stream_read(Type) override;
32
33 virtual void write(Type);
34 virtual void close();
35
37 };
38
43 class OutputStream : public GenericOutputStream<string> {
44
45 public:
48
49 virtual void line_feed();
50 virtual void carriage_return();
51 virtual void clear();
52
53 void write(string string_to_write) override;
54 void write(const char* string_to_write);
55 virtual void write_char(char char_to_write);
56 virtual void write_int(int int_to_write);
57 virtual void write_hex(uint64_t hex_to_write);
58
59 OutputStream& operator <<(string string_to_write) override;
60 OutputStream& operator <<(const char* string_to_write);
61 OutputStream& operator <<(int int_to_write);
62 OutputStream& operator <<(uint64_t hex_to_write);
63 OutputStream& operator <<(char char_to_write);
64 };
65
66
67
69
75 template<class Type> GenericOutputStream<Type>::GenericOutputStream() = default;
76
82 template<class Type> GenericOutputStream<Type>::~GenericOutputStream() = default;
83
90 template<class Type> void GenericOutputStream<Type>::on_stream_read(Type read_element) {
91
92 // When something is read from the input stream, it is written to the output stream.
93 write(read_element);
94
95 // Pass the element to any handlers
96 for(auto& input_stream_event_handler : this->m_input_stream_event_handlers)
97 input_stream_event_handler->on_stream_read(read_element);
98
99
100 }
101
109
110 // Close the stream.
111 close();
112
113 // Pass the event to any handlers
114 for(auto& input_stream_event_handler : this->m_input_stream_event_handlers)
115 input_stream_event_handler->on_end_of_stream(stream);
116
117 // Remove the stream from the list of streams.
119
120 }
121
127 template<class Type> void GenericOutputStream<Type>::write(Type) {
128
129 }
130
136 template<class Type> void GenericOutputStream<Type>::close() {
137
138 }
139
147 template<class Type> GenericOutputStream<Type>& GenericOutputStream<Type>::operator <<(Type write_element) {
148
149 // write the element to the stream.
150 write(write_element);
151
152 // Return the stream.
153 return *this;
154 }
155}
156
157#endif //MAXOS_COMMON_OUTPUTSTREAM_H
Manages the connection of a stream to handlers.
A stream that can be written to.
~GenericOutputStream()
Destructor of the GenericOutputStream class.
void on_end_of_stream(GenericInputStream< Type > *) override
Close the stream and remove it from the list of streams when the end of the stream is reached.
virtual GenericOutputStream< Type > & operator<<(Type)
Overload the << operator to write an element to the stream.
void on_stream_read(Type) override
Writes the date that was read from the input stream to the output stream.
GenericOutputStream()
__________________________________________Templates__________________________________________________...
virtual void write(Type)
write an element to the stream.
virtual void close()
Close the stream.
Converts one stream data type into another.
Definition inputStream.h:49
void on_end_of_stream(GenericInputStream< Type > *stream) override
Called when a stream has finished. Passes the event on to the handlers and then removes the stream fr...
A stream that strings can be written to.
OutputStream()
Constructs an OutputStream object that uses strings as the underlying data type.
virtual void carriage_return()
Writes a carriage return to the output stream.
virtual void write_hex(uint64_t hex_to_write)
Writes a hex to the output stream.
OutputStream & operator<<(string string_to_write) override
Writes a string to the output stream.
virtual void write_int(int int_to_write)
Writes an integer to the output stream.
void write(string string_to_write) override
Writes a string to the output stream.
virtual void write_char(char char_to_write)
Writes a character to the output stream.
virtual void clear()
Clears the output stream.
virtual void line_feed()
Writes a newline to the output stream.
Defines a generic input stream and related classes for handling input data streams.
Defines a String class for dynamically sized strings with various operations.