+
+void modelCDMProject::CheckStructure(std::map<std::string, bool>& properties)
+{
+ //check cmake exist
+ if(this->CMakeLists != NULL)
+ {
+ //set properties parameters based on model
+ properties["project add appli"] = this->appli != NULL;
+ properties["project add lib"] = this->lib != NULL;
+ for (int i = 0; i < (int)(this->packages.size()); i++)
+ properties["project add " + packages[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<std::string> 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);
+
+ //set instructions
+ if (words.size() > 0 && words[words.size()-1] == "SET")
+ {
+ std::getline(ss,word, ')');
+
+ CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
+ if (words.size() > 1)
+ {
+ if (words[0] == "USE_CREA" && words[1] == "ON")
+ {
+ properties["project set USE_CREA"] = true;
+ }
+ else if (words[0] == "USE_GDCM" && words[1] == "ON")
+ {
+ properties["project set USE_GDCM"] = true;
+ }
+ else if (words[0] == "USE_GDCM_VTK" && words[1] == "ON")
+ {
+ properties["project set USE_GDCM_VTK"] = true;
+ }
+ else if (words[0] == "USE_GDCM2" && words[1] == "ON")
+ {
+ properties["project set USE_GDCM2"] = true;
+ }
+ else if (words[0] == "USE_WXWIDGETS" && words[1] == "ON")
+ {
+ properties["project set USE_WXWIDGETS"] = true;
+ }
+ else if (words[0] == "USE_KWWIDGETS" && words[1] == "ON")
+ {
+ properties["project set USE_KWWIDGETS"] = true;
+ }
+ else if (words[0] == "USE_VTK" && words[1] == "ON")
+ {
+ properties["project set USE_VTK"] = true;
+ }
+ else if (words[0] == "USE_ITK" && words[1] == "ON")
+ {
+ properties["project set USE_ITK"] = true;
+ }
+ else if (words[0] == "USE_BOOST" && words[1] == "ON")
+ {
+ properties["project set USE_BOOST"] = true;
+ }
+ }
+ }
+ //add instructions
+ else 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)
+ {
+ if(words[0] == "appli")
+ {
+ properties["project add "+words[0]] = this->appli != NULL;
+ }
+ else if(words[0] == "lib")
+ {
+ properties["project add "+words[0]] = this->lib != NULL;
+ }
+ else
+ {
+ properties["project add "+words[0]] = true;
+ }
+ }
+ }
+ }
+
+ }
+
+ //check appli's structure
+ this->appli->CheckStructure(properties);
+ //check lib's structure
+ this->lib->CheckStructure(properties);
+ //check packages' structure
+ for (int i = 0; i < (int)(this->packages.size()); i++)
+ {
+ properties["package " + this->packages[i]->GetName()] = true;
+ this->packages[i]->CheckStructure(properties);
+ }
+}
+
+bool modelCDMProject::IsPackageIncluded(const std::string& package_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<std::string> lineSeg;
+ CDMUtilities::splitter::split(lineSeg,line,"()",CDMUtilities::splitter::no_empties);
+ if(lineSeg.size() > 0 && lineSeg[0] == "ADD_SUBDIRECTORY" && lineSeg[1] == package_name)
+ {
+ CMFile.close();
+ return true;
+ }
+ }
+ }
+ 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())
+ {
+ std::stringstream outs;
+ std::string line;
+ bool found = false;
+ while(!CMFile.eof())
+ {
+ std::getline(CMFile, line);
+ if (CMFile.eof()) {
+ break;
+ }
+ if(line != "")
+ {
+ std::vector<std::string> 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
+ {
+ 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
+ {
+ CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties);
+ if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_name)
+ {
+ found = true;
+ }
+ outs << line << "\n";
+ }
+ }
+ }
+ else
+ {
+ outs << "\n";
+ }
+ }
+
+ 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;
+ }
+ }
+ }
+ return false;
+}