X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMAppli.cpp;h=c66cbb871beb6deabfe5d74d36f31cbf7ee1d203;hb=ef630179c0efdb37f43994958b727f585cf2c3ec;hp=7bcc4a26a88ca7882d126ca2758004ebf862b50f;hpb=5a17d994576296f2a5a85f3a01ad5631786a0c56;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index 7bcc4a2..c66cbb8 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -486,118 +486,92 @@ void modelCDMAppli::CheckStructure(std::map& properties) bool modelCDMAppli::IsApplicationIncluded(const std::string& application_name) { - if(this->HasCMakeLists()) - { - std::ifstream CMFile(this->CMakeLists->GetPath().c_str()); - if (CMFile.is_open()) - { - std::string line; - while(!CMFile.eof()) - { - std::getline(CMFile, line); - while(line[0]==' ') - line.erase(0,1); - if(line[0] != '#') - { - std::vector lineSeg; - CDMUtilities::splitter::split(lineSeg,line,"()",CDMUtilities::splitter::no_empties); - if(lineSeg.size() > 0 && lineSeg[0] == "ADD_SUBDIRECTORY" && lineSeg[1] == application_name) - { - CMFile.close(); - return true; - } - } - } - CMFile.close(); - } - } - return false; + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + for (int i = 0; i < cmlFile.size(); ++i) + { + if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (application_name == cmlFile[i].second[pos]) + return true; + break; + } + pos++; + } + } + } + } + return false; } bool modelCDMAppli::SetApplicationInclude(const std::string& application_name, const bool& toInclude) { if (this->HasCMakeLists()) { - std::ifstream CMFile(this->CMakeLists->GetPath().c_str()); - if (CMFile.is_open()) + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + + bool found = false; + + for (int i = 0; i < cmlFile.size(); ++i) { - std::stringstream outs; - std::string line; - bool found = false; - while(!CMFile.eof()) + if(toInclude && cmlFile[i].first == "comment") { - std::getline(CMFile, line); - if (CMFile.eof()) { - break; - } - if(line != "") + std::vector segments; + std::string line = cmlFile[i].second[0]; + while(line[0] == '#') + line.erase(0,1); + + CDMUtilities::splitter::split(segments, line, " ()", CDMUtilities::splitter::no_empties); + if (segments.size() > 1 && segments[0] == "ADD_SUBDIRECTORY" && segments[1] == application_name) { - std::vector segs; - CDMUtilities::splitter::split(segs, line, " ", CDMUtilities::splitter::no_empties); - //is comment - if(segs.size() > 0 && segs[0][0] == '#') - { - if(toInclude) - { - CDMUtilities::splitter::split(segs, line, " #()", CDMUtilities::splitter::no_empties); - if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == application_name) - { - found = true; - outs << "ADD_SUBDIRECTORY(" << application_name << ")\n"; - } - else - outs << line << "\n"; - } - else - { - outs << line << "\n"; - } - } - //is not comment - else + found = true; + while(cmlFile[i].second[0][0] == '#') + cmlFile[i].second[0].erase(0,1); + } + } + else if(cmlFile[i].first == "command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') { - if (segs.size() > 0 && !toInclude) - { - CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties); - if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == application_name) - { - outs << "#" << line << "\n"; - } - else - { - outs << line << "\n"; - } - } - else + if (application_name == cmlFile[i].second[pos]) { - CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties); - if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == application_name) + found = true; + if (!toInclude) { - found = true; + cmlFile[i].first = "comment"; + cmlFile[i].second[0] = "#" + cmlFile[i].second[0]; + while (cmlFile[i].second.size() > 1) + { + cmlFile[i].second[0] += cmlFile[i].second[1]; + cmlFile[i].second.erase(cmlFile[i].second.begin()+1); + } + } - outs << line << "\n"; } + break; } - } - else - { - outs << "\n"; + pos++; } } - - CMFile.close(); - - if(!found && toInclude) - outs << "ADD_SUBDIRECTORY(" << application_name << ")\n"; - - std::ofstream CMFileOut(this->CMakeLists->GetPath().c_str()); - if (CMFileOut.is_open()) - { - CMFileOut << outs.rdbuf(); - CMFileOut.close(); - return true; - } } + if (!found && toInclude) + { + CDMUtilities::syntaxElement element; + element.first = "command"; + element.second.push_back("ADD_SUBDIRECTORY(" + application_name + ")"); + cmlFile.push_back(element); + } + + return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile); } return false; }