TrinityCore
Loading...
Searching...
No Matches
DB2Store.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 DB2STORE_H
19#define DB2STORE_H
20
21#include "Common.h"
22#include "Errors.h"
23#include "DBStorageIterator.h"
24#include <vector>
25
26class ByteBuffer;
27struct DB2LoadInfo;
28
31{
32public:
33 DB2StorageBase(char const* fileName, DB2LoadInfo const* loadInfo);
39
40 uint32 GetTableHash() const { return _tableHash; }
41 uint32 GetLayoutHash() const { return _layoutHash; }
42
43 bool HasRecord(uint32 id) const { return id < _indexTableSize && _indexTable[id] != nullptr; }
44 void WriteRecord(uint32 id, LocaleConstant locale, ByteBuffer& buffer) const;
45 void EraseRecord(uint32 id) { if (id < _indexTableSize) _indexTable[id] = nullptr; }
46
47 std::string const& GetFileName() const { return _fileName; }
48 uint32 GetFieldCount() const { return _fieldCount; }
49 DB2LoadInfo const* GetLoadInfo() const { return _loadInfo; }
50 uint32 GetNumRows() const { return _indexTableSize; }
51
52 void Load(std::string const& path, LocaleConstant locale);
53 void LoadStringsFrom(std::string const& path, LocaleConstant locale);
54 void LoadFromDB();
55 void LoadStringsFromDB(LocaleConstant locale);
56
57protected:
60 std::string _fileName;
64 char* _dataTableEx[2];
65 std::vector<char*> _stringPool;
69
70 friend class UnitTestDataLoader;
71};
72
73template <class T> requires (std::is_standard_layout_v<T> && std::is_trivially_copyable_v<T>)
75{
76public:
78
80
81 T const* LookupEntry(uint32 id) const { return (id >= _indexTableSize) ? nullptr : reinterpret_cast<T const*>(_indexTable[id]); }
82 T const* AssertEntry(uint32 id) const
83 {
84 T const* record = LookupEntry(id);
85 ASSERT(record != nullptr, "LookupEntry(%u)", id);
86 return record;
87 }
88
89 iterator begin() const { return iterator(reinterpret_cast<T const* const*>(_indexTable), _indexTableSize, _minId); }
90 iterator end() const { return iterator(reinterpret_cast<T const* const*>(_indexTable), _indexTableSize, _indexTableSize); }
91};
92
93#endif
LocaleConstant
Definition Common.h:51
#define TC_SHARED_API
Definition Define.h:123
uint32_t uint32
Definition Define.h:154
#define ASSERT
Definition Errors.h:80
Interface class for common access.
Definition DB2Store.h:31
uint32 GetNumRows() const
Definition DB2Store.h:50
uint32 GetTableHash() const
Definition DB2Store.h:40
uint32 _minId
Definition DB2Store.h:68
std::string const & GetFileName() const
Definition DB2Store.h:47
DB2LoadInfo const * _loadInfo
Definition DB2Store.h:62
uint32 _layoutHash
Definition DB2Store.h:59
uint32 GetLayoutHash() const
Definition DB2Store.h:41
std::vector< char * > _stringPool
Definition DB2Store.h:65
uint32 _fieldCount
Definition DB2Store.h:61
DB2StorageBase(DB2StorageBase &&)=delete
DB2StorageBase(char const *fileName, DB2LoadInfo const *loadInfo)
Definition DB2Store.cpp:25
uint32 _tableHash
Definition DB2Store.h:58
DB2LoadInfo const * GetLoadInfo() const
Definition DB2Store.h:49
void EraseRecord(uint32 id)
Definition DB2Store.h:45
char * _dataTable
Definition DB2Store.h:63
DB2StorageBase & operator=(DB2StorageBase const &)=delete
char ** _indexTable
Definition DB2Store.h:66
bool HasRecord(uint32 id) const
Definition DB2Store.h:43
DB2StorageBase(DB2StorageBase const &)=delete
uint32 _indexTableSize
Definition DB2Store.h:67
uint32 GetFieldCount() const
Definition DB2Store.h:48
DB2StorageBase & operator=(DB2StorageBase &&)=delete
std::string _fileName
Definition DB2Store.h:60
T const * LookupEntry(uint32 id) const
Definition DB2Store.h:81
iterator end() const
Definition DB2Store.h:90
iterator begin() const
Definition DB2Store.h:89
T const * AssertEntry(uint32 id) const
Definition DB2Store.h:82