]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkUtilities.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkUtilities.h
index b83193fd91e4aee1d9ec002fea8d31317cb5f13e..943df011a38371b5562f3a0c2d9198d1f184a753 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkUtilities.h,v $
   Language:  C++
-  Date:      $Date: 2008/01/22 15:02:00 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2008/09/10 07:25:23 $
+  Version:   $Revision: 1.16 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
  * \class bbtk::Utilities
  * \brief various usefull methods 
  */
+
 #ifndef __bbtkUtilities_h_INCLUDED__
 #define __bbtkUtilities_h_INCLUDED__
 
+#include "bbtkConfigurationFile.h"
 #include "bbtkSystem.h"
 #include <string>
+#include <sys/stat.h>
+#ifdef CMAKE_HAVE_TERMIOS_H
+#include <termios.h>
+#define BBTK_USE_TERMIOS_BASED_PROMPT
+#endif
+
+#ifdef _MSC_VER
+   #include <windows.h> 
+   #include <direct.h>
+#else
+   #include <dirent.h>   
+   #include <sys/types.h>
+#endif
+
+#include <cctype>    // std::toupper
+//#include "bbtkMessageManager.h"
 
 namespace bbtk
 {
   /// Holds various usefull methods 
   struct BBTK_EXPORT Utilities
-  {    
-    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;
-      }      
-    }
+  {
+    
+    // ======================================================================
+    // See : http://www.techbytes.ca/techbyte103.html for more O.S.
+    static bool FileExists(std::string strFilename);
+    
+    // =====================================================================
+    
+    static std::string ExtractPackageName(const std::string  &name, 
+                                         std::string& path);
 
+    //=====================================================================
+    static std::string ExtractScriptName(const std::string &name,
+                                        std::string& path);
+  
+    // ========================================================================
 
-  //========================================================================
-    // Usefull functions for html generation
+    static std::string ExpandLibName(const std::string &name, bool verbose);
    
+// ===================================================================================
+
+  static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
+// ===================================================================================
+
+  static std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt);
     //========================================================================
+    
+    // =======================================================================
+    /// Builds the complete path to the file 'name' located 
+  /// in user settings dir, e.g. /home/username/.bbtk/
+    static std::string MakeUserSettingsFullFileName(const std::string& name);
+
+
+    static bool IsAtRoot(std::string cwd);
+    // ======================================================================
+    
+    static bool IsDirectory(std::string const &dirName);
+    // ===================================================================================
+    
+    static void SplitAroundFirstDot( const std::string& in,
+                                            std::string& left,
+                                            std::string& right);
+    //=======================================================================
+    static void SplitString ( const std::string& str, 
+                                    const std::string& delimiters, 
+                                    std::vector<std::string>& tokens);
+    //=======================================================================
+    
+    
+    // ===================================================================================
+    
+    static std::string get_file_name(const std::string& 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
+     */
+    static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
+
+
+    //=======================================================================
+    // Replaces substrings "\\n" by a real carriage return "\n"
+    static void SubsBackslashN ( std::string& s );
+    //=======================================================================
+
+
+  //========================================================================
+  // Usefull functions for html generation
+  //========================================================================
+
     static inline void replace( std::string& str,
-                                const std::string& from
-                                const std::string& to )
+                                const std::string& what
+                                const std::string& with )
     {
-      using std::string;
-      string::size_type pos = str.find( from );
-      while ( pos != string::npos )
+      std::string::size_type pos = str.find( what );
+         while ( pos != std::string::npos )
       {
-        str.replace( pos, from.size(), to );
-        pos = str.find( from, pos+from.size()-1 );
+        str.replace( pos, what.size(), with );
+        pos = str.find( what, pos+what.size()-1 );
       } 
     }
     //========================================================================
 
-    //========================================================================
     static inline void html_format(std::string& str)
     {
       replace( str, "&", "&amp;" );
       replace( str, "<", "&lt;" );
       replace( str, ">", "&gt;" );
     }
+    
+    
+    //========================================================================
+    // Usefull functions OPTIONS string
     //========================================================================
 
+    
+    static bool loosematch(std::string stdLine,std::string stdOptions);
+    
+   
+    
+    
   };
 
+  
 } // namespace bbtk
  
 #endif //#ifndef __bbtkUtilities_h_INCLUDED__