X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMPackage.cpp;h=377a11bb8303629c5a2c8af0858276e1a600004d;hb=f10df58dfa9c4d8489fe35f57f796bcf37e5f9b4;hp=e565dec98f6728bdc933c7a75d01cf9f6ee6a736;hpb=0cc6a7e002ad79de9453517108d7456fd44ddfdb;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMPackage.cpp b/lib/creaDevManagerLib/modelCDMPackage.cpp index e565dec..377a11b 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.cpp +++ b/lib/creaDevManagerLib/modelCDMPackage.cpp @@ -163,6 +163,12 @@ modelCDMPackage::modelCDMPackage(modelCDMIProjectTreeNode* parent, const std::st 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") @@ -170,11 +176,23 @@ modelCDMPackage::modelCDMPackage(modelCDMIProjectTreeNode* parent, const std::st this->CMakeLists = new modelCDMCMakeListsFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } + //if is a code file, create code file + else if(fileType == ".c" || + fileType == ".cxx" || + fileType == ".h" || + fileType == ".cpp" || + fileType == ".txx" || + fileType == ".cmake" ) + { + modelCDMCodeFile* file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + this->children.push_back(file); + } + //if is an unknown file, create file else { this->children.push_back(new modelCDMFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } - //if is an unknown file, create file + cont = dir.GetNext(&fileName); } } @@ -529,6 +547,12 @@ const bool modelCDMPackage::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") @@ -563,8 +587,22 @@ const bool modelCDMPackage::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); + } } } @@ -763,20 +801,13 @@ bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name, if (correspondence.find(library_name) != correspondence.end()) { std::string library_command = correspondence[library_name]; -// std::cout << "found correspondence " << library_command << std::endl; -// std::cout.flush(); if (this->HasCMakeLists()) { std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); std::string resCMfile = ""; bool found = false; -// std::cout << "found cmakefile: " << CMfile << std::endl; -// std::cout.flush(); - try { -// std::cout << "first regex" << std::endl; -// std::cout.flush(); boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)"); std::string::const_iterator start, end; @@ -786,8 +817,6 @@ bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name, boost::match_flag_type flags = boost::match_default; if(boost::regex_search(start, end, what, expression, flags)) { -// std::cout << "found " << what.str() << std::endl; -// std::cout.flush(); found = true; resCMfile += what.prefix().str(); if (toInclude) @@ -800,49 +829,69 @@ bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name, } else { -// std::cout << "second regex" << std::endl; -// std::cout.flush(); - boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)"); + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+OFF([\\s]|#[^\\n]*\\n)*\\)"); + + start = CMfile.begin(); + end = CMfile.end(); if(boost::regex_search(start, end, what, expression, flags)) { found = true; resCMfile += what.prefix().str(); - if(toInclude) + if (toInclude) { - std::string dete = what[0].str(); - for (int i = 0; i < dete.size(); ++i) { - if (dete[i] != '#') - resCMfile.push_back(dete[i]); - if (dete[i] == 'S') - { - resCMfile += dete.substr(i+1); - break; - } - } + std::string dete = what.str(); + int pos = dete.rfind("OFF"); + dete.replace(pos, 3, "ON"); + resCMfile += dete; } else resCMfile += what.str(); - resCMfile += what.suffix().str(); + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); } else { -// std::cout << "third regex" << std::endl; -// std::cout.flush(); - boost::regex expression("^\\h*#\\h*UNCOMMENT EACH LIBRARY NEEDED \\(WILL BE FOUND AND USED AUTOMATICALLY\\)[^\\n]*\\n"); + boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)"); if(boost::regex_search(start, end, what, expression, flags)) { found = true; resCMfile += what.prefix().str(); - resCMfile += what.str(); if(toInclude) { - resCMfile += "SET(${BBTK_PACKAGE_NAME}"+ library_command +" ON)\n"; + std::string dete = what[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + if (dete[i] == 'S') + { + resCMfile += dete.substr(i+1); + break; + } + } } + else + resCMfile += what.str(); + resCMfile += what.suffix().str(); return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); } + else + { + boost::regex expression("^\\h*#\\h*UNCOMMENT EACH LIBRARY NEEDED \\(WILL BE FOUND AND USED AUTOMATICALLY\\)[^\\n]*\\n"); + if(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + resCMfile += what.str(); + if(toInclude) + { + resCMfile += "SET(${BBTK_PACKAGE_NAME}"+ library_command +" ON)\n"; + } + resCMfile += what.suffix().str(); + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } } } } catch (boost::bad_expression& e) {