Core/Misc: DBC std::array refactors, and |Hachievement unit tests

(cherry picked from commit 3fbbe7cfbe)
This commit is contained in:
Treeston
2020-09-01 00:38:46 +02:00
committed by Shauren
parent f7e1b5338d
commit c4b287c7bf
13 changed files with 284 additions and 201 deletions

View File

@@ -20,6 +20,7 @@
#include "Common.h"
#include "Define.h"
#include "DB2Store.h"
#include <string_view>
@@ -28,6 +29,42 @@ struct ItemTemplate;
class UnitTestDataLoader
{
public:
template <typename T, uint32 T::*ID>
class DB2
{
class LoaderGuard
{
public:
LoaderGuard(DB2& d) : _d(d) {}
~LoaderGuard() { _d.Dump(); }
T& Add() { return _d._storage.emplace_back(); }
private:
DB2& _d;
};
public:
DB2(DB2Storage<T>& store) : _store(store) {}
LoaderGuard Loader() { return {*this}; }
void Dump()
{
delete[] _store._indexTable.AsT;
for (T const& entry : _storage)
if (entry.*ID >= _store._indexTableSize)
_store._indexTableSize = entry.*ID + 1;
_store._indexTable.AsT = new T*[_store._indexTableSize];
for (size_t i = 0; i < _store._indexTableSize; ++i)
_store._indexTable.AsT[i] = nullptr;
for (T& entry : _storage)
_store._indexTable.AsT[entry.*ID] = &entry;
}
private:
std::vector<T> _storage;
DB2Storage<T>& _store;
};
static void LoadAchievementTemplates();
static void LoadItemTemplates();
private: