Changed errorChecking in the converter.

This commit is contained in:
Steffen Fündgens 2014-12-12 12:31:24 +01:00
parent 5ab0897653
commit 18c374c46a
2 changed files with 13 additions and 23 deletions

View File

@ -33,21 +33,19 @@ Converter::Converter(std::string level){
dst << src.rdbuf(); dst << src.rdbuf();
//Load the Level xml file //Load the Level xml file
nextID.push_back(1);
nextID.push_back(1);
const char* charXmlFile = xmlFile.c_str(); const char* charXmlFile = xmlFile.c_str();
doc->LoadFile(charXmlFile); doc->LoadFile(charXmlFile);
nextID.push_back(1);
nextID.push_back(1);
if (doc->ErrorID()!=0){ if (doc->ErrorID()!=0){
printf("Could not open xml, creating new xml.\n"); printf("Could not open xml, creating new xml.\n");
}else{ }else{
XMLElement* thisComposition = doc->FirstChildElement("composition"); XMLElement* thisComposition = doc->FirstChildElement("composition");
int idGreen, idBlue; int idGreen, idBlue;
XMLError error=XML_NO_ERROR;
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
error = thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen); errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
error = thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue);
errorCheck(error);
if(idGreen > nextID[0] || (idGreen == nextID[0] && idBlue > nextID[1])){ if(idGreen > nextID[0] || (idGreen == nextID[0] && idBlue > nextID[1])){
nextID[0] = idGreen; nextID[0] = idGreen;
nextID[1] = idBlue; nextID[1] = idBlue;
@ -116,15 +114,11 @@ void Converter::updateComposition(int idG, int idB, float posX, float posZ){
int idGreen = 0, idBlue = 0; int idGreen = 0, idBlue = 0;
bool compositionExists = false; bool compositionExists = false;
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
XMLError error=XML_NO_ERROR; errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
error = thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen); errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
errorCheck(error);
error = thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue);
errorCheck(error);
if(idGreen == idG && idBlue == idB){ if(idGreen == idG && idBlue == idB){
bool manualPos; bool manualPos;
error=thisComposition->FirstChildElement("manualPos")->QueryBoolText(&manualPos); errorCheck(thisComposition->FirstChildElement("manualPos")->QueryBoolText(&manualPos));
errorCheck(error);
if(!manualPos){ if(!manualPos){
thisComposition->FirstChildElement("xPos")->SetText(std::to_string(posX).c_str()); thisComposition->FirstChildElement("xPos")->SetText(std::to_string(posX).c_str());
thisComposition->FirstChildElement("zPos")->SetText(std::to_string(posZ).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){ void Converter::deleteComposition(int idG, int idB){
XMLElement* thisComposition = doc->FirstChildElement("composition"); XMLElement* thisComposition = doc->FirstChildElement("composition");
int idGreen, idBlue; int idGreen, idBlue;
XMLError error=XML_NO_ERROR;
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
error = thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen); errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
error = thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue);
errorCheck(error);
if(idGreen == idG && idBlue == idB){ if(idGreen == idG && idBlue == idB){
doc->DeleteChild(thisComposition); doc->DeleteChild(thisComposition);
} }

View File

@ -18,9 +18,8 @@ class Converter {
std::vector<int> getNextID(); //returns the next unused ID std::vector<int> getNextID(); //returns the next unused ID
private: private:
std::vector<int> nextID;
void errorCheck(XMLError error); void errorCheck(XMLError error);
std::vector<int> nextID;
std::string xmlFile; std::string xmlFile;
XMLDocument* doc = new XMLDocument(); XMLDocument* doc = new XMLDocument();
XMLDocument* compositions = new XMLDocument(); XMLDocument* compositions = new XMLDocument();