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 if(f
.read(header
,4)!=4) // Number of records
21 if(header
[0]!='W' || header
[1]!='D' || header
[2]!='B' || header
[3]!='C')
24 if(f
.read(&na
,4)!=4) // Number of records
26 if(f
.read(&nb
,4)!=4) // Number of fields
28 if(f
.read(&es
,4)!=4) // Size of a record
30 if(f
.read(&ss
,4)!=4) // String size
37 if(fieldCount
*4 != recordSize
)
40 data
= new unsigned char[recordSize
*recordCount
+stringSize
];
41 stringTable
= data
+ recordSize
*recordCount
;
43 size_t data_size
= recordSize
*recordCount
+stringSize
;
44 if(f
.read(data
,data_size
)!=data_size
)
54 DBCFile::Record
DBCFile::getRecord(size_t id
)
57 return Record(*this, data
+ id
*recordSize
);
60 size_t DBCFile::getMaxId()
65 for(size_t i
= 0; i
< getRecordCount(); ++i
)
67 if(maxId
< getRecord(i
).getUInt(0))
68 maxId
= getRecord(i
).getUInt(0);
73 DBCFile::Iterator
DBCFile::begin()
76 return Iterator(*this, data
);
78 DBCFile::Iterator
DBCFile::end()
81 return Iterator(*this, stringTable
);