TrinityCore
Loading...
Searching...
No Matches
DBCStore.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 DBCSTORE_H
19#define DBCSTORE_H
20
21#include "Common.h"
22#include "DBCStorageIterator.h"
23#include "Errors.h"
24#include <vector>
25
28{
29 public:
30 DBCStorageBase(char const* fmt);
31 virtual ~DBCStorageBase();
32
33 char const* GetFormat() const { return _fileFormat; }
34 uint32 GetFieldCount() const { return _fieldCount; }
35
36 virtual bool Load(char const* path) = 0;
37 virtual bool LoadStringsFrom(char const* path) = 0;
38 virtual void LoadFromDB(char const* table, char const* format, char const* index) = 0;
39
40 protected:
41 bool Load(char const* path, char**& indexTable);
42 bool LoadStringsFrom(char const* path, char** indexTable);
43 void LoadFromDB(char const* table, char const* format, char const* index, char**& indexTable);
44
46 char const* _fileFormat;
48 std::vector<char*> _stringPool;
50};
51
52template <class T>
54{
55 public:
57
58 explicit DBCStorage(char const* fmt) : DBCStorageBase(fmt)
59 {
60 _indexTable.AsT = nullptr;
61 }
62
64 {
65 delete[] reinterpret_cast<char*>(_indexTable.AsT);
66 }
67
68 T const* LookupEntry(uint32 id) const { return (id >= _indexTableSize) ? nullptr : _indexTable.AsT[id]; }
69 T const* AssertEntry(uint32 id) const { return ASSERT_NOTNULL(LookupEntry(id)); }
70
71 uint32 GetNumRows() const { return _indexTableSize; }
72
73 bool Load(char const* path) override
74 {
75 return DBCStorageBase::Load(path, _indexTable.AsChar);
76 }
77
78 bool LoadStringsFrom(char const* path) override
79 {
81 }
82
83 void LoadFromDB(char const* table, char const* format, char const* index) override
84 {
85 DBCStorageBase::LoadFromDB(table, format, index, _indexTable.AsChar);
86 }
87
90
91 private:
92 union
93 {
94 T** AsT;
95 char** AsChar;
96 }
98
99 DBCStorage(DBCStorage const& right) = delete;
100 DBCStorage& operator=(DBCStorage const& right) = delete;
101
102 friend class UnitTestDataLoader;
103};
104
105#endif
#define TC_SHARED_API
Definition Define.h:108
uint32_t uint32
Definition Define.h:133
#define ASSERT_NOTNULL(pointer)
Definition Errors.h:84
Interface class for common access.
Definition DBCStore.h:28
char const * _fileFormat
Definition DBCStore.h:46
virtual bool Load(char const *path)=0
uint32 GetFieldCount() const
Definition DBCStore.h:34
std::vector< char * > _stringPool
Definition DBCStore.h:48
virtual bool LoadStringsFrom(char const *path)=0
uint32 _indexTableSize
Definition DBCStore.h:49
uint32 _fieldCount
Definition DBCStore.h:45
char * _dataTable
Definition DBCStore.h:47
char const * GetFormat() const
Definition DBCStore.h:33
virtual void LoadFromDB(char const *table, char const *format, char const *index)=0
iterator end()
Definition DBCStore.h:89
DBCStorage(char const *fmt)
Definition DBCStore.h:58
T ** AsT
Definition DBCStore.h:94
T const * AssertEntry(uint32 id) const
Definition DBCStore.h:69
~DBCStorage()
Definition DBCStore.h:63
bool LoadStringsFrom(char const *path) override
Definition DBCStore.h:78
iterator begin()
Definition DBCStore.h:88
T const * LookupEntry(uint32 id) const
Definition DBCStore.h:68
union DBCStorage::@278 _indexTable
char ** AsChar
Definition DBCStore.h:95
bool Load(char const *path) override
Definition DBCStore.h:73
uint32 GetNumRows() const
Definition DBCStore.h:71
friend class UnitTestDataLoader
Definition DBCStore.h:102
DBCStorageIterator< T > iterator
Definition DBCStore.h:56
DBCStorage & operator=(DBCStorage const &right)=delete
void LoadFromDB(char const *table, char const *format, char const *index) override
Definition DBCStore.h:83
DBCStorage(DBCStorage const &right)=delete