AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
DBCFile Class Reference

#include "dbcfile.h"

Classes

class  Exception
 
class  Iterator
 
class  NotFound
 
class  Record
 

Public Member Functions

 DBCFile (std::string filename)
 
 ~DBCFile ()
 
bool open ()
 
Record getRecord (size_t id)
 
Iterator begin ()
 Get begin iterator over records.
 
Iterator end ()
 Get begin iterator over records.
 
size_t getRecordCount () const
 Trivial.
 
size_t getFieldCount () const
 
size_t getMaxId ()
 
 DBCFile (std::string filename)
 
 ~DBCFile ()
 
bool open ()
 
Record getRecord (size_t id)
 
Iterator begin ()
 Get begin iterator over records.
 
Iterator end ()
 Get begin iterator over records.
 
size_t getRecordCount () const
 Trivial.
 
size_t getFieldCount () const
 

Private Attributes

std::string filename
 
size_t recordSize
 
size_t recordCount
 
size_t fieldCount
 
size_t stringSize
 
unsigned char * data
 
unsigned char * stringTable
 

Detailed Description

Constructor & Destructor Documentation

◆ DBCFile() [1/2]

DBCFile::DBCFile ( std::string  filename)
25 :
26 filename(std::move(filename)), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr)
27{
28}
size_t fieldCount
Definition: dbcfile.h:132
unsigned char * data
Definition: dbcfile.h:134
size_t stringSize
Definition: dbcfile.h:133
size_t recordCount
Definition: dbcfile.h:131
std::string filename
Definition: dbcfile.h:129
unsigned char * stringTable
Definition: dbcfile.h:135
size_t recordSize
Definition: dbcfile.h:130

◆ ~DBCFile() [1/2]

DBCFile::~DBCFile ( )
68{
69 delete [] data;
70}

References data.

◆ DBCFile() [2/2]

DBCFile::DBCFile ( std::string  filename)

◆ ~DBCFile() [2/2]

DBCFile::~DBCFile ( )

Member Function Documentation

◆ begin() [1/2]

DBCFile::Iterator DBCFile::begin ( )

Get begin iterator over records.

92{
93 assert(data);
94 return Iterator(*this, data);
95}

References data.

◆ begin() [2/2]

Iterator DBCFile::begin ( )

Get begin iterator over records.

◆ end() [1/2]

DBCFile::Iterator DBCFile::end ( )

Get begin iterator over records.

97{
98 assert(data);
99 return Iterator(*this, stringTable);
100}

References data, and stringTable.

◆ end() [2/2]

Iterator DBCFile::end ( )

Get begin iterator over records.

◆ getFieldCount() [1/2]

size_t DBCFile::getFieldCount ( ) const
inline
126{ return fieldCount; }

References fieldCount.

◆ getFieldCount() [2/2]

size_t DBCFile::getFieldCount ( ) const
inline
144{ return fieldCount; }

References fieldCount.

◆ getMaxId()

size_t DBCFile::getMaxId ( )
79{
80 assert(data);
81
82 size_t maxId = 0;
83 for (size_t i = 0; i < getRecordCount(); ++i)
84 {
85 if (maxId < getRecord(i).getUInt(0))
86 maxId = getRecord(i).getUInt(0);
87 }
88 return maxId;
89}
Record getRecord(size_t id)
Definition: dbcfile.cpp:72
size_t getRecordCount() const
Trivial.
Definition: dbcfile.h:125
unsigned int getUInt(size_t field) const
Definition: dbcfile.h:61

References data, getRecord(), getRecordCount(), and DBCFile::Record::getUInt().

◆ getRecord() [1/2]

DBCFile::Record DBCFile::getRecord ( size_t  id)
73{
74 assert(data);
75 return Record(*this, data + id * recordSize);
76}

References data, and recordSize.

Referenced by ExtractCameraFiles(), getMaxId(), main(), ReadLiquidTypeTableDBC(), and ReadMapDBC().

◆ getRecord() [2/2]

Record DBCFile::getRecord ( size_t  id)

◆ getRecordCount() [1/2]

size_t DBCFile::getRecordCount ( ) const
inline

Trivial.

125{ return recordCount;}

References recordCount.

Referenced by ExtractCameraFiles(), getMaxId(), main(), ReadLiquidTypeTableDBC(), and ReadMapDBC().

◆ getRecordCount() [2/2]

size_t DBCFile::getRecordCount ( ) const
inline

Trivial.

143{ return recordCount;}

References recordCount.

◆ open() [1/2]

bool DBCFile::open ( )
31{
32 MPQFile f(filename.c_str());
33 char header[4];
34 unsigned int na, nb, es, ss;
35
36 if (f.read(header, 4) != 4) // Number of records
37 return false;
38
39 if (header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C')
40 return false;
41
42 if (f.read(&na, 4) != 4) // Number of records
43 return false;
44 if (f.read(&nb, 4) != 4) // Number of fields
45 return false;
46 if (f.read(&es, 4) != 4) // Size of a record
47 return false;
48 if (f.read(&ss, 4) != 4) // String size
49 return false;
50
51 recordSize = es;
52 recordCount = na;
53 fieldCount = nb;
54 stringSize = ss;
55 if (fieldCount * 4 != recordSize)
56 return false;
57
58 data = new unsigned char[recordSize * recordCount + stringSize];
60
61 size_t data_size = recordSize * recordCount + stringSize;
62 if (f.read(data, data_size) != data_size)
63 return false;
64 f.close();
65 return true;
66}
Definition: mpq_libmpq04.h:75

References MPQFile::close(), data, fieldCount, filename, MPQFile::read(), recordCount, recordSize, stringSize, and stringTable.

Referenced by ExtractCameraFiles(), ExtractGameobjectModels(), main(), ReadLiquidTypeTableDBC(), and ReadMapDBC().

◆ open() [2/2]

bool DBCFile::open ( )

Member Data Documentation

◆ data

unsigned char * DBCFile::data
private

◆ fieldCount

◆ filename

std::string DBCFile::filename
private

Referenced by open().

◆ recordCount

size_t DBCFile::recordCount
private

Referenced by getRecordCount(), and open().

◆ recordSize

size_t DBCFile::recordSize
private

◆ stringSize

size_t DBCFile::stringSize
private

Referenced by DBCFile::Record::getString(), and open().

◆ stringTable

unsigned char * DBCFile::stringTable
private