Stream.hpp
Go to the documentation of this file.
1 /****
2  * Stream.hpp
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the FlashString Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  * @author: 23 Oct 2018 - mikee47 <mike@sillyhouse.net>
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "String.hpp"
26 
27 namespace FSTR
28 {
34 class Stream : public IDataSourceStream
35 {
36 public:
42  Stream(const ObjectBase& object, bool flashread = true) : object(object), flashread(flashread)
43  {
44  }
45 
46  StreamType getStreamType() const override
47  {
48  return eSST_Memory;
49  }
50 
55  int available() override
56  {
57  return object.length() - readPos;
58  }
59 
60  uint16_t readMemoryBlock(char* data, int bufSize) override;
61 
62  int seekFrom(int offset, SeekOrigin origin) override;
63 
64  bool isFinished() override
65  {
66  return readPos >= object.length();
67  }
68 
69 private:
70  const ObjectBase& object;
71  size_t readPos = 0;
72  bool flashread;
73 };
74 
75 } // namespace FSTR
SeekOrigin
Stream/file seek origins.
Definition: SeekOrigin.h:18
Used when defining data structures.
Definition: ObjectBase.hpp:33
Definition: Stream.hpp:35
bool isFinished() override
Check if all data has been read.
Definition: Stream.hpp:64
StreamType getStreamType() const override
Get the stream type.
Definition: Stream.hpp:46
Stream(const ObjectBase &object, bool flashread=true)
Constructor.
Definition: Stream.hpp:42
int available() override
Return the total length of the stream.
Definition: Stream.hpp:55
uint16_t readMemoryBlock(char *data, int bufSize) override
Read a block of memory.
int seekFrom(int offset, SeekOrigin origin) override
Change position in stream.
Base class for read-only stream.
Definition: DataSourceStream.h:46
StreamType
Data stream type.
Definition: DataSourceStream.h:25
@ eSST_Memory
Memory stream.
Definition: DataSourceStream.h:27
Definition: Array.hpp:108