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  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef DBC_FILE_LOADER_H
20 #define DBC_FILE_LOADER_H
21 
22 #include "Define.h"
24 #include <cassert>
25 
27 {
28  public:
29  DBCFileLoader();
30  ~DBCFileLoader();
31 
32  bool Load(const char *filename, const char *fmt);
33 
34  class Record
35  {
36  public:
37  float getFloat(size_t field) const
38  {
39  assert(field < file.fieldCount);
40  float val = *reinterpret_cast<float*>(offset + file.GetOffset(field));
41  EndianConvert(val);
42  return val;
43  }
44  uint32 getUInt(size_t field) const
45  {
46  assert(field < file.fieldCount);
47  uint32 val = *reinterpret_cast<uint32*>(offset + file.GetOffset(field));
48  EndianConvert(val);
49  return val;
50  }
51  uint8 getUInt8(size_t field) const
52  {
53  assert(field < file.fieldCount);
54  return *reinterpret_cast<uint8*>(offset + file.GetOffset(field));
55  }
56  uint64 getUInt64(size_t field) const
57  {
58  assert(field < file.fieldCount);
59  uint64 val = *reinterpret_cast<uint64*>(offset + file.GetOffset(field));
60  EndianConvert(val);
61  return val;
62  }
63  const char *getString(size_t field) const
64  {
65  assert(field < file.fieldCount);
66  size_t stringOffset = getUInt(field);
67  assert(stringOffset < file.stringSize);
68  return reinterpret_cast<char*>(file.stringTable + stringOffset);
69  }
70 
71  private:
72  Record(DBCFileLoader &file_, unsigned char *offset_): offset(offset_), file(file_) { }
73  unsigned char* offset;
75 
76  friend class DBCFileLoader;
77 
78  };
79 
80  // Get record by id
81  Record getRecord(size_t id);
83 
84  uint32 GetNumRows() const { return recordCount; }
85  uint32 GetRowSize() const { return recordSize; }
86  uint32 GetCols() const { return fieldCount; }
87  uint32 GetOffset(size_t id) const { return (fieldsOffset != NULL && id < fieldCount) ? fieldsOffset[id] : 0; }
88  bool IsLoaded() const { return data != NULL; }
89  char* AutoProduceData(const char* fmt, uint32& count, char**& indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char *& sqlDataTable);
90  char* AutoProduceStrings(const char* fmt, char* dataTable);
91  static uint32 GetFormatRecordSize(const char * format, int32 * index_pos = NULL);
92  private:
93 
99  unsigned char *data;
100  unsigned char *stringTable;
101 
102  DBCFileLoader(DBCFileLoader const& right) = delete;
103  DBCFileLoader& operator=(DBCFileLoader const& right) = delete;
104 };
105 #endif
void format(BasicFormatter< Char > &f, const Char *&format_str, const T &value)
Definition: format.h:2963
Record getRecord(size_t id)
Definition: DBCFileLoader.cpp:122
uint64 getUInt64(size_t field) const
Definition: DBCFileLoader.h:56
uint32 * fieldsOffset
Definition: DBCFileLoader.h:98
uint32 fieldCount
Definition: DBCFileLoader.h:96
uint32 recordCount
Definition: DBCFileLoader.h:95
DBCFileLoader & file
Definition: DBCFileLoader.h:74
void EndianConvert(T &val)
Definition: ByteConverter.h:48
arena_t NULL
Definition: jemalloc_internal.h:624
unsigned char * data
Definition: DBCFileLoader.h:99
bool IsLoaded() const
Definition: DBCFileLoader.h:88
uint8 getUInt8(size_t field) const
Definition: DBCFileLoader.h:51
Definition: DBCFileLoader.h:26
uint32 recordSize
Definition: DBCFileLoader.h:94
float getFloat(size_t field) const
Definition: DBCFileLoader.h:37
uint32 stringSize
Definition: DBCFileLoader.h:97
uint32 GetRowSize() const
Definition: DBCFileLoader.h:85
char * AutoProduceStrings(const char *fmt, char *dataTable)
Definition: DBCFileLoader.cpp:272
unsigned char * offset
Definition: DBCFileLoader.h:73
uint32 GetNumRows() const
Get begin iterator over records.
Definition: DBCFileLoader.h:84
uint32 GetOffset(size_t id) const
Definition: DBCFileLoader.h:87
DBCFileLoader()
Definition: DBCFileLoader.cpp:26
Vector2int16 & operator=(const Any &a)
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
#define TC_SHARED_API
Definition: Define.h:128
char * AutoProduceData(const char *fmt, uint32 &count, char **&indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char *&sqlDataTable)
Definition: DBCFileLoader.cpp:173
unsigned char * stringTable
Definition: DBCFileLoader.h:100
uint32 GetCols() const
Definition: DBCFileLoader.h:86
static uint32 GetFormatRecordSize(const char *format, int32 *index_pos=NULL)
Definition: DBCFileLoader.cpp:128
const char * getString(size_t field) const
Definition: DBCFileLoader.h:63
uint8_t uint8
Definition: Define.h:152
Definition: format.h:285
Record(DBCFileLoader &file_, unsigned char *offset_)
Definition: DBCFileLoader.h:72
uint32 getUInt(size_t field) const
Definition: DBCFileLoader.h:44
Definition: DBCFileLoader.h:34