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: 2008/10/22 09:16:16 $
00006   Version:   $Revision: 1.18 $
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     // ======================================================================
00077     // See : http://www.techbytes.ca/techbyte103.html for more O.S.
00078     static bool FileExists(std::string strFilename);
00079     
00080     // =====================================================================
00081     
00082     static std::string ExtractPackageName(const std::string  &name, 
00083                                           std::string& path);
00084 
00085     //=====================================================================
00086     static std::string ExtractScriptName(const std::string &name,
00087                                          std::string& path);
00088   
00089     // ========================================================================
00090 
00091     static std::string ExpandLibName(const std::string &name, bool verbose);
00092    
00093 // ===================================================================================
00094 
00095   static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
00096  
00097 // ===================================================================================
00098 
00099   static std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt);
00100     //========================================================================
00101     
00102     // =======================================================================
00105     static std::string MakeUserSettingsFullFileName(const std::string& name);
00106 
00107 
00108     static bool IsAtRoot(std::string cwd);
00109     // ======================================================================
00110     
00111     static bool IsDirectory(std::string const &dirName);
00112     // ===================================================================================
00113     
00114     static void SplitAroundFirstDot( const std::string& in,
00115                                             std::string& left,
00116                                             std::string& right);
00117     //=======================================================================
00118     static void SplitString ( const std::string& str, 
00119                                      const std::string& delimiters, 
00120                                      std::vector<std::string>& tokens);
00121     //=======================================================================
00122     
00123     
00124     // ===================================================================================
00125     
00126     static std::string get_file_name(const std::string& s) ;
00127    
00128     
00129     // ===================================================================================
00136     static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
00137 
00138 
00139     //=======================================================================
00140     // Replaces substrings "\\n" by a real carriage return "\n"
00141     static void SubsBackslashN ( std::string& s );
00142     //=======================================================================
00143 
00144 
00145   //========================================================================
00146   // Usefull functions for html generation
00147   //========================================================================
00148 
00149     static inline void replace( std::string& str,
00150                                 const std::string& what, 
00151                                 const std::string& with )
00152     {
00153       std::string::size_type pos = str.find( what );
00154           while ( pos != std::string::npos )
00155       {
00156         str.replace( pos, what.size(), with );
00157         pos = str.find( what, pos+what.size()-1 );
00158       } 
00159     }
00160     //========================================================================
00161 
00162     static inline void html_format(std::string& str)
00163     {
00164       replace( str, "&", "&amp;" );
00165       replace( str, "<", "&lt;" );
00166       replace( str, ">", "&gt;" );
00167     }
00168     
00169     
00170     //========================================================================
00171     // Usefull functions OPTIONS string
00172     //========================================================================
00173 
00174     
00175     static bool loosematch(std::string stdLine,std::string stdOptions);
00176     
00177    
00178     
00179     
00180   };
00181 
00182   
00183 } // namespace bbtk
00184  
00185 #endif //#ifndef __bbtkUtilities_h_INCLUDED__
00186 //EOF

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6