X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMLib.cpp;h=48df51b85c29581095b42db809baa4ab4449cbe0;hb=76962b2ed3513cee0f6afd83b9d93e2b43bdefc5;hp=38cd30df188cdf8a06faf7c326f9272d7ad5380c;hpb=35dd4d1ddf73a91d308cc49fc394104169936055;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMLib.cpp b/lib/creaDevManagerLib/modelCDMLib.cpp index 38cd30d..48df51b 100644 --- a/lib/creaDevManagerLib/modelCDMLib.cpp +++ b/lib/creaDevManagerLib/modelCDMLib.cpp @@ -91,6 +91,12 @@ modelCDMLib::modelCDMLib(modelCDMIProjectTreeNode* parent, const std::string& pa while (cont) { std::string stdfileName = crea::wx2std(fileName); + std::size_t fileTypePos = stdfileName.find_last_of("."); + std::string fileType; + if(fileTypePos != std::string::npos) + fileType = stdfileName.substr(fileTypePos); + else + fileType = ""; //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") @@ -98,6 +104,17 @@ modelCDMLib::modelCDMLib(modelCDMIProjectTreeNode* parent, const std::string& pa 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 { @@ -268,6 +285,13 @@ const bool modelCDMLib::Refresh(std::string*& result) while (cont) { std::string stdfileName = crea::wx2std(fileName); + std::size_t fileTypePos = stdfileName.find_last_of("."); + std::string fileType; + if(fileTypePos != std::string::npos) + fileType = stdfileName.substr(fileTypePos); + else + fileType = ""; + //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") @@ -302,8 +326,22 @@ const bool modelCDMLib::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 is a code file, create modelCDMCodeFile + 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); + } } } @@ -410,29 +448,25 @@ void modelCDMLib::CheckStructure(std::map& properties) bool modelCDMLib::IsLibraryIncluded(const std::string& library_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] == library_name) + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') { - CMFile.close(); - return true; + if (library_name == cmlFile[i].second[pos]) + return true; + break; } + pos++; } } - CMFile.close(); } } return false; @@ -442,87 +476,64 @@ bool modelCDMLib::SetLibraryInclude(const std::string& library_name, const bool& { 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] == library_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] == library_name) - { - found = true; - outs << "ADD_SUBDIRECTORY(" << library_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] == library_name) - { - outs << "#" << line << "\n"; - } - else - { - outs << line << "\n"; - } - } - else + if (library_name == cmlFile[i].second[pos]) { - CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties); - if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == library_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(" << library_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(" + library_name + ")"); + cmlFile.push_back(element); + } + + return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile); } return false; }