bbtkUtilities.h

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkUtilities.h,v $
00004   Language:  C++
00005   Date:      $Date: 2009/01/27 14:22:57 $
00006   Version:   $Revision: 1.19 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00032 
00043 #ifndef __bbtkUtilities_h_INCLUDED__
00044 #define __bbtkUtilities_h_INCLUDED__
00045 
00046 #include "bbtkConfigurationFile.h"
00047 #include "bbtkSystem.h"
00048 #include <string>
00049 #include <sys/stat.h>
00050 #ifdef CMAKE_HAVE_TERMIOS_H
00051 #include <termios.h>
00052 #define BBTK_USE_TERMIOS_BASED_PROMPT
00053 #endif
00054 
00055 #ifdef _MSC_VER
00056    #include <windows.h> 
00057    #include <direct.h>
00058 #else
00059    #include <dirent.h>   
00060    #include <sys/types.h>
00061 #endif
00062 
00063 #include <cctype>    // std::toupper
00064 //#include "bbtkMessageManager.h"
00065 
00066 #if defined(__GNUC__) // gcc 4.3
00067 #include <stdlib.h>
00068 #endif
00069 
00070 namespace bbtk
00071 {
00073   struct BBTK_EXPORT Utilities
00074   {
00075     //  ======================================================================
00076     static std::string GetExecutablePath();
00077 
00078     // ======================================================================
00079     // See : http://www.techbytes.ca/techbyte103.html for more O.S.
00080     static bool FileExists(std::string strFilename);
00081     
00082     // =====================================================================
00083     static std::string ExtractPackageName(const std::string  &name, 
00084                                           std::string& path);
00085     
00086     //=====================================================================
00087     static std::string ExtractScriptName(const std::string &name,
00088                                          std::string& path);
00089     
00090     // ========================================================================
00091     static std::string ExpandLibName(const std::string &name, bool verbose);
00092     
00093     // =======================================================================
00094     static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
00095     
00096     // =====================================================================
00097     static std::string MakePkgnameFromPath(std::string path, 
00098                                            std::string pkgname, bool addExt);
00099     //========================================================================
00100     
00101     
00102     // =======================================================================
00105     static inline void MakeValidFileName(std::string& name)
00106     {
00107       replace( name, 
00108                INVALID_FILE_SEPARATOR , 
00109                VALID_FILE_SEPARATOR);
00110     }
00111 
00112     // =======================================================================
00114     static std::string GetUserSettingsDir();
00115 
00116     // =======================================================================
00119     static std::string MakeUserSettingsFullFileName(const std::string& name);
00120     
00121     
00122     static bool IsAtRoot(std::string cwd);
00123     // ======================================================================
00124     
00125     static bool IsDirectory(std::string const &dirName);
00126 
00127     static void CreateDirectoryIfNeeded( std::string const &dirName);
00128     // =======================================================================
00129     
00130     static void SplitAroundFirstDot( const std::string& in,
00131                                      std::string& left,
00132                                             std::string& right);
00133     //======================================================================
00134     static void SplitString ( const std::string& str, 
00135                                      const std::string& delimiters, 
00136                                      std::vector<std::string>& tokens);
00137     //====================================================================
00138     
00139     
00140     // ====================================================================
00141     
00142     static std::string get_file_name(const std::string& s) ;
00143     
00144     
00145     // ====================================================================
00152     static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
00153     
00154     
00155     //=======================================================================
00156     // Replaces substrings "\\n" by a real carriage return "\n"
00157     static void SubsBackslashN ( std::string& s );
00158     //=======================================================================
00159 
00160 
00161   //========================================================================
00162   // Usefull functions for html generation
00163   //========================================================================
00164 
00165     static inline void replace( std::string& str,
00166                                 const std::string& what, 
00167                                 const std::string& with )
00168     {
00169       std::string::size_type pos = str.find( what );
00170           while ( pos != std::string::npos )
00171       {
00172         str.replace( pos, what.size(), with );
00173         pos = str.find( what, pos+what.size()-1 );
00174       } 
00175     }
00176     //========================================================================
00177 
00178     static inline void html_format(std::string& str)
00179     {
00180       replace( str, "&", "&amp;" );
00181       replace( str, "<", "&lt;" );
00182       replace( str, ">", "&gt;" );
00183     }
00184     
00185     
00186     //========================================================================
00187     // Usefull functions OPTIONS string
00188     //========================================================================
00189 
00190     
00191     static bool loosematch(std::string stdLine,std::string stdOptions);
00192     
00193    
00194     
00195     
00196   };
00197 
00198   
00199 } // namespace bbtk
00200  
00201 #endif //#ifndef __bbtkUtilities_h_INCLUDED__
00202 //EOF

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1