[8895] Use NULL-terminator instead table count in pdump code.

Also rename function to avoid use same name with type.
This commit is contained in:
VladimirMangos 2009-11-30 14:41:59 +03:00
parent 1e3100d664
commit a7cd0f8f44
3 changed files with 15 additions and 13 deletions

View file

@ -24,15 +24,16 @@
#include "ObjectMgr.h" #include "ObjectMgr.h"
// Character Dump tables // Character Dump tables
#define DUMP_TABLE_COUNT 21
struct DumpTable struct DumpTable
{ {
char const* name; char const* name;
DumpTableType type; DumpTableType type;
// helpers
bool isValid() const { return name != NULL; }
}; };
static DumpTable dumpTables[DUMP_TABLE_COUNT] = static DumpTable dumpTables[] =
{ {
{ "characters", DTT_CHARACTER }, { "characters", DTT_CHARACTER },
{ "character_achievement", DTT_CHAR_TABLE }, { "character_achievement", DTT_CHAR_TABLE },
@ -55,6 +56,7 @@ static DumpTable dumpTables[DUMP_TABLE_COUNT] =
{ "pet_aura", DTT_PET_TABLE }, { "pet_aura", DTT_PET_TABLE },
{ "pet_spell", DTT_PET_TABLE }, { "pet_spell", DTT_PET_TABLE },
{ "pet_spell_cooldown", DTT_PET_TABLE }, { "pet_spell_cooldown", DTT_PET_TABLE },
{ NULL, DTT_CHAR_TABLE }, // end marker
}; };
// Low level functions // Low level functions
@ -258,7 +260,7 @@ void StoreGUID(QueryResult *result,uint32 data,uint32 field, std::set<uint32>& g
} }
// Writing - High-level functions // Writing - High-level functions
void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type) void PlayerDumpWriter::DumpTableContent(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type)
{ {
GUIDs const* guids = NULL; GUIDs const* guids = NULL;
char const* fieldname = NULL; char const* fieldname = NULL;
@ -362,8 +364,8 @@ std::string PlayerDumpWriter::GetDump(uint32 guid)
else else
sLog.outError("Character DB not have 'character_db_version' table, revision guard query not added to pdump."); sLog.outError("Character DB not have 'character_db_version' table, revision guard query not added to pdump.");
for(int i = 0; i < DUMP_TABLE_COUNT; ++i) for(DumpTable* itr = &dumpTables[0]; itr->isValid(); ++itr)
DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type); DumpTableContent(dump, guid, itr->name, itr->name, itr->type);
// TODO: Add instance/group.. // TODO: Add instance/group..
// TODO: Add a dump level option to skip some non-important tables // TODO: Add a dump level option to skip some non-important tables
@ -497,17 +499,17 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
} }
DumpTableType type; DumpTableType type;
uint8 i; DumpTable* dTable = &dumpTables[0];
for(i = 0; i < DUMP_TABLE_COUNT; ++i) for(; dTable->isValid(); ++dTable)
{ {
if (tn == dumpTables[i].name) if (tn == dTable->name)
{ {
type = dumpTables[i].type; type = dTable->type;
break; break;
} }
} }
if (i == DUMP_TABLE_COUNT) if (!dTable->isValid())
{ {
sLog.outError("LoadPlayerDump: Unknown table: '%s'!", tn.c_str()); sLog.outError("LoadPlayerDump: Unknown table: '%s'!", tn.c_str());
ROLLBACK(DUMP_FILE_BROKEN); ROLLBACK(DUMP_FILE_BROKEN);

View file

@ -75,7 +75,7 @@ class PlayerDumpWriter : public PlayerDump
private: private:
typedef std::set<uint32> GUIDs; typedef std::set<uint32> GUIDs;
void DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type); void DumpTableContent(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type);
std::string GenerateWhereStr(char const* field, GUIDs const& guids, GUIDs::const_iterator& itr); std::string GenerateWhereStr(char const* field, GUIDs const& guids, GUIDs::const_iterator& itr);
std::string GenerateWhereStr(char const* field, uint32 guid); std::string GenerateWhereStr(char const* field, uint32 guid);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "8894" #define REVISION_NR "8895"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__