Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | // |
| 20 | // rdr::MemInStream is an InStream which streams from a given memory buffer. |
| 21 | // If the deleteWhenDone parameter is true then the buffer will be delete[]d in |
| 22 | // the destructor. Note that it is delete[]d as a U8* - strictly speaking this |
| 23 | // means it ought to be new[]ed as a U8* as well, but on most platforms this |
| 24 | // doesn't matter. |
| 25 | // |
| 26 | |
| 27 | #ifndef __RDR_MEMINSTREAM_H__ |
| 28 | #define __RDR_MEMINSTREAM_H__ |
| 29 | |
| 30 | #include <rdr/InStream.h> |
| 31 | #include <rdr/Exception.h> |
| 32 | |
| 33 | namespace rdr { |
| 34 | |
| 35 | class MemInStream : public InStream { |
| 36 | |
| 37 | public: |
| 38 | |
| 39 | MemInStream(const void* data, int len, bool deleteWhenDone_=false) |
| 40 | : start((const U8*)data), deleteWhenDone(deleteWhenDone_) |
| 41 | { |
| 42 | ptr = start; |
| 43 | end = start + len; |
| 44 | } |
| 45 | |
| 46 | virtual ~MemInStream() { |
| 47 | if (deleteWhenDone) |
Pierre Ossman | 063df03 | 2015-09-29 15:43:28 +0200 | [diff] [blame] | 48 | delete [] start; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | int pos() { return ptr - start; } |
| 52 | void reposition(int pos) { ptr = start + pos; } |
| 53 | |
| 54 | private: |
| 55 | |
| 56 | int overrun(int itemSize, int nItems, bool wait) { throw EndOfStream(); } |
| 57 | const U8* start; |
| 58 | bool deleteWhenDone; |
| 59 | }; |
| 60 | |
| 61 | } |
| 62 | |
| 63 | #endif |