TrinityCore
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DBCFileLoader.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef DBC_FILE_LOADER_H
19#define DBC_FILE_LOADER_H
20
21#include "Define.h"
22#include "Errors.h"
24
26{
27 FT_NA='x', //not used or unknown, 4 byte size
28 FT_NA_BYTE='X', //not used or unknown, byte
29 FT_STRING='s', //char*
30 FT_FLOAT='f', //float
31 FT_INT='i', //uint32
32 FT_BYTE='b', //uint8
33 FT_SORT='d', //sorted by this field, field is not included
34 FT_IND='n', //the same, but parsed to data
35 FT_LOGIC='l', //Logical (boolean)
36 FT_SQL_PRESENT='p', //Used in sql format to mark column present in sql dbc
37 FT_SQL_ABSENT='a' //Used in sql format to mark column absent in sql dbc
38};
39
41{
42 public:
45
46 bool Load(const char *filename, const char *fmt);
47
48 class Record
49 {
50 public:
51 float getFloat(size_t field) const
52 {
53 ASSERT(field < file.fieldCount);
54 float val = *reinterpret_cast<float*>(offset+file.GetOffset(field));
55 EndianConvert(val);
56 return val;
57 }
58 uint32 getUInt(size_t field) const
59 {
60 ASSERT(field < file.fieldCount);
61 uint32 val = *reinterpret_cast<uint32*>(offset+file.GetOffset(field));
62 EndianConvert(val);
63 return val;
64 }
65 uint8 getUInt8(size_t field) const
66 {
67 ASSERT(field < file.fieldCount);
68 return *reinterpret_cast<uint8*>(offset+file.GetOffset(field));
69 }
70
71 const char *getString(size_t field) const
72 {
73 ASSERT(field < file.fieldCount);
74 size_t stringOffset = getUInt(field);
75 ASSERT(stringOffset < file.stringSize);
76 return reinterpret_cast<char*>(file.stringTable + stringOffset);
77 }
78
79 private:
80 Record(DBCFileLoader &file_, unsigned char *offset_): offset(offset_), file(file_) { }
81 unsigned char *offset;
83
84 friend class DBCFileLoader;
85
86 };
87
88 // Get record by id
89 Record getRecord(size_t id);
91
92 uint32 GetNumRows() const { return recordCount; }
93 uint32 GetRowSize() const { return recordSize; }
94 uint32 GetCols() const { return fieldCount; }
95 uint32 GetOffset(size_t id) const { return (fieldsOffset != nullptr && id < fieldCount) ? fieldsOffset[id] : 0; }
96 bool IsLoaded() const { return data != nullptr; }
97 char* AutoProduceData(char const* fmt, uint32& count, char**& indexTable);
98 char* AutoProduceStrings(char const* fmt, char* dataTable);
99 static uint32 GetFormatRecordSize(const char * format, int32 * index_pos = nullptr);
100 private:
101
107 unsigned char *data;
108 unsigned char *stringTable;
109
110 DBCFileLoader(DBCFileLoader const& right) = delete;
111 DBCFileLoader& operator=(DBCFileLoader const& right) = delete;
112};
113#endif
void EndianConvert(T &val)
Definition: ByteConverter.h:48
DbcFieldFormat
Definition: DBCFileLoader.h:26
@ FT_IND
Definition: DBCFileLoader.h:34
@ FT_NA
Definition: DBCFileLoader.h:27
@ FT_FLOAT
Definition: DBCFileLoader.h:30
@ FT_STRING
Definition: DBCFileLoader.h:29
@ FT_SORT
Definition: DBCFileLoader.h:33
@ FT_NA_BYTE
Definition: DBCFileLoader.h:28
@ FT_INT
Definition: DBCFileLoader.h:31
@ FT_LOGIC
Definition: DBCFileLoader.h:35
@ FT_BYTE
Definition: DBCFileLoader.h:32
@ FT_SQL_ABSENT
Definition: DBCFileLoader.h:37
@ FT_SQL_PRESENT
Definition: DBCFileLoader.h:36
uint8_t uint8
Definition: Define.h:135
#define TC_COMMON_API
Definition: Define.h:96
int32_t int32
Definition: Define.h:129
uint32_t uint32
Definition: Define.h:133
#define ASSERT
Definition: Errors.h:68
unsigned char * offset
Definition: DBCFileLoader.h:81
DBCFileLoader & file
Definition: DBCFileLoader.h:82
Record(DBCFileLoader &file_, unsigned char *offset_)
Definition: DBCFileLoader.h:80
const char * getString(size_t field) const
Definition: DBCFileLoader.h:71
uint32 getUInt(size_t field) const
Definition: DBCFileLoader.h:58
float getFloat(size_t field) const
Definition: DBCFileLoader.h:51
uint8 getUInt8(size_t field) const
Definition: DBCFileLoader.h:65
char * AutoProduceStrings(char const *fmt, char *dataTable)
unsigned char * data
uint32 recordCount
Record getRecord(size_t id)
bool IsLoaded() const
Definition: DBCFileLoader.h:96
DBCFileLoader(DBCFileLoader const &right)=delete
uint32 GetCols() const
Definition: DBCFileLoader.h:94
unsigned char * stringTable
uint32 GetOffset(size_t id) const
Definition: DBCFileLoader.h:95
uint32 * fieldsOffset
static uint32 GetFormatRecordSize(const char *format, int32 *index_pos=nullptr)
DBCFileLoader & operator=(DBCFileLoader const &right)=delete
uint32 GetNumRows() const
Get begin iterator over records.
Definition: DBCFileLoader.h:92
uint32 GetRowSize() const
Definition: DBCFileLoader.h:93
char * AutoProduceData(char const *fmt, uint32 &count, char **&indexTable)