libopenraw  0.3.7
memstream.hpp
1 /* -*- Mode: C++ -*- */
2 /*
3  * libopenraw - memstream.h
4  *
5  * Copyright (C) 2007-2020 Hubert Figuière
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include <stddef.h>
25 #include <sys/types.h>
26 
27 #include <libopenraw/consts.h>
28 
29 #include "io/stream.hpp"
30 
31 namespace OpenRaw {
32 namespace IO {
33 
38 class MemStream
39  : public Stream
40 {
41 public:
47  MemStream(const uint8_t* ptr, size_t s);
48 
49  virtual ~MemStream()
50  {}
51 
52  MemStream(const MemStream& f) = delete;
53  MemStream & operator=(const MemStream&) = delete;
54 
56  virtual or_error open() override;
58  virtual int close() override;
60  virtual int seek(off_t offset, int whence) override;
62  virtual int read(void *buf, size_t count) override;
64  virtual off_t filesize() override;
65 
66 
67 private:
68  const uint8_t* m_ptr;
69  size_t m_size;
70  const uint8_t* m_current;
71 };
73 }
74 }
Memory based stream to read memory like a file IO.
Definition: memstream.hpp:40
virtual int close() override
close the file
Definition: memstream.cpp:51
virtual off_t filesize() override
Return the filesize.
Definition: memstream.cpp:106
virtual int read(void *buf, size_t count) override
read in the file. Semantics are similar to POSIX read()
Definition: memstream.cpp:88
virtual or_error open() override
open the file
Definition: memstream.cpp:44
MemStream(const uint8_t *ptr, size_t s)
Construct a new memory base stream.
Definition: memstream.cpp:36
virtual int seek(off_t offset, int whence) override
seek in the file. Semantics are similar to POSIX lseek()
Definition: memstream.cpp:57
base virtual class for IO
Definition: stream.hpp:44
or_error
Error codes returned by libopenraw.
Definition: consts.h:42
Global namespace for libopenraw.
Definition: arwfile.cpp:29