TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DB2Storage< T > Class Template Reference

#include <DB2Store.h>

Public Types

typedef DBStorageIterator< T > iterator
 
typedef bool(* SortFunc )(T const *left, T const *right)
 

Public Member Functions

 DB2Storage (char const *fileName, char const *format, HotfixDatabaseStatements preparedStmtIndex)
 
 ~DB2Storage ()
 
bool HasRecord (uint32 id) const override
 
void WriteRecord (uint32 id, uint32 locale, ByteBuffer &buffer) const override
 
void EraseRecord (uint32 id) override
 
T constLookupEntry (uint32 id) const
 
T constAssertEntry (uint32 id) const
 
std::string constGetFileName () const
 
uint32 GetNumRows () const
 
char constGetFormat () const
 
uint32 GetFieldCount () const
 
bool Load (std::string const &path, uint32 locale)
 
bool LoadStringsFrom (std::string const &path, uint32 locale)
 
void LoadFromDB ()
 
void LoadStringsFromDB (uint32 locale)
 
void Sort (SortFunc pred)
 
iterator begin ()
 
iterator end ()
 
- Public Member Functions inherited from DB2StorageBase
virtual ~DB2StorageBase ()
 
uint32 GetHash () const
 

Private Types

typedef std::list< char * > StringPoolList
 

Private Attributes

std::string _fileName
 
uint32 _indexTableSize
 
uint32 _fieldCount
 
char const_format
 
union {
   T **   AsT
 
