[7625] Drop unexpected published debug related include line
[AHbot.git] / contrib / extractor / dbcfile.cpp
blob9e42f876b7e65a32493f49c568b179fc8612cba2
1 #define _CRT_SECURE_NO_DEPRECATE
3 #include "dbcfile.h"
4 #include "mpq_libmpq.h"
6 DBCFile::DBCFile(const std::string &filename):
7 filename(filename),
8 data(0)
12 bool DBCFile::open()
14 MPQFile f(filename.c_str());
15 char header[4];
16 unsigned int na,nb,es,ss;
18 if(f.read(header,4)!=4) // Number of records
19 return false;
21 if(header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C')
22 return false;
24 if(f.read(&na,4)!=4) // Number of records
25 return false;
26 if(f.read(&nb,4)!=4) // Number of fields
27 return false;
28 if(f.read(&es,4)!=4) // Size of a record
29 return false;
30 if(f.read(&ss,4)!=4) // String size
31 return false;
33 recordSize = es;
34 recordCount = na;
35 fieldCount = nb;
36 stringSize = ss;
37 if(fieldCount*4 != recordSize)
38 return false;
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)
45 return false;
46 f.close();
47 return true;
49 DBCFile::~DBCFile()
51 delete [] data;
54 DBCFile::Record DBCFile::getRecord(size_t id)
56 assert(data);
57 return Record(*this, data + id*recordSize);
60 size_t DBCFile::getMaxId()
62 assert(data);
64 size_t maxId = 0;
65 for(size_t i = 0; i < getRecordCount(); ++i)
67 if(maxId < getRecord(i).getUInt(0))
68 maxId = getRecord(i).getUInt(0);
70 return maxId;
73 DBCFile::Iterator DBCFile::begin()
75 assert(data);
76 return Iterator(*this, data);
78 DBCFile::Iterator DBCFile::end()
80 assert(data);
81 return Iterator(*this, stringTable);