X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMLib.cpp;h=57411ec64f340fc70288a41e9d364eb33904831c;hb=741b9c1d03c7984f7ac4a39188e2bb114471f579;hp=16211eed4ade6c269d87e23b93971cda679d397a;hpb=5af1633cdea030f5189c57c51bd843685eecd8b6;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMLib.cpp b/lib/creaDevManagerLib/modelCDMLib.cpp index 16211ee..57411ec 100644 --- a/lib/creaDevManagerLib/modelCDMLib.cpp +++ b/lib/creaDevManagerLib/modelCDMLib.cpp @@ -35,6 +35,7 @@ #include "modelCDMLib.h" #include +#include #include #include "CDMUtilities.h" @@ -45,9 +46,10 @@ modelCDMLib::modelCDMLib() { } -modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const int& level) +modelCDMLib::modelCDMLib(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level) { std::cout << "creating lib\n"; + this->parent = parent; this->type = wxDIR_DIRS; this->name = name; this->level = level; @@ -72,13 +74,13 @@ modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const if(stdfileName != "template_lib") { - modelCDMLibrary* library = new modelCDMLibrary(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + modelCDMLibrary* library = new modelCDMLibrary(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->libraries.push_back(library); this->children.push_back(library); } else { - modelCDMFolder* folder = new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + modelCDMFolder* folder = new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(folder); } @@ -93,13 +95,13 @@ modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") { - this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } //if is an unknown file, create file else { - this->children.push_back(new modelCDMFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } cont = dir.GetNext(&fileName); @@ -156,7 +158,7 @@ modelCDMLibrary* modelCDMLib::CreateLibrary( } //add library to model - modelCDMLibrary* library = new modelCDMLibrary(this->path + CDMUtilities::SLASH + name, name, this->level + 1); + modelCDMLibrary* library = new modelCDMLibrary(this, this->path + CDMUtilities::SLASH + name, name, this->level + 1); this->libraries.push_back(library); this->children.push_back(library); @@ -191,7 +193,7 @@ const bool modelCDMLib::Refresh(std::string*& result) std::string libraryName = stdfileName; //check if library already exist bool found = false; - for (int i = 0; !found && i < this->libraries.size(); i++) + for (int i = 0; !found && i < (int)(this->libraries.size()); i++) { if (this->libraries[i]->GetName() == libraryName) { @@ -205,7 +207,7 @@ const bool modelCDMLib::Refresh(std::string*& result) } if(!found) { - modelCDMLibrary* library = new modelCDMLibrary(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + modelCDMLibrary* library = new modelCDMLibrary(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->libraries.push_back(library); this->children.push_back(library); } @@ -214,7 +216,7 @@ const bool modelCDMLib::Refresh(std::string*& result) { //check if folder already exist bool found = false; - for (int i = 0; !found && i < this->children.size(); i++) + for (int i = 0; !found && i < (int)(this->children.size()); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -226,7 +228,7 @@ const bool modelCDMLib::Refresh(std::string*& result) } if(!found) { - modelCDMFolder* folder= new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + modelCDMFolder* folder= new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(folder); } } @@ -243,7 +245,7 @@ const bool modelCDMLib::Refresh(std::string*& result) { if (this->CMakeLists == NULL) { - this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } else @@ -258,7 +260,7 @@ const bool modelCDMLib::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; !found && i < this->children.size(); i++) + for (int i = 0; !found && i < (int)(this->children.size()); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -271,7 +273,7 @@ const bool modelCDMLib::Refresh(std::string*& result) if(!found) { - modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(file); } } @@ -280,7 +282,7 @@ const bool modelCDMLib::Refresh(std::string*& result) } } - for (int i = 0; i < checkedLibraries.size(); i++) + for (int i = 0; i < (int)(checkedLibraries.size()); i++) { if(!checkedLibraries[i]) { @@ -289,7 +291,7 @@ const bool modelCDMLib::Refresh(std::string*& result) i--; } } - for (int i = 0; i < checked.size(); i++) + for (int i = 0; i < (int)(checked.size()); i++) { if(!checked[i]) { @@ -303,3 +305,76 @@ const bool modelCDMLib::Refresh(std::string*& result) std::sort(this->libraries.begin(), this->libraries.end(), CompareNodeItem); return true; } + +void modelCDMLib::CheckStructure(std::map& properties) +{ + //check cmake exist + if(this->CMakeLists != NULL) + { + //set properties parameters based on model + for (int i = 0; i < (int)(this->libraries.size()); i++) + properties["lib add " + libraries[i]->GetName()] = false; + + //open cmakelists + std::ifstream confFile; + confFile.open((this->CMakeLists->GetPath()).c_str()); + + //take everything that is not commented + std::string fileContent; + + std::string word; + std::vector words; + while(confFile.is_open() && !confFile.eof()) + { + std::getline(confFile,word, '\n'); + if(word[0] != '#') + { + CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok); + if (words.size() > 0) + { + word = words[0]; + CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok); + for (int i = 0; i < (int)(words.size()); i++) + { + if(words[i].substr(0,2) == "//") + break; + fileContent += words[i] + " "; + } + } + } + } + + //check every instruction + std::stringstream ss(fileContent); + while(!ss.eof()) + { + std::getline(ss,word, '('); + + //check instruction name + CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties); + + //add instructions + if (words.size() > 0 && words[words.size()-1] == "ADD_SUBDIRECTORY") + { + std::getline(ss,word, ')'); + //std::cout << word << std::endl; + CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties); + + if (words.size() > 0) + { + { + properties["lib add " + words[0]] = true; + } + } + } + } + + } + + //check libraries' structure + for (int i = 0; i < (int)(this->libraries.size()); i++) + { + properties["library " + this->libraries[i]->GetName()] = true; + this->libraries[i]->CheckStructure(properties); + } +}