]> Creatis software - crea.git/commitdiff
Feature #1711 CreaDevManager application implementation
authorDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Tue, 16 Apr 2013 09:20:32 +0000 (11:20 +0200)
committerDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Tue, 16 Apr 2013 09:20:32 +0000 (11:20 +0200)
Fix: Problem when creating cpp and cxx files in applications. Now using regex to check if file is the application's main file.

lib/creaDevManagerLib/CMakeLists.txt
lib/creaDevManagerLib/modelCDMApplication.cpp

index 37aa14e1ced15d716ffb7def417428f10412c697..bb1dbea12bb24554962021003dfe1ae332032d56 100644 (file)
@@ -1,7 +1,7 @@
 # ---------------------------------------------------------------------
 #
 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
-#                        pour la Santé)
+#                        pour la Sant)
 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
@@ -83,7 +83,7 @@ IF ( BUILD_${LIBRARY_NAME} )
   #    ${VTK_LIBRARIES}
   #    ${ITK_LIBRARIES}
   #    ${GDCM_LIBRARIES}
-  #    ${BOOST_LIBRARIES}
+      ${BOOST_LIBRARIES}
 
   # If this library must link against other libraries 
   # USER! : Add here any extra Library you need
index 0ee18a913fa037ed71e1065488b54f6cb5785d57..f7f7431bdd3af8cec850e6974767f13031f28ac3 100644 (file)
@@ -37,6 +37,7 @@
 #include <fstream>
 #include <sstream>
 #include <algorithm>
+#include <boost/regex.hpp>
 
 #include "CDMUtilities.h"
 #include "creaWx.h"
@@ -117,7 +118,6 @@ modelCDMApplication::modelCDMApplication(modelCDMIProjectTreeNode* parent, const
       while (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-
           //if CMakeLists, create CMakeLists
           if(stdfileName == "CMakeLists.txt")
             {
@@ -129,23 +129,46 @@ modelCDMApplication::modelCDMApplication(modelCDMIProjectTreeNode* parent, const
             {
               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"))
                 {
-                  std::ifstream fileStream;
-                  std::string word;
-                  fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
-                  while (fileStream.is_open() && !fileStream.eof())
+                  std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str());
+
+                  if (fileStream.is_open())
                     {
-                      //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::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
+                        {
+                          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;
+                            }
+                        }
                     }
-                  fileStream.close();
+
                 }
               this->children.push_back(file);
             }