TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DBCFile Class Reference

#include <dbcfile.h>

Classes

class  Exception
 
class  Iterator
 
class  NotFound
 
class  Record
 

Public Member Functions

 DBCFile (HANDLE file)
 
 ~DBCFile ()
 
bool open ()
 
Record getRecord (size_t id)
 
Iterator begin ()
 Get begin iterator over records. More...
 
Iterator end ()
 Get begin iterator over records. More...
 
size_t getRecordCount () const
 Trivial. More...
 
size_t getFieldCount () const
 
size_t getMaxId ()
 
 DBCFile (HANDLE mpq, const char *filename)
 
 ~DBCFile ()
 
bool open ()
 
Record getRecord (size_t id)
 
Iterator begin ()
 Get begin iterator over records. More...
 
Iterator end ()
 Get begin iterator over records. More...
 
size_t getRecordCount () const
 Trivial. More...
 
size_t getFieldCount () const
 
size_t getMaxId ()
 

Private Attributes

HANDLE _file
 
size_t _recordSize
 
size_t _recordCount
 
size_t _fieldCount
 
size_t _stringSize
 
unsigned char * _data
 
unsigned char * _stringTable
 
HANDLE _mpq
 
const char * _filename
 

Constructor & Destructor Documentation

DBCFile::DBCFile ( HANDLE  file)
23  :
24  _file(file), _recordSize(0), _recordCount(0), _fieldCount(0),
26 {
27 }
HANDLE _file
Definition: dbcfile.h:139
unsigned char * _data
Definition: dbcfile.h:144
arena_t NULL
Definition: jemalloc_internal.h:624
size_t _recordSize
Definition: dbcfile.h:140
unsigned char * _stringTable
Definition: dbcfile.h:145
size_t _recordCount
Definition: dbcfile.h:141
size_t _stringSize
Definition: dbcfile.h:143
size_t _fieldCount
Definition: dbcfile.h:142
DBCFile::~DBCFile ( )
77 {
78  delete [] _data;
79 }
unsigned char * _data
Definition: dbcfile.h:144
DBCFile::DBCFile ( HANDLE  mpq,
const char *  filename 
)
23  :
24  _mpq(mpq), _filename(filename), _file(NULL), _recordSize(0), _recordCount(0),
26 {
27 }
HANDLE _file
Definition: dbcfile.h:139
unsigned char * _data
Definition: dbcfile.h:144
arena_t NULL
Definition: jemalloc_internal.h:624
size_t _recordSize
Definition: dbcfile.h:140
unsigned char * _stringTable
Definition: dbcfile.h:145
size_t _recordCount
Definition: dbcfile.h:141
HANDLE _mpq
Definition: dbcfile.h:150
const char * _filename
Definition: dbcfile.h:151
size_t _stringSize
Definition: dbcfile.h:143
size_t _fieldCount
Definition: dbcfile.h:142
DBCFile::~DBCFile ( )

Member Function Documentation

DBCFile::Iterator DBCFile::begin ( )

Get begin iterator over records.

100 {
101  assert(_data);
102  return Iterator(*this, _data);
103 }
unsigned char * _data
Definition: dbcfile.h:144

+ Here is the caller graph for this function:

Iterator DBCFile::begin ( )

Get begin iterator over records.

DBCFile::Iterator DBCFile::end ( )

Get begin iterator over records.

106 {
107  assert(_data);
108  return Iterator(*this, _stringTable);
109 }
unsigned char * _data
Definition: dbcfile.h:144
unsigned char * _stringTable
Definition: dbcfile.h:145

+ Here is the caller graph for this function:

Iterator DBCFile::end ( )

Get begin iterator over records.

