X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMProject.cpp;h=08cafc74f530d554663117f56d05106ee6c34d43;hb=ef630179c0efdb37f43994958b727f585cf2c3ec;hp=d26932d61504c65033393978a1ccdf5d69173be6;hpb=5a17d994576296f2a5a85f3a01ad5631786a0c56;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index d26932d..08cafc7 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -1012,118 +1012,93 @@ void modelCDMProject::CheckStructure(std::map& properties) bool modelCDMProject::IsPackageIncluded(const std::string& package_name) { - if(this->HasCMakeLists()) + 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()); + for (int i = 0; i < cmlFile.size(); ++i) { - std::string line; - while(!CMFile.eof()) + if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") { - std::getline(CMFile, line); - while(line[0]==' ') - line.erase(0,1); - if(line[0] != '#') + int pos = 1; + while (pos < cmlFile[i].second.size()) { - std::vector lineSeg; - CDMUtilities::splitter::split(lineSeg,line,"()",CDMUtilities::splitter::no_empties); - if(lineSeg.size() > 0 && lineSeg[0] == "ADD_SUBDIRECTORY" && lineSeg[1] == package_name) + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') { - CMFile.close(); - return true; + if (package_name == cmlFile[i].second[pos]) + return true; + break; } + pos++; } } - CMFile.close(); } } return false; + } bool modelCDMProject::SetPackageInclude(const std::string& package_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] == package_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] == package_name) - { - found = true; - outs << "ADD_SUBDIRECTORY(" << package_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] == package_name) - { - outs << "#" << line << "\n"; - } - else - { - outs << line << "\n"; - } - } - else + if (package_name == cmlFile[i].second[pos]) { - CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties); - if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_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(" << package_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(" + package_name + ")"); + cmlFile.push_back(element); + } + + return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile); } return false; }