ScummVM API documentation
named_archive_file.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 ULTIMA8_FILESYS_NAMEDARCHIVEFILE_H
23 #define ULTIMA8_FILESYS_NAMEDARCHIVEFILE_H
24 
25 #include "ultima/ultima8/filesys/archive_file.h"
26 #include "ultima/ultima8/misc/classtype.h"
27 
28 namespace Ultima {
29 namespace Ultima8 {
30 
31 class NamedArchiveFile : public ArchiveFile {
32 public:
33  NamedArchiveFile() : _indexCount(0) { }
34  ~NamedArchiveFile() override { }
35 
36  bool exists(uint32 index) override {
37  Std::string name;
38  return (indexToName(index, name));
39  }
40  bool exists(const Std::string &name) override = 0;
41 
42  uint8 *getObject(uint32 index, uint32 *size = 0) override {
43  Std::string name;
44  if (!indexToName(index, name))
45  return nullptr;
46  return getObject(name, size);
47  }
48  uint8 *getObject(const Std::string &name, uint32 *size = 0) override = 0;
49 
50  uint32 getSize(uint32 index) const override {
51  Std::string name;
52  if (!indexToName(index, name))
53  return 0;
54  return getSize(name);
55  }
56  uint32 getSize(const Std::string &name) const override = 0;
57 
58  uint32 getCount() const override = 0;
59 
60  uint32 getIndexCount() const override {
61  return _indexCount;
62  }
63 
64  bool isIndexed() const override {
65  return false;
66  }
67  bool isNamed() const override {
68  return true;
69  }
70 
71 protected:
72  bool indexToName(uint32 index, Std::string &name) const {
73  Common::HashMap<uint32, Std::string>::const_iterator iter;
74  iter = _indexedNames.find(index);
75  if (iter == _indexedNames.end()) return false;
76  name = iter->_value;
77  return true;
78  }
79 
80  void storeIndexedName(const Std::string &name) {
81  uint32 index;
82  bool hasIndex = extractIndexFromName(name, index);
83  if (hasIndex) {
84  _indexedNames[index] = name;
85  if (index >= _indexCount) _indexCount = index + 1;
86  }
87  }
88 
90  uint32 _indexCount;
91 };
92 
93 } // End of namespace Ultima8
94 } // End of namespace Ultima
95 
96 #endif
uint32 getSize(uint32 index) const override
Definition: named_archive_file.h:50
Definition: archive_file.h:30
uint8 * getObject(uint32 index, uint32 *size=0) override
Definition: named_archive_file.h:42
bool exists(uint32 index) override
Definition: named_archive_file.h:36
Definition: detection.h:27
Definition: hashmap.h:85
bool isIndexed() const override
is archive indexed?
Definition: named_archive_file.h:64
Definition: string.h:30
Definition: named_archive_file.h:31
uint32 getCount() const override=0
uint32 getIndexCount() const override
Definition: named_archive_file.h:60
bool isNamed() const override
is archive named?
Definition: named_archive_file.h:67