[Gcblue-commits] gcb_wx/src/database tcItemDBObject.cpp,NONE,1.1 CsvTranslator.cpp,1.7,1.8 tcDBStrin
Status: Alpha
Brought to you by:
ddcforge
Update of /cvsroot/gcblue/gcb_wx/src/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv840/src/database Modified Files: CsvTranslator.cpp tcDBString.cpp tcDatabase.cpp tcDatabaseObject.cpp tcSqlReader.cpp tcStoresDBObject.cpp Added Files: tcItemDBObject.cpp Log Message: Drag and drop icon gui updates Index: CsvTranslator.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/CsvTranslator.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CsvTranslator.cpp 1 Jun 2005 00:13:29 -0000 1.7 --- CsvTranslator.cpp 12 Jun 2005 20:46:57 -0000 1.8 *************** *** 203,206 **** --- 203,233 ---- /** + * @return field as long integer. This will truncate a float. + * Zero is returned if the field is empty. If the field + * has a bad format (e.g. a string field instead of a + * numerical field), zero is returned and an error is logged. + */ + long CsvTranslator::GetFieldAsLong(int n) + { + long val; + + if (n < 0 || n >= nfield) + { + cerr << "Field out of bounds (GetFieldAsInt)\n"; + return -1; + } + if (field[n].size() == 0) return 0; // do not log an error for null fields + + int scanCount = sscanf(field[n].c_str(), "%d", &val); + if (scanCount != 1) + { + fprintf(stderr, "Bad field type: '%s'(GetFieldAsLong)\n", + field[n].c_str()); + return 0; + } + return val; + } + + /** * Set output stream. Reset field vector in case object has * been used for reading. *************** *** 294,297 **** --- 321,330 ---- } + CsvTranslator& CsvTranslator::operator>>(unsigned long& val) + { + val = GetFieldAsInt(fieldIdx++); + return *this; + } + CsvTranslator& CsvTranslator::operator>>(std::string& s) { Index: tcDBString.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDBString.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcDBString.cpp 1 Jun 2005 00:13:29 -0000 1.7 --- tcDBString.cpp 12 Jun 2005 20:46:57 -0000 1.8 *************** *** 168,181 **** return true; } ! tcDBString::tcDBString(const char *buff) { strncpy(mz,buff,DB_STRING_SIZE); } ! tcDBString::tcDBString() ! { ! strcpy(mz,"DEFAULT"); ! } tcDBString::~tcDBString() { --- 168,188 ---- return true; } ! ! tcDBString::tcDBString() ! { ! strcpy(mz, "DEFAULT"); ! } ! tcDBString::tcDBString(const char *buff) { strncpy(mz,buff,DB_STRING_SIZE); } + + tcDBString::tcDBString(const tcDBString& src) + { + strncpy(mz, src.mz, DB_STRING_SIZE); + } ! tcDBString::~tcDBString() { Index: tcSqlReader.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcSqlReader.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcSqlReader.cpp 1 Jun 2005 00:13:29 -0000 1.4 --- tcSqlReader.cpp 12 Jun 2005 20:46:58 -0000 1.5 *************** *** 50,54 **** * @return data element from column name <field> as double */ ! double tcSqlReader::GetDouble(std::string& field) { unsigned int index = LookupFieldIndex(field); --- 50,54 ---- * @return data element from column name <field> as double */ ! double tcSqlReader::GetDouble(const std::string& field) { unsigned int index = LookupFieldIndex(field); *************** *** 76,80 **** * @return data element from column name <field> as int */ ! int tcSqlReader::GetInt(std::string& field) { unsigned int index = LookupFieldIndex(field); --- 76,80 ---- * @return data element from column name <field> as int */ ! int tcSqlReader::GetInt(const std::string& field) { unsigned int index = LookupFieldIndex(field); *************** *** 100,106 **** /** * throws exception if column <field> not found in map * @return data element from column name <field> as string */ ! std::string tcSqlReader::GetString(std::string& field) { unsigned int index = LookupFieldIndex(field); --- 100,132 ---- /** * throws exception if column <field> not found in map + * @return data element from column name <field> as int + */ + long tcSqlReader::GetLong(const std::string& field) + { + unsigned int index = LookupFieldIndex(field); + + return data.getlong((int)index); + } + + /** + * Version that accepts format string with variable arguments + * to create field string. + */ + long tcSqlReader::GetLong(const char* fmt, ...) + { + va_list argp; + + va_start(argp, fmt); + vsprintf(buffer, fmt, argp); + va_end(argp); + + return GetLong(std::string(buffer)); + } + + /** + * throws exception if column <field> not found in map * @return data element from column name <field> as string */ ! std::string tcSqlReader::GetString(const std::string& field) { unsigned int index = LookupFieldIndex(field); *************** *** 125,129 **** ! unsigned int tcSqlReader::LookupFieldIndex(std::string& field) { std::map<std::string, unsigned int>::const_iterator mapIter; --- 151,155 ---- ! unsigned int tcSqlReader::LookupFieldIndex(const std::string& field) { std::map<std::string, unsigned int>::const_iterator mapIter; --- NEW FILE: tcItemDBObject.cpp --- /** ** @file tcItemDBObject.cpp */ /* Copyright (C) 2005 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" #if _MSC_VER > 1000 #pragma warning(disable:4786) // suppress warning for STL bug in VC6, see Q167355 in the MSDN Library. #endif // _MSC_VER > 1000 #include "tcItemDBObject.h" #include "CsvTranslator.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" #include <sstream> #ifdef _DEBUG #define new DEBUG_NEW #endif using namespace std; namespace database { /** * workaround for write serialization issue * @return true if db obj is a leaf obj */ bool tcItemDBObject::IsLeaf() const { return mnClassID == DTYPE_ITEM; } void tcItemDBObject::PrintToFile(tcFile& file) { tcDatabaseObject::PrintToFile(file); } int tcItemDBObject::Serialize(tcFile& file, bool mbLoad, UINT32 anVersion) { tcDatabaseObject::Serialize(file,mbLoad, anVersion); return 1; } int tcItemDBObject::SerializeCSV(CsvTranslator *csv, bool mbLoad) { tcDatabaseObject::SerializeCSV(csv, mbLoad); return 1; } /** * Loads/saves XML data for database object * @param load true to load, false to save */ void tcItemDBObject::SerializeXml(TiXmlElement* node, bool load) { if (load) return; // write only for now tcDatabaseObject::SerializeXml(node, load); } int tcItemDBObject::WriteCSVHeader(database::CsvTranslator *csv) { tcDatabaseObject::WriteCSVHeader(csv); csv->WriteLine(); return 1; } /** * Adds sql column definitions to columnString. This is used for * SQL create table command */ void tcItemDBObject::AddSqlColumns(std::string& columnString) { tcDatabaseObject::AddSqlColumns(columnString); } void tcItemDBObject::ReadSql(tcSqlReader& entry) { tcDatabaseObject::ReadSql(entry); } void tcItemDBObject::WriteSql(std::string& valueString) { tcDatabaseObject::WriteSql(valueString); } tcItemDBObject::tcItemDBObject() { mzClass = "Default Item"; mnClassID = DTYPE_ITEM; } tcItemDBObject::tcItemDBObject(const tcItemDBObject& obj) : tcDatabaseObject(obj) { } tcItemDBObject::~tcItemDBObject() { } } Index: tcStoresDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcStoresDBObject.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tcStoresDBObject.cpp 1 Jun 2005 00:13:29 -0000 1.3 --- tcStoresDBObject.cpp 12 Jun 2005 20:46:58 -0000 1.4 *************** *** 179,183 **** displayName = entry.GetString("DisplayName"); ! capacity = entry.GetInt("Capacity"); moveTime = entry.GetDouble("MoveTime_s"); --- 179,183 ---- displayName = entry.GetString("DisplayName"); ! capacity = entry.GetLong("Capacity"); moveTime = entry.GetDouble("MoveTime_s"); Index: tcDatabaseObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDatabaseObject.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** tcDatabaseObject.cpp 11 Jun 2005 21:01:44 -0000 1.18 --- tcDatabaseObject.cpp 12 Jun 2005 20:46:57 -0000 1.19 *************** *** 378,395 **** mnClassID = DTYPE_OBJECT; mnType = PTYPE_UNKNOWN; ! model = NULL; } ! tcDatabaseObject::tcDatabaseObject(tcDatabaseObject& obj) { - mzClass = obj.mzClass; mnKey = obj.mnKey; mnClassID = obj.mnClassID; mnType = obj.mnType; mnModelType = obj.mnModelType; ! mzImageFileName = obj.mzImageFileName; ! mz3DModelFileName = obj.mz3DModelFileName; strcpy(mzDescription, obj.mzDescription); // BAD, assumes obj has legal string ! model = NULL; // model not copied } --- 378,396 ---- mnClassID = DTYPE_OBJECT; mnType = PTYPE_UNKNOWN; ! model = 0; } ! tcDatabaseObject::tcDatabaseObject(const tcDatabaseObject& obj) : ! mzClass(obj.mzClass), ! mzImageFileName(obj.mzImageFileName), ! mz3DModelFileName(obj.mz3DModelFileName) { mnKey = obj.mnKey; mnClassID = obj.mnClassID; mnType = obj.mnType; mnModelType = obj.mnModelType; ! strcpy(mzDescription, obj.mzDescription); // BAD, assumes obj has legal string ! model = 0; // model not copied } Index: tcDatabase.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDatabase.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** tcDatabase.cpp 1 Jun 2005 00:13:29 -0000 1.27 --- tcDatabase.cpp 12 Jun 2005 20:46:57 -0000 1.28 *************** *** 37,40 **** --- 37,41 ---- #include "tcDBObjSerializerSql.h" #include "tcGenericDBObject.h" + #include "tcItemDBObject.h" #include "tcMissileDBObject.h" #include "tcLauncherDBObject.h" *************** *** 325,328 **** --- 326,337 ---- else serializer.Save(); } + // tcItemDBObject + { + tcDBObjSerializerSql<tcItemDBObject> + serializer(this, sqlConnection, "items"); + if (load) serializer.Load(); + else serializer.Save(); + } + |