aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/DataStores/DB2Store.h59
1 files changed, 31 insertions, 28 deletions
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<char*> StringPoolList;
typedef std::vector<T*> 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;