From dcdd9447fd9e07a9601134880356a3d53e43f919 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 15 Mar 2013 21:19:15 +0100 Subject: Core/PacketIO: Allow playing all ingame movies Closes #9434 --- src/server/shared/DataStores/DB2Store.h | 59 +++++++++++++++++---------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'src/server/shared') diff --git a/src/server/shared/DataStores/DB2Store.h b/src/server/shared/DataStores/DB2Store.h index 6ebca714fe6..c8f51bc96cb 100644 --- a/src/server/shared/DataStores/DB2Store.h +++ b/src/server/shared/DataStores/DB2Store.h @@ -34,37 +34,39 @@ class DB2Storage typedef std::list StringPoolList; typedef std::vector DataTableEx; public: - explicit DB2Storage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } + explicit DB2Storage(char const* f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } ~DB2Storage() { Clear(); } - T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; } - uint32 GetNumRows() const { return nCount; } + T const* LookupEntry(uint32 id) const { return (id >= nCount) ? NULL : indexTable[id]; } + uint32 GetNumRows() const { return nCount; } char const* GetFormat() const { return fmt; } uint32 GetFieldCount() const { return fieldCount; } - /// Copies the provided entry and stores it. - void AddEntry(uint32 id, const T* entry) + /// Copies the provided entry and stores it. + T* CreateEntry(uint32 id, bool evenIfExists = false) + { + if (evenIfExists && LookupEntry(id)) + return NULL; + + if (id >= nCount) { - if (LookupEntry(id)) - return; - - if (id >= nCount) - { - // reallocate index table - char** tmpIdxTable = new char*[id+1]; - memset(tmpIdxTable, 0, (id+1) * sizeof(char*)); - memcpy(tmpIdxTable, (char*)indexTable, nCount * sizeof(char*)); - delete[] ((char*)indexTable); - nCount = id + 1; - indexTable = (T**)tmpIdxTable; - } - - T* entryDst = new T; - memcpy((char*)entryDst, (char*)entry, sizeof(T)); - m_dataTableEx.push_back(entryDst); - indexTable[id] = entryDst; + // reallocate index table + char** tmpIdxTable = new char*[id + 1]; + memset(tmpIdxTable, 0, (id + 1) * sizeof(char*)); + memcpy(tmpIdxTable, (char*)indexTable, nCount * sizeof(char*)); + delete[] ((char*)indexTable); + nCount = id + 1; + indexTable = (T**)tmpIdxTable; } + T* entryDst = new T; + m_dataTableEx.push_back(entryDst); + indexTable[id] = entryDst; + return entryDst; + } + + void EraseEntry(uint32 id) { indexTable[id] = NULL; } + bool Load(char const* fn) { DB2FileLoader db2; @@ -111,22 +113,23 @@ public: delete[] ((char*)indexTable); indexTable = NULL; + delete[] ((char*)m_dataTable); m_dataTable = NULL; - for (typename DataTableEx::const_iterator itr = m_dataTableEx.begin(); itr != m_dataTableEx.end(); ++itr) - delete *itr; - m_dataTableEx.clear(); + + for (typename DataTableEx::iterator itr = m_dataTableEx.begin(); itr != m_dataTableEx.end(); ++itr) + delete *itr; + m_dataTableEx.clear(); while (!m_stringPoolList.empty()) { delete[] m_stringPoolList.front(); m_stringPoolList.pop_front(); } + nCount = 0; } - void EraseEntry(uint32 id) { indexTable[id] = NULL; } - private: uint32 nCount; uint32 fieldCount; -- cgit v1.2.3