ScummVM API documentation
pack.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program 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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22
23#ifndef TEENAGENT_PACK_H
24#define TEENAGENT_PACK_H
25
26#include "common/file.h"
27#include "common/array.h"
28
29namespace TeenAgent {
30
31class Pack {
32protected:
33 uint32 _fileCount;
34public:
35 Pack(): _fileCount(0) {}
36 virtual ~Pack() {}
37 virtual bool open(const Common::Path &filename) = 0;
38 virtual void close() = 0;
39
40 virtual uint32 fileCount() const { return _fileCount; }
41 virtual uint32 getSize(uint32 id) const = 0;
42 virtual uint32 read(uint32 id, byte *dst, uint32 size) const = 0;
43 virtual Common::SeekableReadStream *getStream(uint32 id) const = 0;
44};
45
47class FilePack : public Pack {
48 mutable Common::File file;
49 uint32 *offsets;
50
51public:
52 FilePack();
53 ~FilePack() override;
54
55 bool open(const Common::Path &filename) override;
56 void close() override;
57
58 uint32 getSize(uint32 id) const override;
59 uint32 read(uint32 id, byte *dst, uint32 size) const override;
60 Common::SeekableReadStream *getStream(uint32 id) const override;
61};
62
66class TransientFilePack : public Pack {
67 uint32 *offsets;
68 Common::Path _filename;
69
70public:
72 ~TransientFilePack() override;
73
74 bool open(const Common::Path &filename) override;
75 void close() override;
76
77 uint32 getSize(uint32 id) const override;
78 uint32 read(uint32 id, byte *dst, uint32 size) const override;
79 Common::SeekableReadStream *getStream(uint32 id) const override;
80};
81
83class MemoryPack : public Pack {
84 struct Chunk {
85 byte *data;
86 uint32 size;
87 inline Chunk(): data(0), size(0) {}
88 inline Chunk(const Chunk &c) : data(c.data), size(c.size) { c.reset(); }
89 inline Chunk &operator=(const Chunk &c) {
90 data = c.data;
91 size = c.size;
92 c.reset();
93 return *this;
94 }
95 inline ~Chunk() { delete[] data; }
96 inline void reset() const {
97 Chunk *c = const_cast<Chunk *>(this);
98 c->data = 0;
99 c->size = 0;
100 }
101 };
103
104public:
105 bool open(const Common::Path &filename) override;
106 void close() override;
107
108 uint32 getSize(uint32 id) const override;
109 uint32 read(uint32 id, byte *dst, uint32 size) const override;
110 Common::SeekableReadStream *getStream(uint32 id) const override;
111};
112
113} // End of namespace TeenAgent
114
115#endif
Definition: file.h:47
Definition: path.h:52
Definition: stream.h:745
FilePack keeps opened file and returns substream for each request.
Definition: pack.h:47
MemoryPack loads whole pack in memory, currently unused.
Definition: pack.h:83
Definition: pack.h:31
Definition: pack.h:66
Definition: actor.h:32