LURE: Simplify StringList class

This commit is contained in:
Paul Gilbert 2015-11-16 20:48:01 -05:00
parent f68dae1849
commit f8b36bf855
2 changed files with 12 additions and 22 deletions

View File

@ -1217,26 +1217,19 @@ void BarmanLists::loadFromStream(Common::ReadStream *stream) {
// String list resource class
void StringList::load(MemoryBlock *data) {
_data = Memory::allocate(data->size());
_data->copyFrom(data);
// Get the number of entries
uint count = READ_LE_UINT16(data->data());
_numEntries = READ_LE_UINT16(_data->data());
char *p = (char *) _data->data() + sizeof(uint16);
_entries = (char **) Memory::alloc(_numEntries * sizeof(char *));
for (int index = 0; index < _numEntries; ++index) {
_entries[index] = p;
// Iterate through loading the strings one at a time
const char *p = (const char *)data->data() + sizeof(uint16);
for (uint index = 0; index < count; ++index) {
_entries.push_back(p);
p += strlen(p) + 1;
}
}
void StringList::clear() {
if (_numEntries != 0) {
Memory::dealloc(_entries);
delete _data;
_numEntries = 0;
}
_entries.clear();
}
// Field list and miscellaneous variables

View File

@ -28,6 +28,7 @@
#include "common/list.h"
#include "common/file.h"
#include "common/ptr.h"
#include "common/str-array.h"
#include "common/textconsole.h"
namespace Lure {
@ -850,19 +851,15 @@ enum StringEnum {S_CREDITS = 25, S_RESTART_GAME = 26, S_SAVE_GAME = 27, S_RESTOR
class StringList {
private:
MemoryBlock *_data;
int _numEntries;
char **_entries;
Common::StringArray _entries;
public:
StringList() { _numEntries = 0; }
~StringList() { clear(); }
StringList() {}
void load(MemoryBlock *data);
void clear();
int count() { return _numEntries; }
int count() { return _entries.size(); }
const char *getString(int index) {
if ((index < 0) || (index >= _numEntries)) error("Invalid index specified to String List");
return _entries[index];
return _entries[index].c_str();
}
const char *getString(Action action) { return getString((int) action - 1); }
const char *getString(StringEnum sEnum) { return getString((int) sEnum); }