Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
DBCFileLoader.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 DBC_FILE_LOADER_H
7#define DBC_FILE_LOADER_H
8#include "Define.h"
10#include <cassert>
11#include <string>
12
14{
15public:
18
19 bool Load(const char* filename, const char* fmt);
20
21 class Record
22 {
23 public:
24 float getFloat(size_t field) const
25 {
26 assert(field < file.fieldCount);
27 float val = *reinterpret_cast<float*>(offset + file.GetOffset(field));
28 EndianConvert(val);
29 return val;
30 }
31 uint32 getUInt(size_t field) const
32 {
33 assert(field < file.fieldCount);
34 uint32 val = *reinterpret_cast<uint32*>(offset + file.GetOffset(field));
35 EndianConvert(val);
36 return val;
37 }
38 uint8 getUInt8(size_t field) const
39 {
40 assert(field < file.fieldCount);
41 return *reinterpret_cast<uint8*>(offset + file.GetOffset(field));
42 }
43
44 const char* getString(size_t field) const
45 {
46 assert(field < file.fieldCount);
47 size_t stringOffset = getUInt(field);
48 assert(stringOffset < file.stringSize);
49 return reinterpret_cast<char*>(file.stringTable + stringOffset);
50 }
51
52 private:
53 Record(DBCFileLoader& file_, unsigned char* offset_) : offset(offset_), file(file_) { }
54 unsigned char* offset;
56
57 friend class DBCFileLoader;
58 };
59
60 // Get record by id
61 Record getRecord(size_t id);
63
64 uint32 GetNumRows() const { return recordCount; }
65 uint32 GetRowSize() const { return recordSize; }
66 uint32 GetCols() const { return fieldCount; }
67 uint32 GetOffset(size_t id) const { return (fieldsOffset != NULL && id < fieldCount) ? fieldsOffset[id] : 0; }
68 bool IsLoaded() const { return data != NULL; }
69 char* AutoProduceData(std::string fmt, uint32& count, char**& indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char*& sqlDataTable);
70 char* AutoProduceStrings(std::string fmt, char* dataTable);
71 static uint32 GetFormatRecordSize(std::string format, int32* index_pos = NULL);
72
73private:
79 unsigned char* data;
80 unsigned char* stringTable;
81 DBCFileLoader(DBCFileLoader const& right) = delete;
82 DBCFileLoader& operator=(DBCFileLoader const& right) = delete;
83};
84#endif
void EndianConvert(T &)
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
unsigned char * offset
DBCFileLoader & file
Record(DBCFileLoader &file_, unsigned char *offset_)
const char * getString(size_t field) const
uint32 getUInt(size_t field) const
friend class DBCFileLoader
float getFloat(size_t field) const
uint8 getUInt8(size_t field) const
unsigned char * data
Record getRecord(size_t id)
bool IsLoaded() const
DBCFileLoader(DBCFileLoader const &right)=delete
bool Load(const char *filename, const char *fmt)
uint32 GetCols() const
unsigned char * stringTable
uint32 GetOffset(size_t id) const
uint32 * fieldsOffset
DBCFileLoader & operator=(DBCFileLoader const &right)=delete
char * AutoProduceData(std::string fmt, uint32 &count, char **&indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char *&sqlDataTable)
static uint32 GetFormatRecordSize(std::string format, int32 *index_pos=NULL)
uint32 GetNumRows() const
Get begin iterator over records.
char * AutoProduceStrings(std::string fmt, char *dataTable)
uint32 GetRowSize() const