   char **   AsChar
 
_indexTable
 
T * _dataTable
 
T * _dataTableEx
 
StringPoolList _stringPoolList
 
HotfixDatabaseStatements _hotfixStatement
 

Additional Inherited Members

- Protected Attributes inherited from DB2StorageBase
uint32 _tableHash
 

Member Typedef Documentation

template<class T>
typedef DBStorageIterator<T> DB2Storage< T >::iterator
template<class T>
typedef bool(* DB2Storage< T >::SortFunc)(T const *left, T const *right)
template<class T>
typedef std::list<char*> DB2Storage< T >::StringPoolList
private

Constructor & Destructor Documentation

template<class T>
DB2Storage< T >::DB2Storage ( char const fileName,
char const format,
HotfixDatabaseStatements  preparedStmtIndex 
)
inline
52  : _fileName(fileName), _indexTableSize(0), _fieldCount(0), _format(format), _dataTable(nullptr), _dataTableEx(nullptr), _hotfixStatement(preparedStmtIndex)
53  {
54  _indexTable.AsT = NULL;
55  }
void format(BasicFormatter< Char > &f, const Char *&format_str, const T &value)
Definition: format.h:2963
T * _dataTable
Definition: DB2Store.h:218
arena_t NULL
Definition: jemalloc_internal.h:624
char const * _format
Definition: DB2Store.h:212
T * _dataTableEx
Definition: DB2Store.h:219
HotfixDatabaseStatements _hotfixStatement
Definition: DB2Store.h:221
std::string _fileName
Definition: DB2Store.h:209
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable
uint32 _fieldCount
Definition: DB2Store.h:211
template<class T>
DB2Storage< T >::~DB2Storage ( )
inline
58  {
59  delete[] reinterpret_cast<char*>(_indexTable.AsT);
60  delete[] reinterpret_cast<char*>(_dataTable);
61  delete[] reinterpret_cast<char*>(_dataTableEx);
62  for (char* stringPool : _stringPoolList)
63  delete[] stringPool;
64  }
T * _dataTable
Definition: DB2Store.h:218
T * _dataTableEx
Definition: DB2Store.h:219
StringPoolList _stringPoolList
Definition: DB2Store.h:220
union DB2Storage::@338 _indexTable

Member Function Documentation

template<class T>
T const* DB2Storage< T >::AssertEntry ( uint32  id) const
inline
128 { return ASSERT_NOTNULL(LookupEntry(id)); }
T * ASSERT_NOTNULL(T *pointer)
Definition: Errors.h:58
T const * LookupEntry(uint32 id) const
Definition: DB2Store.h:127

+ Here is the call graph for this function:

template<class T>
iterator DB2Storage< T >::begin ( )
inline
205 { return iterator(_indexTable.AsT, _indexTableSize); }
DBStorageIterator< T > iterator
Definition: DB2Store.h:49
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable
template<class T>
iterator DB2Storage< T >::end ( )
inline
DBStorageIterator< T > iterator
Definition: DB2Store.h:49
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable
template<class T>
void DB2Storage< T >::EraseRecord ( uint32  id)
inlineoverridevirtual

Implements DB2StorageBase.

125 { if (id < _indexTableSize) _indexTable.AsT[id] = nullptr; }
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable
template<class T>
uint32 DB2Storage< T >::GetFieldCount ( ) const
inline
133 { return _fieldCount; }
uint32 _fieldCount
Definition: DB2Store.h:211

+ Here is the caller graph for this function:

template<class T>
std::string const& DB2Storage< T >::GetFileName ( ) const
inline
130 { return _fileName; }
std::string _fileName
Definition: DB2Store.h:209

+ Here is the caller graph for this function:

template<class T>
char const* DB2Storage< T >::GetFormat ( ) const
inline
132 { return _format; }
char const * _format
Definition: DB2Store.h:212

+ Here is the caller graph for this function:

template<class T>
uint32 DB2Storage< T >::GetNumRows ( ) const
inline
131 { return _indexTableSize; }
uint32 _indexTableSize
Definition: DB2Store.h:210
template<class T>
bool DB2Storage< T >::HasRecord ( uint32  id) const
inlineoverridevirtual

Implements DB2StorageBase.

66 { return id < _indexTableSize && _indexTable.AsT[id] != nullptr; }
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable
template<class T>
bool DB2Storage< T >::Load ( std::string const path,
uint32  locale 
)
inline
135  {
136  DB2FileLoader db2;
137  // Check if load was successful, only then continue
138  if (!db2.Load((path + _fileName).c_str(), _format))
139  return false;
140 
141  _fieldCount = db2.GetCols();
142  _tableHash = db2.GetHash();
143 
144  // load raw non-string data
145  _dataTable = reinterpret_cast<T*>(db2.AutoProduceData(_format, _indexTableSize, _indexTable.AsChar));
146 
147  // create string holders for loaded string fields
148  if (char* stringHolders = db2.AutoProduceStringsArrayHolders(_format, (char*)_dataTable))
149  {
150  _stringPoolList.push_back(stringHolders);
151 
152  // load strings from db2 data
153  if (char* stringBlock = db2.AutoProduceStrings(_format, (char*)_dataTable, locale))
154  _stringPoolList.push_back(stringBlock);
155  }
156 
157  // error in db2 file at loading if NULL
158  return _indexTable.AsT != NULL;
159  }
bool Load(const char *filename, const char *fmt)
Definition: DB2StorageLoader.cpp:44
T * _dataTable
Definition: DB2Store.h:218
uint32 GetHash() const
Definition: DB2StorageLoader.h:87
uint32 _tableHash
Definition: DB2Store.h:41
arena_t NULL
Definition: jemalloc_internal.h:624
char * AutoProduceStringsArrayHolders(const char *fmt, char *dataTable)
Definition: DB2StorageLoader.cpp:343
char const * _format
Definition: DB2Store.h:212
char * AutoProduceData(const char *fmt, uint32 &count, char **&indexTable)
Definition: DB2StorageLoader.cpp:265
Definition: DB2StorageLoader.h:27
uint32 GetCols() const
Definition: DB2StorageLoader.h:85
char * AutoProduceStrings(const char *fmt, char *dataTable, uint32 locale)
Definition: DB2StorageLoader.cpp:412
std::string _fileName
Definition: DB2Store.h:209
StringPoolList _stringPoolList
Definition: DB2Store.h:220
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable
uint32 _fieldCount
Definition: DB2Store.h:211

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T>
void DB2Storage< T >::LoadFromDB ( )
inline
180  {
181  char* extraStringHolders = nullptr;
182  if (char* dataTable = DB2DatabaseLoader(_fileName).Load(_format, _hotfixStatement, _indexTableSize, _indexTable.AsChar, extraStringHolders, _stringPoolList))
183  _dataTableEx = reinterpret_cast<T*>(dataTable);
184 
185  if (extraStringHolders)
186  _stringPoolList.push_back(extraStringHolders);
187  }
char const * _format
Definition: DB2Store.h:212
bool Load(std::string const &path, uint32 locale)
Definition: DB2Store.h:134
T * _dataTableEx
Definition: DB2Store.h:219
HotfixDatabaseStatements _hotfixStatement
Definition: DB2Store.h:221
Definition: DB2StorageLoader.h:117
std::string _fileName
Definition: DB2Store.h:209
StringPoolList _stringPoolList
Definition: DB2Store.h:220
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T>
bool DB2Storage< T >::LoadStringsFrom ( std::string const path,
uint32  locale 
)
inline
162  {
163  // DB2 must be already loaded using Load
164  if (!_indexTable.AsT)
165  return false;
166 
167  DB2FileLoader db2;
168  // Check if load was successful, only then continue
169  if (!db2.Load((path + _fileName).c_str(), _format))
170  return false;
171 
172  // load strings from another locale db2 data
174  if (char* stringBlock = db2.AutoProduceStrings(_format, (char*)_dataTable, locale))
175  _stringPoolList.push_back(stringBlock);
176  return true;
177  }
bool Load(const char *filename, const char *fmt)
Definition: DB2StorageLoader.cpp:44
T * _dataTable
Definition: DB2Store.h:218
char const * _format
Definition: DB2Store.h:212
static uint32 GetFormatLocalizedStringFieldCount(const char *format)
Definition: DB2StorageLoader.cpp:255
Definition: DB2StorageLoader.h:27
char * AutoProduceStrings(const char *fmt, char *dataTable, uint32 locale)
Definition: DB2StorageLoader.cpp:412
std::string _fileName
Definition: DB2Store.h:209
StringPoolList _stringPoolList
Definition: DB2Store.h:220
union DB2Storage::@338 _indexTable

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T>
void DB2Storage< T >::LoadStringsFromDB ( uint32  locale)
inline
190  {
192  return;
193 
195  }
HotfixDatabaseStatements
Definition: HotfixDatabase.h:24
char const * _format
Definition: DB2Store.h:212
static uint32 GetFormatLocalizedStringFieldCount(const char *format)
Definition: DB2StorageLoader.cpp:255
HotfixDatabaseStatements _hotfixStatement
Definition: DB2Store.h:221
Definition: DB2StorageLoader.h:117
std::string _fileName
Definition: DB2Store.h:209
StringPoolList _stringPoolList
Definition: DB2Store.h:220
void LoadStrings(const char *format, HotfixDatabaseStatements preparedStatement, uint32 locale, char **&indexTable, std::list< char * > &stringPool)
Definition: DB2StorageLoader.cpp:643
union DB2Storage::@338 _indexTable

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T>
T const* DB2Storage< T >::LookupEntry ( uint32  id) const
inline
127 { return (id >= _indexTableSize) ? nullptr : _indexTable.AsT[id]; }
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable

+ Here is the caller graph for this function:

template<class T>
void DB2Storage< T >::Sort ( SortFunc  pred)
inline
200  {
201  ASSERT(strpbrk(_format, "nd") == nullptr, "Only non-indexed storages can be sorted");
202  std::sort(_indexTable.AsT, _indexTable.AsT + _indexTableSize, pred);
203  }
char const * _format
Definition: DB2Store.h:212
#define ASSERT
Definition: Errors.h:55
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable
template<class T>
void DB2Storage< T >::WriteRecord ( uint32  id,
uint32  locale,
ByteBuffer buffer 
) const
inlineoverridevirtual

Implements DB2StorageBase.

68  {
69  ASSERT(id < _indexTableSize);
70  char const* entry = _indexTable.AsChar[id];
71  ASSERT(entry);
72 
73  std::size_t fields = strlen(_format);
74  for (uint32 i = 0; i < fields; ++i)
75  {
76  switch (_format[i])
77  {
78  case FT_IND:
79  case FT_INT:
80  buffer << *(uint32*)entry;
81  entry += 4;
82  break;
83  case FT_FLOAT:
84  buffer << *(float*)entry;
85  entry += 4;
86  break;
87  case FT_BYTE:
88  buffer << *(uint8*)entry;
89  entry += 1;
90  break;
91  case FT_STRING:
92  {
93  LocalizedString* locStr = *(LocalizedString**)entry;
94  if (locStr->Str[locale][0] == '\0')
95  locale = 0;
96 
97  char const* str = locStr->Str[locale];
98  std::size_t len = strlen(str);
99  buffer << uint16(len ? len + 1 : 0);
100  if (len)
101  {
102  buffer.append(str, len);
103  buffer << uint8(0);
104  }
105  entry += sizeof(LocalizedString*);
106  break;
107  }
109  {
110  char const* str = *(char const**)entry;
111  std::size_t len = strlen(str);
112  buffer << uint16(len ? len + 1 : 0);
113  if (len)
114  {
115  buffer.append(str, len);
116  buffer << uint8(0);
117  }
118  entry += sizeof(char const*);
119  break;
120  }
121  }
122  }
123  }
Definition: Define.h:161
Definition: Common.h:146
Definition: Define.h:160
uint16_t uint16
Definition: g3dmath.h:166
char const * _format
Definition: DB2Store.h:212
char const * Str[TOTAL_LOCALES]
Definition: Common.h:148
Definition: Define.h:165
uint32_t uint32
Definition: Define.h:150
void append(T value)
Definition: ByteBuffer.h:143
Definition: Define.h:162
uint8_t uint8
Definition: g3dmath.h:164
Definition: Define.h:158
uint8_t uint8
Definition: Define.h:152
#define ASSERT
Definition: Errors.h:55
Definition: Define.h:159
uint32 _indexTableSize
Definition: DB2Store.h:210
union DB2Storage::@338 _indexTable

+ Here is the call graph for this function:

Member Data Documentation

template<class T>
T* DB2Storage< T >::_dataTable
private
template<class T>
T* DB2Storage< T >::_dataTableEx
private
template<class T>
uint32 DB2Storage< T >::_fieldCount
private
template<class T>
std::string DB2Storage< T >::_fileName
private
template<class T>
char const* DB2Storage< T >::_format
private
template<class T>
HotfixDatabaseStatements DB2Storage< T >::_hotfixStatement
private
union { ... } DB2Storage< T >::_indexTable
template<class T>
uint32 DB2Storage< T >::_indexTableSize
private
template<class T>
StringPoolList DB2Storage< T >::_stringPoolList
private
template<class T>
char** DB2Storage< T >::AsChar
template<class T>
T** DB2Storage< T >::AsT

The documentation for this class was generated from the following file: