]> Creatis software - bbtk.git/commitdiff
Compil sous Windows
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 6 May 2008 13:45:11 +0000 (13:45 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 6 May 2008 13:45:11 +0000 (13:45 +0000)
13 files changed:
kernel/cmake/BBTKFindLibraries.cmake
kernel/src/CMakeLists.txt
kernel/src/bbtkBlackBox.cxx
kernel/src/bbtkBlackBox.h
kernel/src/bbtkBlackBoxDescriptor.cxx
kernel/src/bbtkInterpreter.h
kernel/src/bbtkObject.h
kernel/src/bbtkPackage.cxx
kernel/src/bbtkUtilities.cxx
kernel/src/bbtkUtilities.h
kernel/src/bbtkVirtualExec.h
kernel/src/bbtkWxBlackBox.cxx
kernel/src/bbtkWxGUIConsole.cxx

index f39f1ebf40ab5f8abee1f25d571b1adaf16b3bd3..38fbf990cd3a327017e7f3916a4bdaed012eed51 100644 (file)
@@ -174,7 +174,8 @@ IF(USE_BOOST)
     INCLUDE_DIRECTORIES( 
       ${PROJECT_SOURCE_DIR}/kernel/src/ThirdParty/${BBTK_SHIPPED_BOOST})
 
-
+    # TO DO : CLEANLY BLOCK auto_link.hpp INCLUSION 
+    #ADD_DEF(BOOST_SIGNALS_NO_LIB)
     SET(BBTK_BOOST_LIBRARIES
       bbtk_boost_signals
       )  
index 078fffd77e4ef4926da835ae08201d9b0b2ed874..e3b5e43e90f22f6406164fe8b4560c31abe1d193 100644 (file)
@@ -100,7 +100,7 @@ IF(BBTK_USE_BOOST)
   SET(BBTK_LINK_LIBRARIES
     ${BBTK_LINK_LIBRARIES}
     ${BBTK_BOOST_LIBRARIES} 
-    )  
+    ) 
 ENDIF(BBTK_USE_BOOST)
 #-----------------------------------------------------------------------------
 
index edca10ce191024bd2a961e6013ba11534e5a1349..51a9ab7cfe824b790f5cd30cdc780c67003412c4 100644 (file)
@@ -3,8 +3,8 @@
 Program:   bbtk
 Module:    $RCSfile: bbtkBlackBox.cxx,v $
 Language:  C++
-Date:      $Date: 2008/04/24 10:11:27 $
-Version:   $Revision: 1.16 $
+Date:      $Date: 2008/05/06 13:45:12 $
+Version:   $Revision: 1.17 $
                                                                                 
 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
 l'Image). All rights reserved. See doc/license.txt or
@@ -103,6 +103,9 @@ namespace bbtk
   }
   //=========================================================================
 
+  //=========================================================================
+  BlackBox::BlackBox(const BlackBox&)
+  {}
 
   //=========================================================================
   BlackBox::BlackBox(BlackBox& from, const std::string &name) 
index 48509a1930ac2e48a768f432e2e85f888611f36d..eb6f46c60e8e030f9ee6e9daf1578fbbda2df6f7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.h,v $
   Language:  C++
-  Date:      $Date: 2008/04/22 14:30:25 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
@@ -377,7 +377,7 @@ bool reaction = true);
     /// Black box deleter 
     /// 1) Calls the user overloadable bbDelete method
     /// 2) Releases the box descriptor
-    struct Deleter : public Object::Deleter
+    struct BBTK_EXPORT Deleter : public Object::Deleter
     { 
       Deleter();
       void Delete(Object* p);
index e0156087f0b80dcf6622b09b72a16ea4ba2bfdcf..e4318a7a3dd3d7259bef6bb5486509d2cc76a89e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/18 12:59:15 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -51,6 +51,11 @@ namespace bbtk
   }
   //=========================================================================
 
+  //=========================================================================
+  /// Default ctor
+  BlackBoxDescriptor::BlackBoxDescriptor(const BlackBoxDescriptor&)  
+  {
+  }
   //=========================================================================
   /// Dtor
   BlackBoxDescriptor::~BlackBoxDescriptor()
index 8440873b352781f93eb0a1a6dcd7346a9ab1f705..2e7ba4df6f2c0462179108c1bcf6e910f3e2d277 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.h,v $ $
   Language:  C++
-  Date:      $Date: 2008/04/25 08:05:23 $
-  Version:   $Revision: 1.29 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.30 $
 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -86,7 +86,7 @@ namespace bbtk
   //=======================================================================
   class BBTK_EXPORT Interpreter : public Object
   {
-    BBTK_OBJECT_INTERFACE(Interpreter);
+    BBTK_OBJECT_INTERFACE_NO_CONDES(Interpreter);
     typedef Object Superclass;
   public:
     static Pointer New(const std::string& cpp_file = "");
@@ -319,6 +319,9 @@ namespace bbtk
     
     bool mThrow;
 
+       protected:
+       ~Interpreter();
+
   };
   // EO class Interpreter
 
index 27ed132e5c90d23c9c842fe70535945bc53e86da..ac9a5b98003025f61f6b1be2b996633253c7b7c6 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkObject.h,v $
   Language:  C++