size_t DBCFile::getFieldCount ( ) const
inline
135 { return _fieldCount; }
size_t _fieldCount
Definition: dbcfile.h:142
size_t DBCFile::getFieldCount ( ) const
inline
146 { return _fieldCount; }
size_t _fieldCount
Definition: dbcfile.h:142
size_t DBCFile::getMaxId ( )
88 {
89  assert(_data);
90 
91  size_t maxId = 0;
92  for(size_t i = 0; i < getRecordCount(); ++i)
93  if (maxId < getRecord(i).getUInt(0))
94  maxId = getRecord(i).getUInt(0);
95 
96  return maxId;
97 }
Record getRecord(size_t id)
Definition: dbcfile.cpp:81
unsigned char * _data
Definition: dbcfile.h:144
unsigned int getUInt(size_t field) const
Definition: dbcfile.h:62
size_t getRecordCount() const
Trivial.
Definition: dbcfile.h:134

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t DBCFile::getMaxId ( )
DBCFile::Record DBCFile::getRecord ( size_t  id)
82 {
83  assert(_data);
84  return Record(*this, _data + id*_recordSize);
85 }
unsigned char * _data
Definition: dbcfile.h:144
size_t _recordSize
Definition: dbcfile.h:140

+ Here is the caller graph for this function:

Record DBCFile::getRecord ( size_t  id)
size_t DBCFile::getRecordCount ( ) const
inline

Trivial.

134 { return _recordCount; }
size_t _recordCount
Definition: dbcfile.h:141

+ Here is the caller graph for this function:

size_t DBCFile::getRecordCount ( ) const
inline

Trivial.

145 { return _recordCount; }
size_t _recordCount
Definition: dbcfile.h:141
bool DBCFile::open ( )
bool DBCFile::open ( )
30 {
31  char header[4];
32  unsigned int na, nb, es, ss;
33 
34  DWORD readBytes = 0;
35  CascReadFile(_file, header, 4, &readBytes);
36  if (readBytes != 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  CascReadFile(_file, &na, 4, &readBytes);
43  if (readBytes != 4) // Number of records
44  return false;
45 
46  CascReadFile(_file, &nb, 4, &readBytes);
47  if (readBytes != 4) // Number of fields
48  return false;
49 
50  CascReadFile(_file, &es, 4, &readBytes);
51  if (readBytes != 4) // Size of a record
52  return false;
53 
54  CascReadFile(_file, &ss, 4, &readBytes);
55  if (readBytes != 4) // String size
56  return false;
57 
58  _recordSize = es;
59  _recordCount = na;
60  _fieldCount = nb;
61  _stringSize = ss;
62  if (_fieldCount * 4 != _recordSize)
63  return false;
64 
65  _data = new unsigned char[_recordSize * _recordCount + _stringSize];
67 
68  size_t data_size = _recordSize * _recordCount + _stringSize;
69  CascReadFile(_file, _data, data_size, &readBytes);
70  if (readBytes != data_size)
71  return false;
72 
73  return true;
74 }
HANDLE _file
Definition: dbcfile.h:139
unsigned char * _data
Definition: dbcfile.h:144
size_t _recordSize
Definition: dbcfile.h:140
unsigned char * _stringTable
Definition: dbcfile.h:145
size_t _recordCount
Definition: dbcfile.h:141
unsigned int DWORD
Definition: CascPort.h:139
size_t _stringSize
Definition: dbcfile.h:143
bool WINAPI CascReadFile(HANDLE hFile, void *lpBuffer, DWORD dwToRead, PDWORD pdwRead)
Definition: CascReadFile.cpp:459
size_t _fieldCount
Definition: dbcfile.h:142

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

unsigned char * DBCFile::_data
private
size_t DBCFile::_fieldCount
private
HANDLE DBCFile::_file
private
const char* DBCFile::_filename
private
HANDLE DBCFile::_mpq
private
size_t DBCFile::_recordCount
private
size_t DBCFile::_recordSize
private
size_t DBCFile::_stringSize
private
unsigned char * DBCFile::_stringTable
private

The documentation for this class was generated from the following files: