Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
dbcfile.h
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#ifndef DBCFILE_H
7
#define DBCFILE_H
8
#include <cassert>
9
#include <string>
10
#include "StormLib.h"
11
12
class
DBCFile
13
{
14
public
:
15
DBCFile
(HANDLE mpq,
const
char
* filename);
16
~DBCFile
();
17
18
// Open database. It must be openened before it can be used.
19
bool
open
();
20
21
// Database exceptions
22
class
Exception
23
{
24
public
:
25
Exception
(
const
std::string &
message
) :
message
(
message
) { }
26
virtual
~Exception
() { }
27
const
std::string &
getMessage
() {
return
message
; }
28
private
:
29
std::string
message
;
30
};
31
32
class
NotFound:
public
Exception
33
{
34
public
:
35
NotFound
():
Exception
(
"Key was not found"
) { }
36
};
37
38
// Iteration over database
39
class
Iterator;
40
class
Record
41
{
42
public
:
43
float
getFloat
(
size_t
field)
const
44
{
45
assert(field <
file
._fieldCount);
46
return
*
reinterpret_cast<
float
*
>
(
offset
+ field * 4);
47
}
48
49
unsigned
int
getUInt
(
size_t
field)
const
50
{
51
assert(field <
file
._fieldCount);
52
return
*
reinterpret_cast<
unsigned
int
*
>
(
offset
+ field * 4);
53
}
54
55
int
getInt
(
size_t
field)
const
56
{
57
assert(field <
file
._fieldCount);
58
return
*
reinterpret_cast<
int
*
>
(
offset
+ field * 4);
59
}
60
61
char
const
*
getString
(
size_t
field)
const
62
{
63
assert(field <
file
._fieldCount);
64
size_t
stringOffset =
getUInt
(field);
65
assert(stringOffset <
file
._stringSize);
66
return
reinterpret_cast<
char
*
>
(
file
._stringTable + stringOffset);
67
}
68
69
private
:
70
Record
(
DBCFile
&
file
,
unsigned
char
*
offset
):
file
(
file
),
offset
(
offset
) {}
71
DBCFile
&
file
;
72
unsigned
char
*
offset
;
73
74
friend
class
DBCFile
;
75
friend
class
DBCFile::Iterator
;
76
77
Record
&
operator=
(
Record
const
&);
78
Record
(
Record
const
& right) :
file
(right.
file
),
offset
(right.
offset
)
79
{
80
}
81
};
84
class
Iterator
85
{
86
public
:
87
Iterator
(
DBCFile
&file,
unsigned
char
* offset) :
record
(file, offset) { }
88
89
Iterator
(
Iterator
const
& right) :
record
(right.
record
)
90
{
91
}
92
94
Iterator
&
operator++
()
95
{
96
record
.offset +=
record
.file._recordSize;
97
return
*
this
;
98
}
99
101
Record
const
&
operator*
()
const
{
return
record
; }
102
Record
const
*
operator->
()
const
{
return
&
record
; }
103
105
bool
operator==
(
Iterator
const
& b)
const
106
{
107
return
record
.offset == b.record.offset;
108
}
109
110
bool
operator!=
(
Iterator
const
& b)
const
111
{
112
return
record
.offset != b.record.offset;
113
}
114
115
Iterator
&
operator=
(
Iterator
const
& right)
116
{
117
record
.offset = right.record.offset;
118
return
*
this
;
119
}
120
private
:
121
Record
record
;
122
};
123
124
// Get record by id
125
Record
getRecord
(
size_t
id
);
127
Iterator
begin
();
129
Iterator
end
();
131
size_t
getRecordCount
()
const
{
return
_recordCount
; }
132
size_t
getFieldCount
()
const
{
return
_fieldCount
; }
133
size_t
getMaxId
();
134
135
private
:
136
HANDLE
_mpq
;
137
const
char
*
_filename
;
138
HANDLE
_file
;
139
size_t
_recordSize
;
140
size_t
_recordCount
;
141
size_t
_fieldCount
;
142
size_t
_stringSize
;
143
unsigned
char
*
_data
;
144
unsigned
char
*
_stringTable
;
145
};
146
147
#endif
DBCFile::Exception
Definition
dbcfile.h:23
DBCFile::Exception::Exception
Exception(const std::string &message)
Definition
dbcfile.h:25
DBCFile::Exception::message
std::string message
Definition
dbcfile.h:29
DBCFile::Exception::~Exception
virtual ~Exception()
Definition
dbcfile.h:26
DBCFile::Exception::getMessage
const std::string & getMessage()
Definition
dbcfile.h:27
DBCFile::Iterator
Definition
dbcfile.h:82
DBCFile::Iterator::operator->
Record const * operator->() const
Definition
dbcfile.h:102
DBCFile::Iterator::operator=
Iterator & operator=(Iterator const &right)
Definition
dbcfile.h:115
DBCFile::Iterator::operator!=
bool operator!=(Iterator const &b) const
Definition
dbcfile.h:110
DBCFile::Iterator::Iterator
Iterator(DBCFile &file, unsigned char *offset)
Definition
dbcfile.h:87
DBCFile::Iterator::operator==
bool operator==(Iterator const &b) const
Comparison.
Definition
dbcfile.h:105
DBCFile::Iterator::operator*
Record const & operator*() const
Return address of current instance.
Definition
dbcfile.h:101
DBCFile::Iterator::record
Record record
Definition
dbcfile.h:109
DBCFile::Iterator::Iterator
Iterator(Iterator const &right)
Definition
dbcfile.h:89
DBCFile::Iterator::operator++
Iterator & operator++()
Advance (prefix only).
Definition
dbcfile.h:94
DBCFile::NotFound::NotFound
NotFound()
Definition
dbcfile.h:35
DBCFile::Record
Definition
dbcfile.h:41
DBCFile::Record::operator=
Record & operator=(Record const &)
DBCFile::Record::Record
Record(DBCFile &file, unsigned char *offset)
Definition
dbcfile.h:70
DBCFile::Record::getString
char const * getString(size_t field) const
Definition
dbcfile.h:61
DBCFile::Record::DBCFile
friend class DBCFile
Definition
dbcfile.h:74
DBCFile::Record::getFloat
float getFloat(size_t field) const
Definition
dbcfile.h:43
DBCFile::Record::getUInt
unsigned int getUInt(size_t field) const
Definition
dbcfile.h:49
DBCFile::Record::getInt
int getInt(size_t field) const
Definition
dbcfile.h:55
DBCFile::Record::Record
Record(Record const &right)
Definition
dbcfile.h:78
DBCFile::Record::file
DBCFile & file
Definition
dbcfile.h:71
DBCFile::Record::offset
unsigned char * offset
Definition
dbcfile.h:72
DBCFile
Definition
dbcfile.h:13
DBCFile::_stringSize
size_t _stringSize
Definition
dbcfile.h:130
DBCFile::_mpq
HANDLE _mpq
Definition
dbcfile.h:136
DBCFile::~DBCFile
~DBCFile()
DBCFile::begin
Iterator begin()
Get begin iterator over records.
DBCFile::_stringTable
unsigned char * _stringTable
Definition
dbcfile.h:132
DBCFile::getRecord
Record getRecord(size_t id)
DBCFile::_data
unsigned char * _data
Definition
dbcfile.h:131
DBCFile::getFieldCount
size_t getFieldCount() const
Definition
dbcfile.h:132
DBCFile::_recordSize
size_t _recordSize
Definition
dbcfile.h:127
DBCFile::getMaxId
size_t getMaxId()
DBCFile::_fieldCount
size_t _fieldCount
Definition
dbcfile.h:129
DBCFile::_recordCount
size_t _recordCount
Definition
dbcfile.h:128
DBCFile::open
bool open()
DBCFile::_file
HANDLE _file
Definition
dbcfile.h:126
DBCFile::getRecordCount
size_t getRecordCount() const
Trivial.
Definition
dbcfile.h:131
DBCFile::_filename
const char * _filename
Definition
dbcfile.h:137
DBCFile::end
Iterator end()
Get begin iterator over records.
DBCFile::DBCFile
DBCFile(HANDLE file)
Definition
dbcfile.cpp:10
src
tools
vmap4_extractor
dbcfile.h
Generated on
for Project SkyFire Core by
1.17.0