~ubuntu-branches/debian/jessie/scummvm/jessie

« back to all changes in this revision

Viewing changes to common/substream.h

  • Committer: Package Import Robot
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-11-05 10:29:43 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20111105102943-zfm3dhlvy5b01u7v
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * along with this program; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $URL$
22
 
 * $Id$
23
 
 *
24
21
 */
25
22
 
26
23
#ifndef COMMON_SUBSTREAM_H
27
24
#define COMMON_SUBSTREAM_H
28
25
 
 
26
#include "common/ptr.h"
29
27
#include "common/stream.h"
30
28
#include "common/types.h"
31
29
 
41
39
 */
42
40
class SubReadStream : virtual public ReadStream {
43
41
protected:
44
 
        ReadStream *_parentStream;
45
 
        DisposeAfterUse::Flag _disposeParentStream;
 
42
        DisposablePtr<ReadStream> _parentStream;
46
43
        uint32 _pos;
47
44
        uint32 _end;
48
45
        bool _eos;
49
46
public:
50
47
        SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
51
 
                : _parentStream(parentStream),
52
 
                  _disposeParentStream(disposeParentStream),
 
48
                : _parentStream(parentStream, disposeParentStream),
53
49
                  _pos(0),
54
50
                  _end(end),
55
51
                  _eos(false) {
56
52
                assert(parentStream);
57
53
        }
58
 
        ~SubReadStream() {
59
 
                if (_disposeParentStream)
60
 
                        delete _parentStream;
61
 
        }
62
54
 
63
55
        virtual bool eos() const { return _eos | _parentStream->eos(); }
64
56
        virtual bool err() const { return _parentStream->err(); }
102
94
        }
103
95
};
104
96
 
 
97
/**
 
98
 * A seekable substream that removes the exclusivity demand required by the
 
99
 * normal SeekableSubReadStream, at the cost of seek()ing the parent stream
 
100
 * before each read().
 
101
 *
 
102
 * More than one SafeSubReadStream to the same parent stream can be used
 
103
 * at the same time; they won't mess up each other. They will, however,
 
104
 * reposition the parent stream, so don't depend on its position to be
 
105
 * the same after a read() or seek() on one of its SafeSubReadStream.
 
106
 */
 
107
class SafeSubReadStream : public SeekableSubReadStream {
 
108
public:
 
109
 SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) :
 
110
                SeekableSubReadStream(parentStream, begin, end, disposeParentStream) {
 
111
        }
 
112
 
 
113
 virtual uint32 read(void *dataPtr, uint32 dataSize);
 
114
};
 
115
 
105
116
 
106
117
}       // End of namespace Common
107
118