From 8c7648a51e18c90cc872ae795a6be56c95e8246a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Fri, 12 Dec 2014 12:31:24 +0100 Subject: [PATCH] Changed errorChecking in the converter. --- converter/converter.cc | 29 ++++++++++------------------- converter/converter.hh | 7 +++---- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/converter/converter.cc b/converter/converter.cc index 64643bb..2323573 100644 --- a/converter/converter.cc +++ b/converter/converter.cc @@ -33,21 +33,19 @@ Converter::Converter(std::string level){ dst << src.rdbuf(); //Load the Level xml file + nextID.push_back(1); + nextID.push_back(1); const char* charXmlFile = xmlFile.c_str(); doc->LoadFile(charXmlFile); - nextID.push_back(1); - nextID.push_back(1); if (doc->ErrorID()!=0){ printf("Could not open xml, creating new xml.\n"); + }else{ XMLElement* thisComposition = doc->FirstChildElement("composition"); int idGreen, idBlue; - XMLError error=XML_NO_ERROR; for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ - error = thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen); - errorCheck(error); - error = thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue); - errorCheck(error); + errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen)); + errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue)); if(idGreen > nextID[0] || (idGreen == nextID[0] && idBlue > nextID[1])){ nextID[0] = idGreen; nextID[1] = idBlue; @@ -116,15 +114,11 @@ void Converter::updateComposition(int idG, int idB, float posX, float posZ){ int idGreen = 0, idBlue = 0; bool compositionExists = false; for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ - XMLError error=XML_NO_ERROR; - error = thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen); - errorCheck(error); - error = thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue); - errorCheck(error); + errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen)); + errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue)); if(idGreen == idG && idBlue == idB){ bool manualPos; - error=thisComposition->FirstChildElement("manualPos")->QueryBoolText(&manualPos); - errorCheck(error); + errorCheck(thisComposition->FirstChildElement("manualPos")->QueryBoolText(&manualPos)); if(!manualPos){ thisComposition->FirstChildElement("xPos")->SetText(std::to_string(posX).c_str()); thisComposition->FirstChildElement("zPos")->SetText(std::to_string(posZ).c_str()); @@ -141,12 +135,9 @@ void Converter::updateComposition(int idG, int idB, float posX, float posZ){ void Converter::deleteComposition(int idG, int idB){ XMLElement* thisComposition = doc->FirstChildElement("composition"); int idGreen, idBlue; - XMLError error=XML_NO_ERROR; for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ - error = thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen); - errorCheck(error); - error = thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue); - errorCheck(error); + errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen)); + errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue)); if(idGreen == idG && idBlue == idB){ doc->DeleteChild(thisComposition); } diff --git a/converter/converter.hh b/converter/converter.hh index 7b603f9..bfface4 100644 --- a/converter/converter.hh +++ b/converter/converter.hh @@ -14,13 +14,12 @@ class Converter { void updateComposition(int idG, int idB, float posX, float posZ); //updates the position of a composition std::vector newComposition(int type, float posX, float posZ);//creates a new composition and returns its ID void deleteComposition(int idG, int idB); - void save(); //writes the xml to file - std::vector getNextID(); //returns the next unused ID + void save(); //writes the xml to file + std::vector getNextID(); //returns the next unused ID private: - - std::vector nextID; void errorCheck(XMLError error); + std::vector nextID; std::string xmlFile; XMLDocument* doc = new XMLDocument(); XMLDocument* compositions = new XMLDocument();