Core/Storage: A few more improvements to code style, corrected some engrish and fixed compile

This commit is contained in:
Shauren
2011-03-18 17:01:37 +01:00
parent 2f89fa9e69
commit d3425921f8
2 changed files with 31 additions and 35 deletions
+12 -12
View File
@@ -28,7 +28,7 @@ DBCFileLoader::DBCFileLoader()
fieldsOffset = NULL;
}
bool DBCFileLoader::Load(const char *filename, const char *fmt)
bool DBCFileLoader::Load(const char* filename, const char* fmt)
{
uint32 header;
if (data)
@@ -37,7 +37,7 @@ bool DBCFileLoader::Load(const char *filename, const char *fmt)
data = NULL;
}
FILE * f = fopen(filename,"rb");
FILE* f = fopen(filename,"rb");
if (!f)
return false;
@@ -128,7 +128,7 @@ DBCFileLoader::Record DBCFileLoader::getRecord(size_t id)
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;
int32 i = -1;
@@ -170,7 +170,7 @@ uint32 DBCFileLoader::GetFormatRecordSize(const char * format, int32* index_pos)
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 <=>
@@ -183,8 +183,8 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
this func will generate entry[rows] data;
*/
typedef char * ptr;
if (strlen(format)!=fieldCount)
typedef char* ptr;
if (strlen(format) != fieldCount)
return NULL;
//get struct size and index pos
@@ -197,8 +197,9 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
//find max index
for (uint32 y = 0; y < recordCount; ++y)
{
uint32 ind = getRecord(y).getUInt (i);
if (indi > maxi)maxi = ind;
uint32 ind = getRecord(y).getUInt(i);
if (ind > maxi)
maxi = ind;
}
// 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;
records = maxi;
indexTable = new ptr[maxi];
memset(indexTable, 0, imaxi * sizeof(ptr));
memset(indexTable, 0, maxi * sizeof(ptr));
}
else
{
@@ -249,7 +250,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
offset += sizeof(char*);
break;
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;
case FT_NA:
case FT_NA_BYTE:
@@ -306,7 +307,7 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
break;
}
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;
case FT_NA:
case FT_NA_BYTE:
@@ -321,4 +322,3 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
return stringPool;
}
+19 -23
View File
@@ -21,13 +21,13 @@
template<class T>
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);
}
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)
{
@@ -44,7 +44,7 @@ void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char *src
template<class T>
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 = 0;
@@ -52,17 +52,17 @@ void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, ch
template<class T>
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;
}
template<class T>
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));
switch(store.dst_format[x])
T* subclass = (static_cast<T*>(this));
switch (store.dst_format[x])
{
case FT_LOGIC:
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>
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));
switch(store.dst_format[x])
T* subclass = (static_cast<T*>(this));
switch (store.dst_format[x])
{
case FT_LOGIC:
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>
void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
void SQLStorageLoaderBase<T>::Load(SQLStorage& store)
{
uint32 maxi;
Field *fields;
Field* fields;
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
}
maxi = (*result)[0].GetUInt32() + 1;
maxi = result->Fetch()[0].GetUInt32() + 1;
result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
if (result)
@@ -170,7 +170,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
if (store.iNumFields != result->GetFieldCount())
{
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.
}
@@ -182,12 +182,12 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
do
{
fields = result->Fetch();
char *p = (char*)&_data[recordsize*count];
char* p = (char*)&_data[recordsize * count];
newIndex[fields[0].GetUInt32()] = p;
offset = 0;
for (uint32 x = 0; x < store.iNumFields; ++x)
switch(store.src_format[x])
switch (store.src_format[x])
{
case FT_LOGIC:
storeValue((bool)(fields[x].GetUInt32() > 0), store, p, x, offset);
@@ -216,13 +216,9 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
}
++count;
}
while( result->NextRow() );
delete result;
} while (result->NextRow());
store.pIndex = newIndex;
store.MaxEntry = maxi;
store.data = _data;
}