-  Date:      $Date: 2008/04/24 11:49:59 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.4 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
@@ -24,6 +24,7 @@
 #ifndef __bbtkObject_h__
 #define __bbtkObject_h__
 
+#include <bbtkSystem.h>
 #include <boost/shared_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 #include <set>
@@ -32,7 +33,7 @@ namespace bbtk
 {
 
   // The top class of bbtk class hierarchy 
-  class Object 
+  class BBTK_EXPORT Object 
   {
   public:
     typedef boost::shared_ptr<Object> Pointer;
@@ -58,7 +59,7 @@ namespace bbtk
     static long GetObjectsCount() { return mgObjectList.size(); }
 
     /// Default objects deleter : removes object from list on deletion
-    struct Deleter 
+    struct BBTK_EXPORT Deleter 
     { 
       Deleter() : mPointer() {}
       virtual void operator() (Object* p); 
@@ -159,6 +160,15 @@ protected:                                                     \
     CLASS(const CLASS&);                                                   \
     ~CLASS();                                      
   
+#define BBTK_OBJECT_INTERFACE_NO_CONDES(CLASS)                             \
+  BBTK_OBJECT_MINIMAL_INTERFACE_WITH_SELF(CLASS);                  \
+public:                                                                    \
+  std::string GetObjectName() const;                               \
+    std::string GetObjectInfo() const ;                                    \
+    size_t GetObjectSize() const ;                                 \
+    size_t GetObjectInternalSize() const ;                         \
+    size_t GetObjectRecursiveSize() const ;                        
+
 #define BBTK_ABSTRACT_OBJECT_INTERFACE(CLASS)                          \
   public : typedef CLASS Self;                                         \
     BBTK_OBJECT_MINIMAL_INTERFACE;                                     \
@@ -170,15 +180,16 @@ protected:                                                                \
   //=======================================================================
   // A struct with one static instance 
   // just to print object list info after main
-  struct StaticInitTime
+  class BBTK_EXPORT StaticInitTime
   {
+  public:
     StaticInitTime();
     ~StaticInitTime();
 
 
     static bool PrintObjectListInfo;
   private:
-    static Object mObject;
+         static bbtk::Object mObject;
   };
   
   
index 29368896dafd2c47b6bb3576197a704ce383aab4..31f5a13a8b2bbc5895f80b4f9763744706699aa8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkPackage.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/25 13:37:49 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
@@ -432,7 +432,7 @@ namespace bbtk
     getvername += 
       BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_BBTK_VERSION_FUNCTION_NAME);
     DLGetPackageBBTKVersionFunction getbbtkversion 
-      = (DLGetPackageBBTKVersionFunction)(GetProcAdress(handler,
+      = (DLGetPackageBBTKVersionFunction)(GetProcAddress(handler,
                                                        getvername.c_str()));
     if (!getbbtkversion)
       {
@@ -461,7 +461,7 @@ namespace bbtk
      // Loads the Package get function
     std::string getpackname(package_name);
     getpackname += BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_FUNCTION_NAME);
-    getpack = (DLGetPackageFunction)(GetProcAdress(handler, getpackname.c_str()));
+    getpack = (DLGetPackageFunction)(GetProcAddress(handler, getpackname.c_str()));
     if (!getpack)
       {
        FreeLibrary(handler);
@@ -475,7 +475,7 @@ namespace bbtk
     // Loads the Package delete function
     std::string delpackname(package_name);
     delpackname += BBTK_STRINGIFY_SYMBOL(BBTK_DEL_PACKAGE_FUNCTION_NAME);
-    delpack = (DLDeletePackageFunction)(GetProcAdress(handler, delpackname.c_str()));
+    delpack = (DLDeletePackageFunction)(GetProcAddress(handler, delpackname.c_str()));
     if (!delpack)
       {
        FreeLibrary(handler);
index 968853ff91b111f59a100382974cf1cb42f9eacb..ff96d767462d502ffe7aee9d2e9acc1f3700546a 100644 (file)
@@ -5,6 +5,483 @@ namespace bbtk
 {
 
 
+
+           // ======================================================================
+    // See : http://www.techbytes.ca/techbyte103.html for more O.S.
+    bool Utilities::FileExists(std::string strFilename) 
+    {
+      struct stat stFileInfo;
+     bool blnReturn;
+     int intStat;
+     
+     // Attempt to get the file attributes
+     intStat = stat(strFilename.c_str(),&stFileInfo);
+     if(intStat == 0) 
+       {
+        // We were able to get the file attributes
+        // so the file obviously exists.
+        blnReturn = true;
+       } 
+     else 
+       {
+        // We were not able to get the file attributes.
+        // This may mean that we don't have permission to
+        // access the folder which contains this file. If you
+        // need to do that level of checking, lookup the
+        // return values of stat which will give you
+        // more details on why stat failed.
+        blnReturn = false;
+       }
+     
+     return(blnReturn);
+    }
+    
+    
+    // =====================================================================
+    
+    std::string Utilities::ExtractPackageName(const std::string  &name, 
+                                         std::string& path)
+    {
+      std::string pkgname;
+      path = "";
+      
+      std::string::size_type slash_position = name.find_last_of("/\\");
+      if (slash_position != std::string::npos) 
+       {
+         pkgname = name.substr(slash_position+1,std::string::npos);
+         path = name.substr(0,slash_position);
+         //    std::cout << "F:P='"<<path<<"'"<<std::endl;//+1,std::string::npos);
+       }
+      else 
+       {
+         pkgname = name;
+       }
+      
+      // remove {.so | dll} if any
+      std::string::size_type dot_position = pkgname.find_last_of('.');      
+      if (dot_position != std::string::npos){
+       pkgname = pkgname.substr(0,dot_position);
+      }      
+#if defined(__GNUC__)
+      
+      // GCC mechanism
+      // shared lib name = libbb<name>.so
+      
+      // remove {libbb} if any
+      if (memcmp ( pkgname.c_str(), "libbb", 5) == 0) {
+       pkgname =  pkgname.substr(5, pkgname.length());
+      }
+      /*
+     /// \ \todo     what would happen if (stupid) user names his package 'libbb' ?!?
+      /// \ --> Should be forbidden!
+      */
+#elif defined(_WIN32)
+      
+      // WIN 32 mechanism
+      // shared lib name = <name>.dll
+      
+      // EED Problem loading package call bbtkTools
+      //     // remove {bb} if any
+      if (memcmp (pkgname.c_str(), "bb", 2) == 0) {
+       pkgname =  pkgname.substr(2, pkgname.length());  
+      }
+      
+      /*
+     /// \ \todo     what would happen if (stupid) user names his package 'bb' ?!?
+     /// \ --> Should be forbidden!
+     */
+#else
+      bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
+#endif      
+      return pkgname;
+    }
+    
+    //=====================================================================
+    std::string Utilities::ExtractScriptName(const std::string &name,
+                                        std::string& path)
+    {
+      std::string pkgname;
+      
+      std::string::size_type slash_position = name.find_last_of("/\\");
+      if (slash_position != std::string::npos) {
+       pkgname =name.substr(slash_position+1,std::string::npos);
+       path = name.substr(0,slash_position);      
+      } else {
+       pkgname = name;
+      }
+      // remove {.bbs } if any
+      std::string::size_type dot_position = pkgname.find_last_of('.');
+      if (dot_position != std::string::npos){
+       pkgname = pkgname.substr(0,dot_position);
+      }
+      return pkgname;
+    }
+    
+    // ========================================================================
+
+    std::string Utilities::ExpandLibName(const std::string &name, bool verbose)
+    {
+      // -----   Think of expanding path name ( ./ ../ ../../ )
+      
+      char buf[2048]; // for getcwd
+      char * currentDir = getcwd(buf, 2048);
+      std::string cwd(currentDir);
+      std::string libname(name);
+      std::string fileSeparator;
+      fileSeparator = ConfigurationFile::GetInstance().Get_file_separator();
+      // tooHigh : true is user supplies a library pathname with too many "../"
+      bool tooHigh = false;
+      
+      //std::cout << "------------------cwd ["  << cwd << "] name [" << name << "]" << std::endl;
+      
+      if ( name[0] == '/' ||  name[1] == ':' ) // Linux or Windows absolute name
+       {
+         return(libname);
+       }
+      else if  ( name =="." )
+       {
+         libname = cwd  + fileSeparator;
+         return(libname);
+       }
+      else if  (name[0] == '.' && (name[1] == '/' || name[1] == '\\') )
+       {
+         libname = cwd  + fileSeparator + name.substr(2, name.length());
+         return(libname);
+       }
+      else if ( name[0] == '.' &&  name[1] == '.' /*  && (name[2] == '/' || name[2] == '\\') */ ) 
+       {
+         if ( IsAtRoot(cwd) )  // hope it gets / (for Linux),  C: D: (for Windows)
+      {  
+     // if we are already at / or c: --> hopeless  
+         if (verbose)
+           std::cout << "   File path [" <<  name << "] doesn't exist" << std::endl;
+         tooHigh = true;
+      }
+      else
+      {
+         // iterate on ../ and go up from the current working dir!
+         std::string a(name); 
+         bool alreadyProcessRoot = false;
+
+          //if (a[a.size()-1] != fileSeparator[0])
+          //   a.append(fileSeparator);
+//std::cout << "------------------a ["  << a << "]" << std::endl;
+
+         for(;;)  // wild loop !
+         {
+            std::string::size_type slash_position = cwd.find_last_of(fileSeparator);
+            if (slash_position != std::string::npos) {
+             if (slash_position == 0)
+                slash_position = 1;
+              cwd = cwd.substr(0,slash_position/*+1*/);
+//std::cout << "------------------cwd ["  << cwd << "]" << std::endl;
+            //  if (a == "..") {
+            //    a = "";
+            //    break;
+            //   }
+            //   else
+                 a = a.substr(3, /*name.length()*/ a.length());  // remove ../
+//std::cout << "------------------a ["  << a << "]" << std::endl;  
+              if (a == "" || alreadyProcessRoot)
+              {
+                if (verbose)
+                  std::cout << "   File path : [" <<  name << "] doesn't exist" << std::endl;
+                tooHigh = true;
+                break;
+              }
+             // std::string b = cwd + a;
+              libname =  cwd;
+              char c = cwd[cwd.size()-1];
+              if (c != '/' && c != '\\' )
+                libname += fileSeparator;
+              libname += a;
+
+              if ( a[0] != '.' ) // if . (probabely ../), loop again
+                break;
+
+              if (IsAtRoot(cwd))
+                alreadyProcessRoot = true;
+            }
+         } // end iterating on ../
+      }
+//std::cout << "------------------out of loop]" << std::endl;        
+      if (tooHigh)
+         libname="";
+      return (libname);
+
+    }  // -----   End of expanding path name   ( ./ ../ ../../ )
+
+    std::cout <<"* ERROR in ExpandLibName : should never get here!" << std::endl;
+    // To avoid warning
+    return(""); // Will never get here!
+  }
+
+// ===================================================================================
+
+  std::string Utilities::MakeLibnameFromPath(std::string path, std::string pkgname)
+  {
+    std::string libname = path;
+    char c = path[path.size()-1];    
+#if defined(__GNUC__)
+       if (c != '/')
+          libname += "/libbb";
+       else
+          libname += "libbb";
+       libname += pkgname;
+       libname += ".so";
+         
+#elif defined(_WIN32)
+       if (c != '\\')
+          libname = path+"\\bb";
+       libname += pkgname;
+       libname += ".dll";
+#endif
+    return libname;    
+  }
+
+// ===================================================================================
+
+  std::string Utilities::MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt)
+  {
+    std::string libname = path;
+    char c = path[path.size()-1];
+    if (c != '/' && c != '\\')
+    {
+       libname +=  ConfigurationFile::GetInstance().Get_file_separator ();
+    }
+    libname += pkgname;
+    if (addExt)
+    {
+       int l = libname.size();
+       if (l>4)
+       {
+          if (libname.substr(l-4, 4) != ".bbs")
+          {
+               libname = libname + ".bbs";
+          }
+       }
+    }
+    return libname;
+  }
+
+    //========================================================================
+    
+    bool Utilities::IsAtRoot(std::string cwd)
+    {
+      if ( cwd == "/"              // hope it gets /     (for Linux)
+          || (cwd.size() <= 3 && cwd[1] == ':') ) // hope it gets C: D: (for Windows)
+       return (true);
+      else
+       return(false);
+    }
+    
+    // ======================================================================
+    
+    bool Utilities::IsDirectory(std::string const &dirName)
+    {
+      struct stat fs;
+      
+      if ( stat(dirName.c_str(), &fs) == 0 )
+       {
+#if _WIN32
+         return ((fs.st_mode & _S_IFDIR) != 0);
+#else
+         return S_ISDIR(fs.st_mode);
+#endif
+       }
+      else
+       {
+         return false;
+       }
+    }
+    
+    // ===================================================================================
+    
+    void Utilities::SplitAroundFirstDot( const std::string& in,
+                                            std::string& left,
+                                            std::string& right)
+    {
+      std::string delimiter = ".";
+      std::string::size_type pos = in.find_first_of(delimiter);
+      if (std::string::npos != pos) 
+       {
+         left = in.substr(0,pos);
+         right = in.substr(pos+1,in.size());
+         
+       }
+      else
+       {
+         // bbtkError(in<<" : expected 'a.b' format but no dot found");
+         left ="";
+         right = "";
+       }
+    }
+    //=======================================================================
+    void Utilities::SplitString ( const std::string& str, 
+                                    const std::string& delimiters, 
+                                    std::vector<std::string>& tokens)
+    {
+      // Skip delimiters at beginning.
+      std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+      // Find first delimiter.
+      std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
+      
+      while (std::string::npos != pos || std::string::npos != lastPos)
+       {
+         // Found a token, add it to the vector.
+         tokens.push_back(str.substr(lastPos, pos - lastPos));
+         // Skip delimiters.  Note the "not_of"
+         lastPos = str.find_first_not_of(delimiters, pos);
+         // Find next delimiter
+         pos = str.find_first_of(delimiters, lastPos);
+       }
+      
+    }
+    //=======================================================================
+    
+    
+    // ===================================================================================
+    
+    std::string Utilities::get_file_name(const std::string& s) 
+    { 
+      std::string::size_type slash_position = s.find_last_of("/\\");
+      if (slash_position != std::string::npos) 
+       {
+         return  s.substr(slash_position+1,std::string::npos);   
+       }
+      else 
+       {
+         return s;
+       }
+    }
+    
+    // ===================================================================================
+    /**
+     * \brief   Explore a directory with possibility of recursion
+     *          return number of files read
+     * @param  dirpath   directory to explore
+     * @param  recursive whether we want recursion or not
+     */
+    int Utilities::Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames)
+    {
+      int numberOfFiles = 0;
+      std::string fileName;
+      
+      std::string dirName = dirpath;
+      
+#ifdef _MSC_VER
+      WIN32_FIND_DATA fileData;
+   HANDLE hFile = FindFirstFile((dirName+"\\*").c_str(), &fileData);
+
+   for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b;
+       b = FindNextFile(hFile, &fileData))
+   {
+      fileName = fileData.cFileName;
+      if ( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
+      {
+         // Need to check for . and .. to avoid infinite loop
+         if ( fileName != "." && fileName != ".." && recursive )
+         {
+            numberOfFiles += Explore(dirName+ "\\"+fileName,recursive,Filenames);
+         }
+      }
+      else
+      {
+         Filenames.push_back(dirName+"\\"+fileName);
+         numberOfFiles++;
+      }
+   }
+   DWORD dwError = GetLastError();
+   if (hFile != INVALID_HANDLE_VALUE) 
+      FindClose(hFile);
+   if (dwError != ERROR_NO_MORE_FILES) 
+   {
+      LPVOID lpMsgBuf;
+      FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
+                    FORMAT_MESSAGE_FROM_SYSTEM|
+                    FORMAT_MESSAGE_IGNORE_INSERTS,
+                    NULL,GetLastError(),
+                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+                    (LPTSTR) &lpMsgBuf,0,NULL);
+
+     // ErrorMacro("FindNextFile error. Error is " << (char *)lpMsgBuf
+     //             <<" for the directory : "<<dirName);
+      
+      return 0;
+   }
+
+#else
+  // Real POSIX implementation: scandir is a BSD extension only, and doesn't 
+  // work on debian for example
+//std::cout <<"in Explor dirname[" << dirName << "]" << std::endl; 
+   DIR* dir = opendir(dirName.c_str());
+   if (!dir)
+   {
+      return 0;
+   }
+//std::cout <<"Open OK" << std::endl; 
+   // According to POSIX, the dirent structure contains a field char d_name[]
+   // of unspecified size, with at most NAME_MAX characters preceeding the
+   // terminating null character. Use of other fields will harm the  porta-
+   // bility of your programs.
+
+   struct stat buf;
+   dirent *d;
+   for (d = readdir(dir); d; d = readdir(dir))
+   {
+      fileName = dirName + "/" + d->d_name;
+//std::cout <<"in Explor filename[" << fileName << "]" << std::endl;      
+      if( stat(fileName.c_str(), &buf) != 0 )
+      {
+         //ErrorMacro( strerror(errno) );
+      }
+      if ( S_ISREG(buf.st_mode) )    //is it a regular file?
+      {
+         Filenames.push_back( fileName );
+         numberOfFiles++;
+      }
+      else if ( S_ISDIR(buf.st_mode) ) //directory?
+      {
+         if ( d->d_name[0] != '.' && recursive ) //we also skip hidden files
+         {
+            numberOfFiles += Explore( fileName, recursive, Filenames);
+         }
+      }
+      else
+      {
+         //ErrorMacro( "Unexpected error" );
+         return -1;
+      }
+   }
+   if( closedir(dir) != 0 )
+   {
+     // ErrorMacro( strerror(errno) );
+   }
+#endif
+
+  return numberOfFiles;
+
+}
+
+
+    //=======================================================================
+    // Replaces substrings "\\n" by a real carriage return "\n"
+    void Utilities::SubsBackslashN ( std::string& s )
+    {
+      std::string ss("\\n");
+      std::string::size_type pos = 0;
+      pos = s.find(ss,0);
+      char* cr = "\n";
+      while ( pos != std::string::npos )
+       {
+         s.replace(pos,2,cr,1);
+         pos = s.find(ss, pos-1);
+       }
+    }
+    //=======================================================================
+
+
+
 bool Utilities::loosematch(std::string stdLine,std::string stdOptions) 
 {
        bool result=false;
index 087f2208b09995fce326e5ec706413d72c5c5e49..910f4da4c1180ad72659d5043a8632ce1cfc7efe 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkUtilities.h,v $
   Language:  C++
-  Date:      $Date: 2008/03/26 08:27:19 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
@@ -58,352 +58,50 @@ namespace bbtk
     
     // ======================================================================
     // See : http://www.techbytes.ca/techbyte103.html for more O.S.
-    static inline bool FileExists(std::string strFilename) 
-    {
-      struct stat stFileInfo;
-     bool blnReturn;
-     int intStat;
-     
-     // Attempt to get the file attributes
-     intStat = stat(strFilename.c_str(),&stFileInfo);
-     if(intStat == 0) 
-       {
-        // We were able to get the file attributes
-        // so the file obviously exists.
-        blnReturn = true;
-       } 
-     else 
-       {
-        // We were not able to get the file attributes.
-        // This may mean that we don't have permission to
-        // access the folder which contains this file. If you
-        // need to do that level of checking, lookup the
-        // return values of stat which will give you
-        // more details on why stat failed.
-        blnReturn = false;
-       }
-     
-     return(blnReturn);
-    }
-    
+    static bool FileExists(std::string strFilename);
     
     // =====================================================================
     
     static std::string ExtractPackageName(const std::string  &name, 
-                                         std::string& path)
-    {
-      std::string pkgname;
-      path = "";
-      
-      std::string::size_type slash_position = name.find_last_of("/\\");
-      if (slash_position != std::string::npos) 
-       {
-         pkgname = name.substr(slash_position+1,std::string::npos);
-         path = name.substr(0,slash_position);
-         //    std::cout << "F:P='"<<path<<"'"<<std::endl;//+1,std::string::npos);
-       }
-      else 
-       {
-         pkgname = name;
-       }
-      
-      // remove {.so | dll} if any
-      std::string::size_type dot_position = pkgname.find_last_of('.');      
-      if (dot_position != std::string::npos){
-       pkgname = pkgname.substr(0,dot_position);
-      }      
-#if defined(__GNUC__)
-      
-      // GCC mechanism
-      // shared lib name = libbb<name>.so
-      
-      // remove {libbb} if any
-      if (memcmp ( pkgname.c_str(), "libbb", 5) == 0) {
-       pkgname =  pkgname.substr(5, pkgname.length());
-      }
-      /*
-     /// \ \todo     what would happen if (stupid) user names his package 'libbb' ?!?
-      /// \ --> Should be forbidden!
-      */
-#elif defined(_WIN32)
-      
-      // WIN 32 mechanism
-      // shared lib name = <name>.dll
-      
-      // EED Problem loading package call bbtkTools
-      //     // remove {bb} if any
-      if (memcmp (pkgname.c_str(), "bb", 2) == 0) {
-       pkgname =  pkgname.substr(2, pkgname.length());  
-      }
-      
-      /*
-     /// \ \todo     what would happen if (stupid) user names his package 'bb' ?!?
-     /// \ --> Should be forbidden!
-     */
-#else
-      bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
-#endif      
-      return pkgname;
-    }
-    
+                                         std::string& path);
+
     //=====================================================================
     static std::string ExtractScriptName(const std::string &name,
-                                        std::string& path)
-    {
-      std::string pkgname;
-      
-      std::string::size_type slash_position = name.find_last_of("/\\");
-      if (slash_position != std::string::npos) {
-       pkgname =name.substr(slash_position+1,std::string::npos);
-       path = name.substr(0,slash_position);      
-      } else {
-       pkgname = name;
-      }
-      // remove {.bbs } if any
-      std::string::size_type dot_position = pkgname.find_last_of('.');
-      if (dot_position != std::string::npos){
-       pkgname = pkgname.substr(0,dot_position);
-      }
-      return pkgname;
-    }
-    
+                                        std::string& path);
+  
     // ========================================================================
 
-    static std::string ExpandLibName(const std::string &name, bool verbose)
-    {
-      // -----   Think of expanding path name ( ./ ../ ../../ )
-      
-      char buf[2048]; // for getcwd
-      char * currentDir = getcwd(buf, 2048);
-      std::string cwd(currentDir);
-      std::string libname(name);
-      std::string fileSeparator;
-      fileSeparator = ConfigurationFile::GetInstance().Get_file_separator();
-      // tooHigh : true is user supplies a library pathname with too many "../"
-      bool tooHigh = false;
-      
-      //std::cout << "------------------cwd ["  << cwd << "] name [" << name << "]" << std::endl;
-      
-      if ( name[0] == '/' ||  name[1] == ':' ) // Linux or Windows absolute name
-       {
-         return(libname);
-       }
-      else if  ( name =="." )
-       {
-         libname = cwd  + fileSeparator;
-         return(libname);
-       }
-      else if  (name[0] == '.' && (name[1] == '/' || name[1] == '\\') )
-       {
-         libname = cwd  + fileSeparator + name.substr(2, name.length());
-         return(libname);
-       }
-      else if ( name[0] == '.' &&  name[1] == '.' /*  && (name[2] == '/' || name[2] == '\\') */ ) 
-       {
-         if ( IsAtRoot(cwd) )  // hope it gets / (for Linux),  C: D: (for Windows)
-      {  
-     // if we are already at / or c: --> hopeless  
-         if (verbose)
-           std::cout << "   File path [" <<  name << "] doesn't exist" << std::endl;
-         tooHigh = true;
-      }
-      else
-      {
-         // iterate on ../ and go up from the current working dir!
-         std::string a(name); 
-         bool alreadyProcessRoot = false;
-
-          //if (a[a.size()-1] != fileSeparator[0])
-          //   a.append(fileSeparator);
-//std::cout << "------------------a ["  << a << "]" << std::endl;
-
-         for(;;)  // wild loop !
-         {
-            std::string::size_type slash_position = cwd.find_last_of(fileSeparator);
-            if (slash_position != std::string::npos) {
-             if (slash_position == 0)
-                slash_position = 1;
-              cwd = cwd.substr(0,slash_position/*+1*/);
-//std::cout << "------------------cwd ["  << cwd << "]" << std::endl;
-            //  if (a == "..") {
-            //    a = "";
-            //    break;
-            //   }
-            //   else
-                 a = a.substr(3, /*name.length()*/ a.length());  // remove ../
-//std::cout << "------------------a ["  << a << "]" << std::endl;  
-              if (a == "" || alreadyProcessRoot)
-              {
-                if (verbose)
-                  std::cout << "   File path : [" <<  name << "] doesn't exist" << std::endl;
-                tooHigh = true;
-                break;
-              }
-             // std::string b = cwd + a;
-              libname =  cwd;
-              char c = cwd[cwd.size()-1];
-              if (c != '/' && c != '\\' )
-                libname += fileSeparator;
-              libname += a;
-
-              if ( a[0] != '.' ) // if . (probabely ../), loop again
-                break;
-
-              if (IsAtRoot(cwd))
-                alreadyProcessRoot = true;
-            }
-         } // end iterating on ../
-      }
-//std::cout << "------------------out of loop]" << std::endl;        
-      if (tooHigh)
-         libname="";
-      return (libname);
-
-    }  // -----   End of expanding path name   ( ./ ../ ../../ )
-
-    std::cout <<"* ERROR in ExpandLibName : should never get here!" << std::endl;
-    // To avoid warning
-    return(""); // Will never get here!
-  }
-
+    static std::string ExpandLibName(const std::string &name, bool verbose);
+   
 // ===================================================================================
 
-  static std::string MakeLibnameFromPath(std::string path, std::string pkgname)
-  {
-    std::string libname = path;
-    char c = path[path.size()-1];    
-#if defined(__GNUC__)
-       if (c != '/')
-          libname += "/libbb";
-       else
-          libname += "libbb";
-       libname += pkgname;
-       libname += ".so";
-         
-#elif defined(_WIN32)
-       if (c != '\\')
-          libname = path+"\\bb";
-       libname += pkgname;
-       libname += ".dll";
-#endif
-    return libname;    
-  }
-
+  static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
 // ===================================================================================
 
-  static inline std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt)
-  {
-    std::string libname = path;
-    char c = path[path.size()-1];
-    if (c != '/' && c != '\\')
-    {
-       libname +=  ConfigurationFile::GetInstance().Get_file_separator ();
-    }
-    libname += pkgname;
-    if (addExt)
-    {
-       int l = libname.size();
-       if (l>4)
-       {
-          if (libname.substr(l-4, 4) != ".bbs")
-          {
-               libname = libname + ".bbs";
-          }
-       }
-    }
-    return libname;
-  }
-
+  static std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt);
     //========================================================================
     
-    static inline  bool IsAtRoot(std::string cwd)
-    {
-      if ( cwd == "/"              // hope it gets /     (for Linux)
-          || (cwd.size() <= 3 && cwd[1] == ':') ) // hope it gets C: D: (for Windows)
-       return (true);
-      else
-       return(false);
-    }
-    
+    static bool IsAtRoot(std::string cwd);
     // ======================================================================
     
-    static bool IsDirectory(std::string const &dirName)
-    {
-      struct stat fs;
-      
-      if ( stat(dirName.c_str(), &fs) == 0 )
-       {
-#if _WIN32
-         return ((fs.st_mode & _S_IFDIR) != 0);
-#else
-         return S_ISDIR(fs.st_mode);
-#endif
-       }
-      else
-       {
-         return false;
-       }
-    }
-    
+    static bool IsDirectory(std::string const &dirName);
     // ===================================================================================
     
-    static inline void SplitAroundFirstDot( const std::string& in,
+    static void SplitAroundFirstDot( const std::string& in,
                                             std::string& left,
-                                            std::string& right)
-    {
-      std::string delimiter = ".";
-      std::string::size_type pos = in.find_first_of(delimiter);
-      if (std::string::npos != pos) 
-       {
-         left = in.substr(0,pos);
-         right = in.substr(pos+1,in.size());
-         
-       }
-      else
-       {
-         // bbtkError(in<<" : expected 'a.b' format but no dot found");
-         left ="";
-         right = "";
-       }
-    }
+                                            std::string& right);
     //=======================================================================
-    static inline void SplitString ( const std::string& str, 
+    static void SplitString ( const std::string& str, 
                                     const std::string& delimiters, 
-                                    std::vector<std::string>& tokens)
-    {
-      // Skip delimiters at beginning.
-      std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
-      // Find first delimiter.
-      std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
-      
-      while (std::string::npos != pos || std::string::npos != lastPos)
-       {
-         // Found a token, add it to the vector.
-         tokens.push_back(str.substr(lastPos, pos - lastPos));
-         // Skip delimiters.  Note the "not_of"
-         lastPos = str.find_first_not_of(delimiters, pos);
-         // Find next delimiter
-         pos = str.find_first_of(delimiters, lastPos);
-       }
-      
-    }
+                                    std::vector<std::string>& tokens);
     //=======================================================================
     
     
     // ===================================================================================
     
-    static inline std::string get_file_name(const std::string& s) 
-    { 
-      std::string::size_type slash_position = s.find_last_of("/\\");
-      if (slash_position != std::string::npos) 
-       {
-         return  s.substr(slash_position+1,std::string::npos);   
-       }
-      else 
-       {
-         return s;
-       }
-    }
+    static std::string get_file_name(const std::string& s) ;
+   
     
     // ===================================================================================
     /**
@@ -412,122 +110,12 @@ namespace bbtk
      * @param  dirpath   directory to explore
      * @param  recursive whether we want recursion or not
      */
-    static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames)
-    {
-      int numberOfFiles = 0;
-      std::string fileName;
-      
-      std::string dirName = dirpath;
-      
-#ifdef _MSC_VER
-      WIN32_FIND_DATA fileData;
-   HANDLE hFile = FindFirstFile((dirName+"*").c_str(), &fileData);
-
-   for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b;
-       b = FindNextFile(hFile, &fileData))
-   {
-      fileName = fileData.cFileName;
-      if ( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
-      {
-         // Need to check for . and .. to avoid infinite loop
-         if ( fileName != "." && fileName != ".." && recursive )
-         {
-            numberOfFiles += Explore(dirName+ "\\"+fileName,recursive,Filenames);
-         }
-      }
-      else
-      {
-         Filenames.push_back(dirName+fileName);
-         numberOfFiles++;
-      }
-   }
-   DWORD dwError = GetLastError();
-   if (hFile != INVALID_HANDLE_VALUE) 
-      FindClose(hFile);
-   if (dwError != ERROR_NO_MORE_FILES) 
-   {
-      LPVOID lpMsgBuf;
-      FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
-                    FORMAT_MESSAGE_FROM_SYSTEM|
-                    FORMAT_MESSAGE_IGNORE_INSERTS,
-                    NULL,GetLastError(),
-                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
-                    (LPTSTR) &lpMsgBuf,0,NULL);
-
-     // ErrorMacro("FindNextFile error. Error is " << (char *)lpMsgBuf
-     //             <<" for the directory : "<<dirName);
-      
-      return 0;
-   }
-
-#else
-  // Real POSIX implementation: scandir is a BSD extension only, and doesn't 
-  // work on debian for example
-//std::cout <<"in Explor dirname[" << dirName << "]" << std::endl; 
-   DIR* dir = opendir(dirName.c_str());
-   if (!dir)
-   {
-      return 0;
-   }
-//std::cout <<"Open OK" << std::endl; 
-   // According to POSIX, the dirent structure contains a field char d_name[]
-   // of unspecified size, with at most NAME_MAX characters preceeding the
-   // terminating null character. Use of other fields will harm the  porta-
-   // bility of your programs.
-
-   struct stat buf;
-   dirent *d;
-   for (d = readdir(dir); d; d = readdir(dir))
-   {
-      fileName = dirName + "/" + d->d_name;
-//std::cout <<"in Explor filename[" << fileName << "]" << std::endl;      
-      if( stat(fileName.c_str(), &buf) != 0 )
-      {
-         //ErrorMacro( strerror(errno) );
-      }
-      if ( S_ISREG(buf.st_mode) )    //is it a regular file?
-      {
-         Filenames.push_back( fileName );
-         numberOfFiles++;
-      }
-      else if ( S_ISDIR(buf.st_mode) ) //directory?
-      {
-         if ( d->d_name[0] != '.' && recursive ) //we also skip hidden files
-         {
-            numberOfFiles += Explore( fileName, recursive, Filenames);
-         }
-      }
-      else
-      {
-         //ErrorMacro( "Unexpected error" );
-         return -1;
-      }
-   }
-   if( closedir(dir) != 0 )
-   {
-     // ErrorMacro( strerror(errno) );
-   }
-#endif
-
-  return numberOfFiles;
-
-}
+    static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
 
 
     //=======================================================================
     // Replaces substrings "\\n" by a real carriage return "\n"
