Core/Storage: A few more improvements to code style, corrected some engrish and fixed compile
This commit is contained in:
@@ -28,7 +28,7 @@ DBCFileLoader::DBCFileLoader()
|
|||||||
fieldsOffset = NULL;
|
fieldsOffset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
bool DBCFileLoader::Load(const char* filename, const char* fmt)
|
||||||
{
|
{
|
||||||
uint32 header;
|
uint32 header;
|
||||||
if (data)
|
if (data)
|
||||||
@@ -37,7 +37,7 @@ bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
|||||||
data = NULL;
|
data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE * f = fopen(filename,"rb");
|
FILE* f = fopen(filename,"rb");
|
||||||
if (!f)
|
if (!f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ DBCFileLoader::Record DBCFileLoader::getRecord(size_t id)
|
|||||||
return Record(*this, data + id * recordSize);
|
return Record(*this, data + id * recordSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 DBCFileLoader::GetFormatRecordSize(const char * format, int32* index_pos)
|
uint32 DBCFileLoader::GetFormatRecordSize(const char* format, int32* index_pos)
|
||||||
{
|
{
|
||||||
uint32 recordsize = 0;
|
uint32 recordsize = 0;
|
||||||
int32 i = -1;
|
int32 i = -1;
|
||||||
@@ -170,7 +170,7 @@ uint32 DBCFileLoader::GetFormatRecordSize(const char * format, int32* index_pos)
|
|||||||
return recordsize;
|
return recordsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**& indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char *& sqlDataTable)
|
char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**& indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char*& sqlDataTable)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
format STRING, NA, FLOAT,NA,INT <=>
|
format STRING, NA, FLOAT,NA,INT <=>
|
||||||
@@ -183,8 +183,8 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||||||
this func will generate entry[rows] data;
|
this func will generate entry[rows] data;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef char * ptr;
|
typedef char* ptr;
|
||||||
if (strlen(format)!=fieldCount)
|
if (strlen(format) != fieldCount)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
//get struct size and index pos
|
//get struct size and index pos
|
||||||
@@ -197,8 +197,9 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||||||
//find max index
|
//find max index
|
||||||
for (uint32 y = 0; y < recordCount; ++y)
|
for (uint32 y = 0; y < recordCount; ++y)
|
||||||
{
|
{
|
||||||
uint32 ind = getRecord(y).getUInt (i);
|
uint32 ind = getRecord(y).getUInt(i);
|
||||||
if (indi > maxi)maxi = ind;
|
if (ind > maxi)
|
||||||
|
maxi = ind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If higher index avalible from sql - use it instead of dbcs
|
// If higher index avalible from sql - use it instead of dbcs
|
||||||
@@ -208,7 +209,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||||||
++maxi;
|
++maxi;
|
||||||
records = maxi;
|
records = maxi;
|
||||||
indexTable = new ptr[maxi];
|
indexTable = new ptr[maxi];
|
||||||
memset(indexTable, 0, imaxi * sizeof(ptr));
|
memset(indexTable, 0, maxi * sizeof(ptr));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -249,7 +250,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||||||
offset += sizeof(char*);
|
offset += sizeof(char*);
|
||||||
break;
|
break;
|
||||||
case FT_LOGIC:
|
case FT_LOGIC:
|
||||||
assert(false && "Attempted to load DBC files that do not have field types that match what is in the core. Check DBCfmt.h or your DBC files.");
|
assert(false && "Attempted to load DBC files that do not have field types that match what is in the core. Check DBCfmt.h or your DBC files.");
|
||||||
break;
|
break;
|
||||||
case FT_NA:
|
case FT_NA:
|
||||||
case FT_NA_BYTE:
|
case FT_NA_BYTE:
|
||||||
@@ -306,7 +307,7 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FT_LOGIC:
|
case FT_LOGIC:
|
||||||
assert(false && "Attempted to load DBC files that do not have field types that match what is in the core. Check DBCfmt.h or your DBC files.");
|
assert(false && "Attempted to load DBC files that does not have field types that match what is in the core. Check DBCfmt.h or your DBC files.");
|
||||||
break;
|
break;
|
||||||
case FT_NA:
|
case FT_NA:
|
||||||
case FT_NA_BYTE:
|
case FT_NA_BYTE:
|
||||||
@@ -321,4 +322,3 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
|
|||||||
|
|
||||||
return stringPool;
|
return stringPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<class S, class D>
|
template<class S, class D>
|
||||||
void SQLStorageLoaderBase<T>::convert(uint32 /*field_pos*/, S src, D &dst)
|
void SQLStorageLoaderBase<T>::convert(uint32 /*field_pos*/, S src, D& dst)
|
||||||
{
|
{
|
||||||
dst = D(src);
|
dst = D(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char *src, char *&dst)
|
void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char* src, char*& dst)
|
||||||
{
|
{
|
||||||
if (!src)
|
if (!src)
|
||||||
{
|
{
|
||||||
@@ -44,7 +44,7 @@ void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char *src
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<class S>
|
template<class S>
|
||||||
void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, char * & dst)
|
void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, char*& dst)
|
||||||
{
|
{
|
||||||
dst = new char[1];
|
dst = new char[1];
|
||||||
*dst = 0;
|
*dst = 0;
|
||||||
@@ -52,17 +52,17 @@ void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, ch
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<class D>
|
template<class D>
|
||||||
void SQLStorageLoaderBase<T>::convert_from_str(uint32 /*field_pos*/, char * /*src*/, D& dst)
|
void SQLStorageLoaderBase<T>::convert_from_str(uint32 /*field_pos*/, char* /*src*/, D& dst)
|
||||||
{
|
{
|
||||||
dst = 0;
|
dst = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<class V>
|
template<class V>
|
||||||
void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset)
|
void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage& store, char* p, int x, uint32 &offset)
|
||||||
{
|
{
|
||||||
T * subclass = (static_cast<T*>(this));
|
T* subclass = (static_cast<T*>(this));
|
||||||
switch(store.dst_format[x])
|
switch (store.dst_format[x])
|
||||||
{
|
{
|
||||||
case FT_LOGIC:
|
case FT_LOGIC:
|
||||||
subclass->convert(x, value, *((bool*)(&p[offset])) );
|
subclass->convert(x, value, *((bool*)(&p[offset])) );
|
||||||
@@ -96,10 +96,10 @@ void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void SQLStorageLoaderBase<T>::storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset)
|
void SQLStorageLoaderBase<T>::storeValue(char* value, SQLStorage& store, char* p, int x, uint32& offset)
|
||||||
{
|
{
|
||||||
T * subclass = (static_cast<T*>(this));
|
T* subclass = (static_cast<T*>(this));
|
||||||
switch(store.dst_format[x])
|
switch (store.dst_format[x])
|
||||||
{
|
{
|
||||||
case FT_LOGIC:
|
case FT_LOGIC:
|
||||||
subclass->convert_from_str(x, value, *((bool*)(&p[offset])) );
|
subclass->convert_from_str(x, value, *((bool*)(&p[offset])) );
|
||||||
@@ -133,18 +133,18 @@ void SQLStorageLoaderBase<T>::storeValue(char * value, SQLStorage &store, char *
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
|
void SQLStorageLoaderBase<T>::Load(SQLStorage& store)
|
||||||
{
|
{
|
||||||
uint32 maxi;
|
uint32 maxi;
|
||||||
Field *fields;
|
Field* fields;
|
||||||
QueryResult result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
|
QueryResult result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
|
||||||
if(!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
sLog->outError("Error loading %s table (not exist?)\n", store.table);
|
sLog->outError("Error loading %s table (does not exist?)\n", store.table);
|
||||||
exit(1); // Stop server at loading non exited table or not accessable table
|
exit(1); // Stop server at loading non exited table or not accessable table
|
||||||
}
|
}
|
||||||
|
|
||||||
maxi = (*result)[0].GetUInt32() + 1;
|
maxi = result->Fetch()[0].GetUInt32() + 1;
|
||||||
|
|
||||||
result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
|
result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
|
||||||
if (result)
|
if (result)
|
||||||
@@ -170,7 +170,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
|
|||||||
if (store.iNumFields != result->GetFieldCount())
|
if (store.iNumFields != result->GetFieldCount())
|
||||||
{
|
{
|
||||||
store.RecordCount = 0;
|
store.RecordCount = 0;
|
||||||
sLog->outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n", store.table, store.iNumFields);
|
sLog->outError("Error loading table %s, probably table format was updated (there should be %u fields in sql).\n", store.table, store.iNumFields);
|
||||||
exit(1); // Stop server at loading broken or non-compatible table.
|
exit(1); // Stop server at loading broken or non-compatible table.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,12 +182,12 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
fields = result->Fetch();
|
fields = result->Fetch();
|
||||||
char *p = (char*)&_data[recordsize*count];
|
char* p = (char*)&_data[recordsize * count];
|
||||||
newIndex[fields[0].GetUInt32()] = p;
|
newIndex[fields[0].GetUInt32()] = p;
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
for (uint32 x = 0; x < store.iNumFields; ++x)
|
for (uint32 x = 0; x < store.iNumFields; ++x)
|
||||||
switch(store.src_format[x])
|
switch (store.src_format[x])
|
||||||
{
|
{
|
||||||
case FT_LOGIC:
|
case FT_LOGIC:
|
||||||
storeValue((bool)(fields[x].GetUInt32() > 0), store, p, x, offset);
|
storeValue((bool)(fields[x].GetUInt32() > 0), store, p, x, offset);
|
||||||
@@ -216,13 +216,9 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
|
|||||||
|
|
||||||
}
|
}
|
||||||
++count;
|
++count;
|
||||||
}
|
} while (result->NextRow());
|
||||||
while( result->NextRow() );
|
|
||||||
|
|
||||||
delete result;
|
|
||||||
|
|
||||||
store.pIndex = newIndex;
|
store.pIndex = newIndex;
|
||||||
store.MaxEntry = maxi;
|
store.MaxEntry = maxi;
|
||||||
store.data = _data;
|
store.data = _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user