Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
DB2FileLoader.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 DB2_FILE_LOADER_H
7#define DB2_FILE_LOADER_H
8
9#include "Define.h"
11#include <cassert>
12#include <string>
13
15{
16public:
18 tableHash(0), build(0), unk1(0), minIndex(0), maxIndex(0), locale(0), unk5(0) { }
19
21
22 bool Load(const char* filename, const char* fmt);
23
24 class Record
25 {
26 public:
27 float getFloat(size_t field) const
28 {
29 assert(field < file.fieldCount);
30 float val = *reinterpret_cast<float*>(offset + file.GetOffset(field));
31 EndianConvert(val);
32 return val;
33 }
34 uint32 getUInt(size_t field) const
35 {
36 assert(field < file.fieldCount);
37 uint32 val = *reinterpret_cast<uint32*>(offset + file.GetOffset(field));
38 EndianConvert(val);
39 return val;
40 }
41 uint8 getUInt8(size_t field) const
42 {
43 assert(field < file.fieldCount);
44 return *reinterpret_cast<uint8*>(offset + file.GetOffset(field));
45 }
46
47 const char* getString(size_t field) const
48 {
49 assert(field < file.fieldCount);
50 size_t stringOffset = getUInt(field);
51 assert(stringOffset < file.stringSize);
52 return reinterpret_cast<char*>(file.stringTable + stringOffset);
53 }
54
55 private:
56 Record(DB2FileLoader& file_, unsigned char* offset_) : offset(offset_), file(file_) {}
57 unsigned char* offset;
59
60 friend class DB2FileLoader;
61 };
62
63 // Get record by id
64 Record getRecord(size_t id);
66
67 uint32 GetNumRows() const { return recordCount; }
68 uint32 GetCols() const { return fieldCount; }
69 uint32 GetOffset(size_t id) const { return (fieldsOffset != NULL && id < fieldCount) ? fieldsOffset[id] : 0; }
70 uint32 GetHash() const { return tableHash; }
71 bool IsLoaded() const { return (data != NULL); }
72 char* AutoProduceData(std::string fmt, uint32& count, char**& indexTable);
73 char* AutoProduceStringsArrayHolders(std::string fmt, char* dataTable);
74 char* AutoProduceStrings(std::string fmt, char* dataTable, uint32 locale);
75 static uint32 GetFormatRecordSize(std::string format, int32* index_pos = NULL);
76 static uint32 GetFormatStringsFields(std::string format);
77
78private:
84 unsigned char* data;
85 unsigned char* stringTable;
86
87 // WDB2 / WCH2 fields
89 uint32 build; // WDB2
90
91 int unk1; // WDB2 (Unix time in WCH2)
92 int minIndex; // WDB2
93 int maxIndex; // WDB2 (index table)
94 int locale; // WDB2
95 int unk5; // WDB2
96};
97
98#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
float getFloat(size_t field) const
uint8 getUInt8(size_t field) const
friend class DB2FileLoader
unsigned char * offset
uint32 getUInt(size_t field) const
DB2FileLoader & file
Record(DB2FileLoader &file_, unsigned char *offset_)
const char * getString(size_t field) const
static uint32 GetFormatStringsFields(std::string format)
unsigned char * data
static uint32 GetFormatRecordSize(std::string format, int32 *index_pos=NULL)
bool Load(const char *filename, const char *fmt)
char * AutoProduceStrings(std::string fmt, char *dataTable, uint32 locale)
char * AutoProduceData(std::string fmt, uint32 &count, char **&indexTable)
bool IsLoaded() const
uint32 GetNumRows() const
Get begin iterator over records.
Record getRecord(size_t id)
unsigned char * stringTable
uint32 GetHash() const
uint32 GetOffset(size_t id) const
uint32 * fieldsOffset
char * AutoProduceStringsArrayHolders(std::string fmt, char *dataTable)
uint32 GetCols() const