ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

substream.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_SUBSTREAM_H
00024 #define COMMON_SUBSTREAM_H
00025 
00026 #include "common/ptr.h"
00027 #include "common/stream.h"
00028 #include "common/types.h"
00029 
00030 namespace Common {
00031 
00040 class SubReadStream : virtual public ReadStream {
00041 protected:
00042     DisposablePtr<ReadStream> _parentStream;
00043     uint32 _pos;
00044     uint32 _end;
00045     bool _eos;
00046 public:
00047     SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
00048         : _parentStream(parentStream, disposeParentStream),
00049           _pos(0),
00050           _end(end),
00051           _eos(false) {
00052         assert(parentStream);
00053     }
00054 
00055     virtual bool eos() const { return _eos | _parentStream->eos(); }
00056     virtual bool err() const { return _parentStream->err(); }
00057     virtual void clearErr() { _eos = false; _parentStream->clearErr(); }
00058     virtual uint32 read(void *dataPtr, uint32 dataSize);
00059 };
00060 
00061 /*
00062  * SeekableSubReadStream provides access to a SeekableReadStream restricted to
00063  * the range [begin, end).
00064  * The same caveats apply to SeekableSubReadStream as do to SeekableReadStream.
00065  *
00066  * Manipulating the parent stream directly /will/ mess up a substream.
00067  * @see SubReadStream
00068  */
00069 class SeekableSubReadStream : public SubReadStream, public SeekableReadStream {
00070 protected:
00071     SeekableReadStream *_parentStream;
00072     uint32 _begin;
00073 public:
00074     SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
00075 
00076     virtual int32 pos() const { return _pos - _begin; }
00077     virtual int32 size() const { return _end - _begin; }
00078 
00079     virtual bool seek(int32 offset, int whence = SEEK_SET);
00080 };
00081 
00089 class SeekableSubReadStreamEndian : public SeekableSubReadStream, public ReadStreamEndian {
00090 public:
00091     SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
00092         : SeekableSubReadStream(parentStream, begin, end, disposeParentStream),
00093           ReadStreamEndian(bigEndian) {
00094     }
00095 };
00096 
00110 class SafeSeekableSubReadStream : public SeekableSubReadStream {
00111 public:
00112     SafeSeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
00113         : SeekableSubReadStream(parentStream, begin, end, disposeParentStream) {
00114     }
00115 
00116     virtual uint32 read(void *dataPtr, uint32 dataSize);
00117 };
00118 
00119 
00120 } // End of namespace Common
00121 
00122 #endif


Generated on Sat Sep 14 2019 05:01:06 for ResidualVM by doxygen 1.7.1
curved edge   curved edge