Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::common::InputStreamBuffer< Type > Class Template Reference

Buffers data from a stream and fires an event when a certain element is read. More...

#include <inputStream.h>

Inheritance diagram for MaxOS::common::InputStreamBuffer< Type >:
MaxOS::common::InputStreamProcessor< Type, Type * > MaxOS::common::InputStreamEventHandler< Type > MaxOS::common::GenericInputStream< Type >

Public Member Functions

 InputStreamBuffer (Type event_fire_element, Type termination_element)
 Creates a new InputStreamBuffer.
 
 ~InputStreamBuffer ()
 Destroys the InputStreamBuffer.
 
void on_stream_read (Type) override
 Called when data is read from a stream. Adds the data to the buffer and checks if the event should be fired.
 
void on_end_of_stream (GenericInputStream< Type > *) override
 Called when a stream has finished. Flushes the buffer if there is any data in it.
 
void flush ()
 Flushes the buffer by adding the termination element and firing an on read event (NOTE: The buffer is not cleared after this just overwritten)
 

Protected Attributes

Type m_buffer [10240]
 The buffer to store data in.
 
int m_offset { 0 }
 The current position in the buffer.
 
Type m_event_fire_element
 The element that will cause the buffer to flush and fire an event.
 
Type m_termination_element
 The element that will cause the buffer to flush and end the stream.
 
- Protected Attributes inherited from MaxOS::common::InputStreamEventHandler< Type >
common::Vector< GenericInputStream< Type > * > m_generic_input_streams
 List of streams being observed by this handler.
 
- Protected Attributes inherited from MaxOS::common::GenericInputStream< Type >
common::Vector< InputStreamEventHandler< Type > * > m_input_stream_event_handlers
 List of streams being observed by this handler.
 

Additional Inherited Members

- Protected Member Functions inherited from MaxOS::common::InputStreamProcessor< Type, Type * >
 InputStreamProcessor ()
 Creates a new InputStreamProcessor.
 
 InputStreamProcessor (InputStreamEventHandler< Type * > *generic_stream_event_handler)
 Creates a new InputStreamProcessor.
 
 ~InputStreamProcessor ()
 Destroys the InputStreamProcessor.
 
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 from the array of streams.
 
- Protected Member Functions inherited from MaxOS::common::InputStreamEventHandler< Type >
 InputStreamEventHandler ()
 _______________________________________________TEMPLATES_________________________________________________________________///
 
 ~InputStreamEventHandler ()
 Destroys the InputStreamProcessor and disconnects it from all streams.
 
- Protected Member Functions inherited from MaxOS::common::GenericInputStream< Type >
 GenericInputStream ()
 Creates a new GenericInputStream.
 
 GenericInputStream (InputStreamEventHandler< Type > *)
 Creates a new GenericInputStream and connects it to the handler.
 
 ~GenericInputStream ()
 Destroys the GenericInputStream and disconnects all handlers.
 
void connect_input_stream_event_handler (InputStreamEventHandler< Type > *)
 Adds a inputStreamEventHandler to the list of internetProtocolHandlers.
 
void disconnect_input_stream_event_handler (InputStreamEventHandler< Type > *)
 Removes a handler from the list of handlers.
 

Detailed Description

template<class Type>
class MaxOS::common::InputStreamBuffer< Type >

Buffers data from a stream and fires an event when a certain element is read.

Template Parameters
TypeThe type of data the stream is handling

Definition at line 80 of file inputStream.h.

Constructor & Destructor Documentation

◆ InputStreamBuffer()

template<class Type >
MaxOS::common::InputStreamBuffer< Type >::InputStreamBuffer ( Type  event_fire_element,
Type  termination_element 
)

Creates a new InputStreamBuffer.

Template Parameters
TypeThe type of data the stream is handling
Parameters
event_fire_elementThe element to fire the event on
termination_elementThe element that signifies the end of the part of the stream to be buffered (e.g a newline)