-    static inline void SubsBackslashN ( std::string& s )
-    {
-      std::string ss("\\n");
-      std::string::size_type pos = 0;
-      pos = s.find(ss,0);
-      char* cr = "\n";
-      while ( pos != std::string::npos )
-       {
-         s.replace(pos,2,cr,1);
-         pos = s.find(ss, pos-1);
-       }
-    }
+    static void SubsBackslashN ( std::string& s );
     //=======================================================================
 
 
index 52ceb2c1eb324de6f03115aa74a38e9594f18075..2b57eb0323366ad9365740bd827dc63fb7f16144 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkVirtualExec.h,v $ $
   Language:  C++
-  Date:      $Date: 2008/04/24 12:56:39 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -37,7 +37,7 @@ namespace bbtk
   class Interpreter;
   BBTK_FORWARD_DECLARE_POINTER(Interpreter);
 
-  class /*BBTK_EXPORT*/ VirtualExec : public Object
+  class BBTK_EXPORT VirtualExec : public Object
   {
     BBTK_ABSTRACT_OBJECT_INTERFACE(VirtualExec);
   public:
index a66ecc617eb28f3c0c1c00c4c115505f2fd830fb..38474a005630edb70ad6fc86ace7c5434bbcadee 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/24 10:11:28 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -491,13 +491,16 @@ namespace bbtk
     // call 'standard' BlackBox execution method
     if (!bbGetUpdateTransferedToParent()) 
       { 
-       AtomicBlackBox::bbBackwardUpdate(caller);
+         AtomicBlackBox::bbBackwardUpdate(caller);
       }
     
     bbtkDebugMessageDec("process",3,
                        "<= WxBlackBox::bbBackwardUpdate() ["
                        <<bbGetFullName()<<"]"<<std::endl);
     
+   return bbGetStatus();
+     
+
   }
 
   //=========================================================================
index f1b347ee8fa172a17cd485398dd370a1f5b4f29a..53cbb2fdc4d40f0a7d0c7b88971600c71aae6309 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUIConsole.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/24 12:56:39 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2008/05/06 13:45:12 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -413,7 +413,7 @@ namespace bbtk
   bool WxGUIConsole::Show(bool show)
   {
     Wx::AutoDestroyTopWindow(!show);
-    wxFrame::Show(show);
+    return wxFrame::Show(show);
   }
   //================================================================