1 #define _CRT_SECURE_NO_DEPRECATE
4 #include "mpq_libmpq.h"
6 DBCFile::DBCFile(const std::string
&filename
):
14 MPQFile
f(filename
.c_str());
16 unsigned int na
,nb
,es
,ss
;
18 f
.read(header
,4); // Number of records
19 assert(header
[0]=='W' && header
[1]=='D' && header
[2]=='B' && header
[3] == 'C');
20 f
.read(&na
,4); // Number of records
21 f
.read(&nb
,4); // Number of fields
22 f
.read(&es
,4); // Size of a record
23 f
.read(&ss
,4); // String size
29 assert(fieldCount
*4 == recordSize
);
31 data
= new unsigned char[recordSize
*recordCount
+stringSize
];
32 stringTable
= data
+ recordSize
*recordCount
;
33 f
.read(data
,recordSize
*recordCount
+stringSize
);
41 DBCFile::Record
DBCFile::getRecord(size_t id
)
44 return Record(*this, data
+ id
*recordSize
);
47 size_t DBCFile::getMaxId()
52 for(size_t i
= 0; i
< getRecordCount(); ++i
)
54 if(maxId
< getRecord(i
).getUInt(0))
55 maxId
= getRecord(i
).getUInt(0);
60 DBCFile::Iterator
DBCFile::begin()
63 return Iterator(*this, data
);
65 DBCFile::Iterator
DBCFile::end()
68 return Iterator(*this, stringTable
);