ScummVM API documentation
stringtable.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
* Based on
24
* WebVenture (c) 2010, Sean Kasun
25
* https://github.com/mrkite/webventure, http://seancode.com/webventure/
26
*
27
* Used with explicit permission from the author
28
*/
29
30
#ifndef MACVENTURE_STRINGTABLE_H
31
#define MACVENTURE_STRINGTABLE_H
32
33
#include "macventure/macventure.h"
34
35
#include "common/file.h"
36
#include "common/str-enc.h"
37
38
namespace
MacVenture
{
39
40
enum
StringTableID {
41
kErrorStringTableID = 0x80,
42
kFilenamesStringTableID = 0x81,
43
kCommonArticlesStringTableID = 0x82,
44
kNamingArticlesStringTableID = 0x83,
45
kIndirectArticlesStringTableID = 0x84
46
};
47
48
class
StringTable
{
49
public
:
50
StringTable
(
MacVentureEngine
*engine,
Common::MacResManager
*resMan, StringTableID
id
) {
51
_engine = engine;
52
_resourceManager = resMan;
53
_id = id;
54
55
if
(!loadStrings())
56
error
(
"ENGINE: Could not load string table %x"
,
id
);
57
}
58
59
~
StringTable
() {
60
61
}
62
63
const
Common::Array<Common::String>
&getStrings() {
64
return
_strings;
65
}
66
67
Common::String
getString(uint ndx) {
68
assert(ndx < _strings.
size
());
69
return
_strings[ndx];
70
}
71
72
private
:
73
74
bool
loadStrings() {
75
Common::MacResIDArray
resArray;
76
Common::SeekableReadStream
*res;
77
78
if
((resArray = _resourceManager->
getResIDArray
(
MKTAG
(
'S'
,
'T'
,
'R'
,
'#'
))).size() == 0)
79
return
false
;
80
81
res = _resourceManager->
getResource
(
MKTAG
(
'S'
,
'T'
,
'R'
,
'#'
), _id);
82
83
_strings.
push_back
(
"dummy"
);
// String tables are 1-indexed
84
uint16 numStrings = res->
readUint16BE
();
85
uint8 strLength = 0;
86
for
(uint i = 0; i < numStrings; ++i) {
87
strLength = res->
readByte
();
88
char
*str =
new
char
[strLength + 1];
89
res->
read
(str, strLength);
90
str[strLength] =
'\0'
;
91
92
Common::U32String
result(str, Common::kMacRoman);
93
94
debugC
(4, kMVDebugText,
"Loaded string %s"
, str);
95
_strings.
push_back
(
Common::String
(result));
96
delete
[] str;
97
}
98
99
delete
res;
100
return
true
;
101
}
102
103
private
:
104
105
MacVentureEngine
*_engine;
106
Common::MacResManager
*_resourceManager;
107
108
StringTableID _id;
109
110
Common::Array<Common::String>
_strings;
111
};
112
113
}
// End of namespace MacVenture
114
115
#endif
Common::MacResManager
Definition:
macresman.h:125
Common::String
Definition:
str.h:59
Common::Array< Common::String >
Common::SeekableReadStream
Definition:
stream.h:745
Common::ReadStream::readByte
byte readByte()
Definition:
stream.h:434
Common::Array::push_back
void push_back(const T &element)
Definition:
array.h:180
Common::U32String
Definition:
ustr.h:57
MacVenture::MacVentureEngine
Definition:
macventure.h:185
Common::Array::size
size_type size() const
Definition:
array.h:315
Common::MacResManager::getResource
SeekableReadStream * getResource(uint32 typeID, uint16 resID)
error
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
MacVenture
Definition:
container.h:38
MacVenture::StringTable
Definition:
stringtable.h:48
MKTAG
#define MKTAG(a0, a1, a2, a3)
Definition:
endian.h:188
Common::ReadStream::readUint16BE
uint16 readUint16BE()
Definition:
stream.h:501
Common::MacResManager::getResIDArray
MacResIDArray getResIDArray(uint32 typeID)
debugC
void void void void void debugC(int level, uint32 debugChannels, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
Common::ReadStream::read
virtual uint32 read(void *dataPtr, uint32 dataSize)=0
engines
macventure
stringtable.h
Generated on Sun Nov 24 2024 09:18:42 for ScummVM API documentation by
1.8.13