X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMAppli.cpp;h=70471a785dc60e13d4b5b089a9dcabc7676f16f4;hb=dd9de710df141a074f10d0cab27b217425ecab20;hp=62d02a9c0191fdcf0276644de409673479924388;hpb=9f11db34cb1acacf545f819d6b552a95835d93bd;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index 62d02a9..70471a7 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -90,6 +90,8 @@ modelCDMAppli::modelCDMAppli(modelCDMIProjectTreeNode* parent, const std::string while (cont) { std::string stdfileName = crea::wx2std(fileName); + std::size_t fileTypePos = stdfileName.find_last_of("."); + std::string fileType = stdfileName.substr(fileTypePos); //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") @@ -97,6 +99,17 @@ modelCDMAppli::modelCDMAppli(modelCDMIProjectTreeNode* parent, const std::string this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } + //if is a code file, create modelCDMCodeFile + else if( + fileType == ".c" || + fileType == ".cxx" || + fileType == ".h" || + fileType == ".cpp" || + fileType == ".txx" || + fileType == ".cmake" ) + { + this->children.push_back(new modelCDMCodeFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + } //if is an unknown file, create file else { @@ -344,6 +357,8 @@ const bool modelCDMAppli::Refresh(std::string*& result) while (cont) { std::string stdfileName = crea::wx2std(fileName); + std::size_t fileTypePos = stdfileName.find_last_of("."); + std::string fileType = stdfileName.substr(fileTypePos); //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") @@ -361,6 +376,7 @@ const bool modelCDMAppli::Refresh(std::string*& result) return false; } } + //if is a code file, create modelCDMCodeFile //if is an unknown file, create file else { @@ -378,8 +394,21 @@ const bool modelCDMAppli::Refresh(std::string*& result) if(!found) { - modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); - this->children.push_back(file); + if( + fileType == ".c" || + fileType == ".cxx" || + fileType == ".h" || + fileType == ".cpp" || + fileType == ".txx" || + fileType == ".cmake" ) + { + this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + } + else + { + modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + this->children.push_back(file); + } } } @@ -486,115 +515,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); - 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(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; } + pos++; } - else - { - outs << "\n"; - } - } - - 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; }