StreamWrapper.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * StreamWrapper.h
8  *
9  * @author: 2021 - Slavey Karadzhov <slav@attachix.com>
10  *
11  ****/
12 
13 #pragma once
14 
15 #include "ReadWriteStream.h"
16 #include <memory>
17 
23 {
24 public:
25  StreamWrapper(ReadWriteStream* source) : source(source)
26  {
27  }
28 
29  StreamType getStreamType() const override
30  {
31  return eSST_Wrapper;
32  }
33 
34  uint16_t readMemoryBlock(char* data, int bufSize) override
35  {
36  return source ? source->readMemoryBlock(data, bufSize) : 0;
37  }
38 
40  {
41  return source.get();
42  }
43 
44  bool isFinished() override
45  {
46  return source ? source->isFinished() : true;
47  }
48 
49 private:
50  std::unique_ptr<ReadWriteStream> source;
51 };
uint16_t readMemoryBlock(char *data, int bufSize) override
Read a block of memory.
Definition: StreamWrapper.h:44
virtual uint16_t readMemoryBlock(char *data, int bufSize)=0
Read a block of memory.
An abstract class that provides a wrapper around a stream.
Definition: StreamWrapper.h:22
ReadWriteStream * getSource() const
Definition: StreamWrapper.h:49
virtual bool isFinished()=0
Check if all data has been read.
StreamType
Data stream type.
Definition: DataSourceStream.h:25
StreamWrapper(ReadWriteStream *source)
Definition: StreamWrapper.h:35
StreamType getStreamType() const override
Get the stream type.
Definition: StreamWrapper.h:39
@ eSST_Wrapper
A stream that is a wrapper around a source stream.
Definition: DataSourceStream.h:36
Base class for read/write stream.
Definition: ReadWriteStream.h:19
bool isFinished() override
Check if all data has been read.
Definition: StreamWrapper.h:54