Definition at line 288 of file inputStream.h.

289 : m_event_fire_element(event_fire_element),
290 m_termination_element(termination_element) {
291
292 }
Type m_event_fire_element
The element that will cause the buffer to flush and fire an event.
Definition inputStream.h:84
Type m_termination_element
The element that will cause the buffer to flush and end the stream.
Definition inputStream.h:85

◆ ~InputStreamBuffer()

Destroys the InputStreamBuffer.

Template Parameters
TypeThe type of data the stream is handling

Member Function Documentation

◆ flush()

Flushes the buffer by adding the termination element and firing an on read event (NOTE: The buffer is not cleared after this just overwritten)

Template Parameters
TypeThe type of data the stream is handling

Definition at line 346 of file inputStream.h.

346 {
347
348 // Ensure the buffer is not empty
349 if(m_offset == 0)
350 return;
351
352 // Add the termination element to the buffer
354
355 // Fire the on read event
357
358 // Reset the offset
359 m_offset = 0;
360
361 }
int m_offset
The current position in the buffer.
Definition inputStream.h:83
Type m_buffer[10240]
The buffer to store data in.
Definition inputStream.h:82
virtual void on_stream_read(Type)
Called when data is read from a stream (overridden by subclasses)

References MaxOS::common::InputStreamEventHandler< Type >::on_stream_read().

◆ on_end_of_stream()

template<class Type >
void MaxOS::common::InputStreamBuffer< Type >::on_end_of_stream ( GenericInputStream< Type > *  stream)
overridevirtual

Called when a stream has finished. Flushes the buffer if there is any data in it.

Template Parameters
TypeThe type of data the stream is handling
Parameters
streamThe stream that has finished

Reimplemented from MaxOS::common::InputStreamEventHandler< Type >.

Definition at line 331 of file inputStream.h.

331 {
332
333 // flush the buffer if there is any data in it
334 if(m_offset > 0)
335 flush();
336
337 // Pass the event on to the handlers and remove the stream
339 }
void flush()
Flushes the buffer by adding the termination element and firing an on read event (NOTE: The buffer is...
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...

References MaxOS::common::InputStreamProcessor< Type, ProcessorType >::on_end_of_stream().

◆ on_stream_read()

template<class Type >
void MaxOS::common::InputStreamBuffer< Type >::on_stream_read ( Type  read_element)
overridevirtual

Called when data is read from a stream. Adds the data to the buffer and checks if the event should be fired.

Template Parameters
Type
Parameters
read_element

Reimplemented from MaxOS::common::InputStreamEventHandler< Type >.

Definition at line 307 of file inputStream.h.

307 {
308
309 // flush the buffer if the event fire element is read
310 if(read_element == m_event_fire_element) {
311 flush();
312 return;
313 }
314
315 // Ensure the buffer is not full
316 if(m_offset >= 10238) {
317 flush();
318 }
319
320 // Add the element
321 m_buffer[m_offset++] = read_element;
322
323 }

Member Data Documentation

◆ m_buffer

template<class Type >
Type MaxOS::common::InputStreamBuffer< Type >::m_buffer[10240]
protected

The buffer to store data in.

Definition at line 82 of file inputStream.h.

◆ m_event_fire_element

template<class Type >
Type MaxOS::common::InputStreamBuffer< Type >::m_event_fire_element
protected

The element that will cause the buffer to flush and fire an event.

Definition at line 84 of file inputStream.h.

◆ m_offset

template<class Type >
int MaxOS::common::InputStreamBuffer< Type >::m_offset { 0 }
protected

The current position in the buffer.

Definition at line 83 of file inputStream.h.

83{ 0 };

◆ m_termination_element

template<class Type >
Type MaxOS::common::InputStreamBuffer< Type >::m_termination_element
protected

The element that will cause the buffer to flush and end the stream.

Definition at line 85 of file inputStream.h.


The documentation for this class was generated from the following file: