ScummVM API documentation
resources.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#ifndef ULTIMA_SHARED_ENGINE_RESOURCES_H
23#define ULTIMA_SHARED_ENGINE_RESOURCES_H
24
25#include "common/algorithm.h"
26#include "common/archive.h"
27#include "common/array.h"
28#include "common/memstream.h"
29#include "common/str.h"
30#include "common/serializer.h"
31#include "ultima/shared/core/file.h"
32
33#define STRING_BUFFER_SIZE 32768
34
35namespace Ultima {
36namespace Shared {
37
38class Resources;
39
44private:
45 File _file;
46 char _buffer[STRING_BUFFER_SIZE];
47 char *_bufferP;
48protected:
49 Common::Path _filename;
50protected:
54 ResourceFile(const Common::Path &filename);
55
59 virtual ~ResourceFile() {
60 }
61
65 virtual void synchronize() = 0;
66
67 virtual void syncString(const char *&str);
68 virtual void syncStrings(const char **str, size_t count);
69 virtual void syncStrings2D(const char **str, size_t count1, size_t count2);
70 virtual void syncNumber(int &val);
71 virtual void syncNumbers(int *vals, size_t count);
72 virtual void syncNumbers2D(int *vals, size_t count1, size_t count2);
73 virtual void syncNumbers3D(int *vals, size_t count1, size_t count2, size_t count3);
74 virtual void syncBytes(byte *vals, size_t count);
75 virtual void syncBytes2D(byte *vals, size_t count1, size_t count2);
76public:
80 void load();
81};
82
89private:
91 Resources *_owner;
92protected:
96 LocalResourceFile(const Common::Path &filename) : ResourceFile(filename), _owner(nullptr), _file(DisposeAfterUse::YES) {}
97
101 LocalResourceFile(Resources *owner, const Common::Path &filename) : ResourceFile(filename),
102 _owner(owner), _file(DisposeAfterUse::YES) {}
103
107 bool isSaving() const { return _owner != nullptr; }
108
109 void syncString(const char *&str) override;
110 void syncStrings(const char **str, size_t count) override;
111 void syncStrings2D(const char **str, size_t count1, size_t count2) override;
112 void syncNumber(int &val) override;
113 void syncNumbers(int *vals, size_t count) override;
114 void syncNumbers2D(int *vals, size_t count1, size_t count2) override;
115 void syncNumbers3D(int *vals, size_t count1, size_t count2, size_t count3) override;
116 void syncBytes(byte *vals, size_t count) override;
117 void syncBytes2D(byte *vals, size_t count1, size_t count2) override;
118public:
122 void save();
123};
124
129 struct LocalResource {
130 Common::Path _name;
132 };
133 struct FileResource {
134 Common::Path _name;
135 size_t _offset, _size;
136
140 void load(File &f);
141 };
142private:
143 Common::Array<LocalResource> _localResources;
144public:
149 }
150
155 bool open();
156
162 void addResource(const Common::Path &name, const byte *data, size_t size);
163
164 // Archive implementation
170 bool hasFile(const Common::Path &path) const override;
171
178 int listMembers(Common::ArchiveMemberList &list) const override;
179
183 const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
184
191};
192
193} // End of namespace Shared
194} // End of namespace Ultima
195
196#endif
Definition: archive.h:141
Definition: list.h:44
Definition: memstream.h:194
Definition: path.h:52
Definition: stream.h:745
Definition: file.h:34
Definition: resources.h:88
LocalResourceFile(Resources *owner, const Common::Path &filename)
Definition: resources.h:101
bool isSaving() const
Definition: resources.h:107
LocalResourceFile(const Common::Path &filename)
Definition: resources.h:96
Definition: resources.h:43
ResourceFile(const Common::Path &filename)
virtual ~ResourceFile()
Definition: resources.h:59
virtual void synchronize()=0
Definition: resources.h:128
bool hasFile(const Common::Path &path) const override
void addResource(const Common::Path &name, const byte *data, size_t size)
Resources()
Definition: resources.h:148
Common::SeekableReadStream * createReadStreamForMember(const Common::Path &path) const override
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override
int listMembers(Common::ArchiveMemberList &list) const override