[Gcblue-commits] gcb_wx/src/database tcDatabase.cpp,1.7,1.8 tcDatabaseObject.cpp,1.5,1.6
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-03-25 01:44:21
|
Update of /cvsroot/gcblue/gcb_wx/src/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28131/src/database Modified Files: tcDatabase.cpp tcDatabaseObject.cpp Log Message: Index: tcDatabaseObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDatabaseObject.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tcDatabaseObject.cpp 30 Jan 2004 01:02:34 -0000 1.5 --- tcDatabaseObject.cpp 25 Mar 2004 01:33:39 -0000 1.6 *************** *** 34,37 **** --- 34,38 ---- #include "CsvTranslator.h" #include "tc3DModel.h" + #include "common/tinyxml.h" namespace Database *************** *** 208,211 **** --- 209,230 ---- return 1; } + + /** + * Loads/saves XML data for database object + * @param load true to load, false to save + */ + void tcDatabaseObject::SerializeXml(TiXmlElement* node, bool load) + { + if (load) return; // write only for now + wxASSERT(node); + + node->SetAttribute("DBCLASS", mzClass.mz); + node->SetAttribute("MODELTYPE", int(mnModelType)); + node->SetAttribute("FUNCTYPE", int(mnType)); + node->SetAttribute("IMAGE", mzImageFileName.mz); + node->SetAttribute("3DMODEL", mz3DModelFileName.mz); + TiXmlNode* descriptionNode = node->InsertEndChild(TiXmlElement("DESCRIPTION")); + descriptionNode->InsertEndChild(TiXmlText(mzDescription)); + } int tcDatabaseObject::WriteCSVHeader(Database::CsvTranslator *csv) Index: tcDatabase.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDatabase.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcDatabase.cpp 7 Feb 2004 02:19:54 -0000 1.7 --- tcDatabase.cpp 25 Mar 2004 01:33:39 -0000 1.8 *************** *** 42,45 **** --- 42,46 ---- #include "tcAirDBObject.h" #include "tcFlightportDBObject.h" + #include "common/tinyxml.h" using namespace std; *************** *** 152,155 **** --- 153,196 ---- } + /** + * @param suffix string to append after type name, e.g. "2b" -> database2b.xml + * @param load true to load DB from XML file, false to save to XML file + */ + void tcDatabase::SerializeXml(std::string suffix, bool load) + { + std::string path(DATABASE_PATH); + std::string fileName = path + string("database") + suffix + ".xml"; + if (load) return; // load not supported yet + + + // create XML document + TiXmlDocument* doc = new TiXmlDocument(fileName.c_str()); + + // create root node to be XML compliant + TiXmlNode* root = doc->InsertEndChild(TiXmlElement("DATA")); + + // for each DB object: add new TiXmlElement to doc, and call virtual SerializeXml method + // need to create iterator for this + long pos = mcObjectData.GetStartPosition(); + long objCount = mcObjectData.GetCount(); + + for (long i=0; i<objCount; i++) + { + tcDatabaseObject* obj; + long key; + mcObjectData.GetNextAssoc(pos, key, obj); + wxASSERT(obj); + + TiXmlNode* objNode = root->InsertEndChild(TiXmlElement("OBJ")); + obj->SerializeXml(objNode->ToElement(), false); + } + + // write document to file + doc->SaveFile(); + + // delete document + delete doc; + } + int tcDatabase::Serialize(tcFile& file, bool mbLoad) { tnPoolIndex nMapSize, nKey, nPoolPos; *************** *** 656,659 **** --- 697,707 ---- } + /** + * Load database from XML file. + */ + void tcDatabase::LoadDBXml(std::string suffix) + { + } + void tcDatabase::SaveDB(tcString astrDBFileName) { int nResult; *************** *** 690,693 **** --- 738,749 ---- } + /** + * Save database to XML file + */ + void tcDatabase::SaveDBXml(std::string suffix) + { + SerializeXml(suffix, false); + } + void tcDatabase::LoadDB() { |