4 #define __STORMLIB_SELF__
6 DBCFile::DBCFile(const std::string
&filename
) : filename(filename
)
13 MPQFile
f(filename
.c_str());
15 // Need some error checking, otherwise an unhandled exception error occurs
16 // if people screw with the data path.
17 if (f
.isEof() == true)
20 unsigned char header
[4];
21 unsigned int na
,nb
,es
,ss
;
23 f
.read(header
,4); // File Header
25 if (header
[0]!='W' || header
[1]!='D' || header
[2]!='B' || header
[3] != 'C') {
29 printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename
.c_str());
33 //assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C');
35 f
.read(&na
,4); // Number of records
36 f
.read(&nb
,4); // Number of fields
37 f
.read(&es
,4); // Size of a record
38 f
.read(&ss
,4); // String size
44 //assert(fieldCount*4 == recordSize);
45 assert(fieldCount
*4 >= recordSize
);
47 data
= new unsigned char[recordSize
*recordCount
+stringSize
];
48 stringTable
= data
+ recordSize
*recordCount
;
49 f
.read(data
,recordSize
*recordCount
+stringSize
);
59 DBCFile::Record
DBCFile::getRecord(size_t id
)
62 return Record(*this, data
+ id
*recordSize
);
65 DBCFile::Iterator
DBCFile::begin()
68 return Iterator(*this, data
);
70 DBCFile::Iterator
DBCFile::end()
73 return Iterator(*this, stringTable
);