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 
35 namespace Ultima {
36 namespace Shared {
37 
38 class Resources;
39 
43 class ResourceFile {
44 private:
45  File _file;
46  char _buffer[STRING_BUFFER_SIZE];
47  char *_bufferP;
48 protected:
49  Common::Path _filename;
50 protected:
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);
76 public:
80  void load();
81 };
82 
89 private:
91  Resources *_owner;
92 protected:
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;
118 public:
122  void save();
123 };
124 
128 class Resources : public Common::Archive {
129  struct LocalResource {
130  Common::Path _name;
131  Common::Array<byte> _data;
132  };
133  struct FileResource {
134  Common::Path _name;
135  size_t _offset, _size;
136 
140  void load(File &f);
141  };
142 private:
143  Common::Array<LocalResource> _localResources;
144 public:
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 
190  Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
191 };
192 
193 } // End of namespace Shared
194 } // End of namespace Ultima
195 
196 #endif
Definition: resources.h:88
Definition: types.h:27
Definition: list.h:44
Definition: resources.h:128
Definition: memstream.h:194
Definition: path.h:52
Definition: stream.h:745
virtual ~ResourceFile()
Definition: resources.h:59
Definition: archive.h:141
Definition: detection.h:27
LocalResourceFile(Resources *owner, const Common::Path &filename)
Definition: resources.h:101
virtual void synchronize()=0
bool isSaving() const
Definition: resources.h:107
Definition: resources.h:43
LocalResourceFile(const Common::Path &filename)
Definition: resources.h:96
Definition: file.h:34
ResourceFile(const Common::Path &filename)
Resources()
Definition: resources.h:148