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le for direct file writes.
FILE *file;
tagHeader() : tagID(0), offset(0L), file(NULL) { }
tagHeader(FILE *f) : tagID(0), offset(0L), file(f) { }
unsigned char readByte();
void writeByte(unsigned char byte);
void write(const void *data, size_t size);
void read(void *data, size_t size);
void advance(int skip);
void marshallByte(struct tagHeader &th, char data);
void marshallShort(struct tagHeader &th, short data);
void marshallLong(struct tagHeader &th, long data);
void marshallFloat(struct tagHeader &th, float data);
void marshallBoolean(struct tagHeader &th, bool data);
void marshallString(struct tagHeader &th, const std::string &data,
void marshallByte(tagHeader &th, char data);
void marshallShort(tagHeader &th, short data);
void marshallLong(tagHeader &th, long data);
void marshallFloat(tagHeader &th, float data);
void marshallBoolean(tagHeader &th, bool data);
void marshallString(tagHeader &th, const std::string &data,
char unmarshallByte(struct tagHeader &th);
short unmarshallShort(struct tagHeader &th);
long unmarshallLong(struct tagHeader &th);
float unmarshallFloat(struct tagHeader &th);
bool unmarshallBoolean(struct tagHeader &th);
int unmarshallCString(struct tagHeader &th, char *data, int maxSize);
char unmarshallByte(tagHeader &th);
short unmarshallShort(tagHeader &th);
long unmarshallLong(tagHeader &th);
float unmarshallFloat(tagHeader &th);
bool unmarshallBoolean(tagHeader &th);
int unmarshallCString(tagHeader &th, char *data, int maxSize);
static void tag_construct_you(struct tagHeader &th);
static void tag_construct_you_items(struct tagHeader &th);
static void tag_construct_you_dungeon(struct tagHeader &th);
static void tag_construct_you(tagHeader &th);
static void tag_construct_you_items(tagHeader &th);
static void tag_construct_you_dungeon(tagHeader &th);
static void tag_read_you(struct tagHeader &th, char minorVersion);
static void tag_read_you_items(struct tagHeader &th, char minorVersion);
static void tag_read_you_dungeon(struct tagHeader &th);
static void tag_read_you(tagHeader &th, char minorVersion);
static void tag_read_you_items(tagHeader &th, char minorVersion);
static void tag_read_you_dungeon(tagHeader &th);
static void tag_construct_level(struct tagHeader &th);
static void tag_construct_level_items(struct tagHeader &th);
static void tag_construct_level_monsters(struct tagHeader &th);
static void tag_construct_level_attitude(struct tagHeader &th);
static void tag_read_level(struct tagHeader &th, char minorVersion);
static void tag_read_level_items(struct tagHeader &th, char minorVersion);
static void tag_read_level_monsters(struct tagHeader &th, char minorVersion);
static void tag_read_level_attitude(struct tagHeader &th);
static void tag_construct_level(tagHeader &th);
static void tag_construct_level_items(tagHeader &th);
static void tag_construct_level_monsters(tagHeader &th);
static void tag_construct_level_attitude(tagHeader &th);
static void tag_read_level(tagHeader &th, char minorVersion);
static void tag_read_level_items(tagHeader &th, char minorVersion);
static void tag_read_level_monsters(tagHeader &th, char minorVersion);
static void tag_read_level_attitude(tagHeader &th);
static void unmarshall_vector(struct tagHeader& th, std::vector<T>& vec,
T (*T_unmarshall)(struct tagHeader&));
static void unmarshall_vector(tagHeader& th, std::vector<T>& vec,
T (*T_unmarshall)(tagHeader&));
//////////////////////////////////////////////////////////////////////
// tagHeader
unsigned char tagHeader::readByte()
{
if (file)
return static_cast<unsigned char>(fgetc(file));
else
return tagBuffer[offset++];
}
void tagHeader::writeByte(unsigned char ch)
{
if (file)
fputc(ch, file);
else
tagBuffer[offset++] = ch;
}
void tagHeader::write(const void *data, size_t size)
{
if (file)
fwrite(data, 1, size, file);
else
{
memcpy(tagBuffer + offset, data, size);
offset += size;
}
}
void tagHeader::read(void *data, size_t size)
{
if (file)
fread(data, 1, size, file);
else
{
memcpy(data, tagBuffer + offset, size);
offset += size;
}
}
void tagHeader::advance(int skip)
{
if (file)
fseek(file, skip, SEEK_CUR);
else
offset += skip;
}
//////////////////////////////////////////////////////////////////////
char b2 = (char)(data & 0x00FF);
char b1 = (char)((data & 0xFF00) >> 8);
tagBuffer[th.offset] = b1;
tagBuffer[th.offset + 1] = b2;
th.offset += 2;
const char b2 = (char)(data & 0x00FF);
const char b1 = (char)((data & 0xFF00) >> 8);
th.writeByte(b1);
th.writeByte(b2);
void marshallMap(struct tagHeader &th, const std::map<key,value>& data,
void (*key_marshall)(struct tagHeader&, const key&),
void (*value_marshall)(struct tagHeader&, const value&))
void marshallMap(tagHeader &th, const std::map<key,value>& data,
void (*key_marshall)(tagHeader&, const key&),
void (*value_marshall)(tagHeader&, const value&))
writeByte(file, item.base_type);
writeByte(file, item.sub_type);
writeShort(file, item.plus);
writeShort(file, item.plus2);
writeLong(file, item.special);
writeShort(file, item.quantity);
writeByte(file, item.colour);
writeLong(file, item.flags);
writeShort(file, item.orig_place);
writeShort(file, item.orig_monnum);
writeString(file, item.inscription.c_str(), 80);
tagHeader th(file);
marshallItem(th, item);
item.base_type = static_cast<object_class_type>(readByte(file));
item.sub_type = readByte(file);
item.plus = readShort(file);
item.plus2 = readShort(file);
item.special = readLong(file);
item.quantity = readShort(file);
item.colour = readByte(file);
item.flags = readLong(file);
item.orig_place = readShort(file);
item.orig_monnum = readShort(file);
item.inscription = readString(file);
tagHeader th(file);
unmarshallItem(th, item);