]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMApplication.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / modelCDMApplication.cpp
index 5d0f597df42de34211590bb008739ffa6412e660..d214ac4cf97bae0b393eb24720eb89b2f8213d02 100644 (file)
@@ -122,59 +122,76 @@ modelCDMApplication::modelCDMApplication(modelCDMIProjectTreeNode* parent, const
       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")
             {
               this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(this->CMakeLists);
             }
-          //if is an unknown file, create file
           else
             {
-              modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
-              std::string extension = stdfileName.substr(stdfileName.size()-4);
-              //if is cxx or cpp check if is the main file.
-              if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
+              //if is a code file, create modelCDMCodeFile and check for main file
+              if(
+                fileType == ".c" ||
+                fileType == ".cxx" ||
+                fileType == ".h" ||
+                fileType == ".cpp" ||
+                fileType == ".txx" ||
+                fileType == ".cmake" )
                 {
-                  std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str());
+                  modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
 
-                  if (fileStream.is_open())
+                  if (mainFile == NULL && (fileType == ".cxx" || fileType == ".cpp"))
                     {
-                      std::string fileContent = "";
-                      char ch = fileStream.get();
-                      while(!fileStream.eof())
-                        {
-                          fileContent.push_back(ch);
-                          ch = fileStream.get();
-                        }
-                      fileStream.close();
-
-                      boost::regex expression("^\\h*IMPLEMENT_APP[#\\s\\(]");
-                      std::string::const_iterator start, end;
-                      start = fileContent.begin();
-                      end = fileContent.end();
-                      boost::match_results<std::string::const_iterator> what;
-                      boost::match_flag_type flags = boost::match_default;
-                      if(boost::regex_search(start, end, what, expression, flags))
-                        {
-                          std::cout << "found main wxwidgets file: " << stdfileName << std::endl;
-                          this->mainFile = file;
-                        }
-                      else
+                      std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str());
+
+                      if (fileStream.is_open())
                         {
-                          expression = boost::regex("^\\h*int\\h+main[#\\s\\(]");
+                          std::string fileContent = "";
+                          char ch = fileStream.get();
+                          while(!fileStream.eof())
+                            {
+                              fileContent.push_back(ch);
+                              ch = fileStream.get();
+                            }
+                          fileStream.close();
+
+                          boost::regex expression("^\\h*IMPLEMENT_APP[#\\s\\(]");
+                          std::string::const_iterator start, end;
                           start = fileContent.begin();
                           end = fileContent.end();
+                          boost::match_results<std::string::const_iterator> what;
+                          boost::match_flag_type flags = boost::match_default;
                           if(boost::regex_search(start, end, what, expression, flags))
                             {
-                              std::cout << "found main console file: " << stdfileName << std::endl;
+                              std::cout << "found main wxwidgets file: " << stdfileName << std::endl;
                               this->mainFile = file;
                             }
+                          else
+                            {
+                              expression = boost::regex("^\\h*int\\h+main[#\\s\\(]");
+                              start = fileContent.begin();
+                              end = fileContent.end();
+                              if(boost::regex_search(start, end, what, expression, flags))
+                                {
+                                  std::cout << "found main console file: " << stdfileName << std::endl;
+                                  this->mainFile = file;
+                                }
+                            }
                         }
                     }
-
+                  this->children.push_back(file);
+                }
+              //if is an unknown file, create file
+              else
+                {
+                  modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  this->children.push_back(file);
                 }
-              this->children.push_back(file);
+
             }
 
           cont = dir.GetNext(&fileName);
@@ -347,6 +364,8 @@ const bool modelCDMApplication::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")
@@ -364,7 +383,8 @@ const bool modelCDMApplication::Refresh(std::string*& result)
                     return false;
                 }
             }
-          //if is an unknown file, create file
+          // if is a code file, create modelCDMCodeFile
+          // if is an unknown file, create file
           else
             {
               bool found = false;
@@ -392,7 +412,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
                               CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
                               if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
                                 {
-                                  this->mainFile = dynamic_cast<modelCDMFile*>(children[i]);
+                                  this->mainFile = dynamic_cast<modelCDMCodeFile*>(children[i]);
                                 }
                             }
                           fileStream.close();
@@ -402,29 +422,40 @@ const bool modelCDMApplication::Refresh(std::string*& result)
 
               if(!found)
                 {
-                  modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
-
-                  std::string extension = stdfileName.substr(stdfileName.size()-4);
-                  if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
+                  if (fileType == ".c" ||
+                    fileType == ".cxx" ||
+                    fileType == ".h" ||
+                    fileType == ".cpp" ||
+                    fileType == ".txx" ||
+                    fileType == ".cmake" )
                     {
-                      std::ifstream fileStream;
-                      std::string word;
-                      fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
-                      while (fileStream.is_open() && !fileStream.eof())
+                      modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+
+                      if(mainFile == NULL && (fileType == ".cxx" || fileType == ".cpp"))
                         {
-                          //get sets
-                          std::getline(fileStream,word,'(');
-                          std::vector<std::string> wordBits;
-                          CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
-                          if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
+                          std::ifstream fileStream;
+                          std::string word;
+                          fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
+                          while (fileStream.is_open() && !fileStream.eof())
                             {
-                              this->mainFile = file;
+                              //get sets
+                              std::getline(fileStream,word,'(');
+                              std::vector<std::string> wordBits;
+                              CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
+                              if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
+                                {
+                                  this->mainFile = file;
+                                }
                             }
+                          fileStream.close();
                         }
-                      fileStream.close();
+                      this->children.push_back(file);
+                    }
+                  else
+                    {
+                      modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                      this->children.push_back(file);
                     }
-
-                  this->children.push_back(file);
                 }
             }