1 /*=========================================================================
3 Module: $RCSfile: bbtkUtilities.h,v $
5 Date: $Date: 2008/10/22 09:16:16 $
6 Version: $Revision: 1.18 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
35 * \brief struct bbtk::Utilities : various usefull methods
39 * \class bbtk::Utilities
40 * \brief various usefull methods
43 #ifndef __bbtkUtilities_h_INCLUDED__
44 #define __bbtkUtilities_h_INCLUDED__
46 #include "bbtkConfigurationFile.h"
47 #include "bbtkSystem.h"
50 #ifdef CMAKE_HAVE_TERMIOS_H
52 #define BBTK_USE_TERMIOS_BASED_PROMPT
60 #include <sys/types.h>
63 #include <cctype> // std::toupper
64 //#include "bbtkMessageManager.h"
66 #if defined(__GNUC__) // gcc 4.3
72 /// Holds various usefull methods
73 struct BBTK_EXPORT Utilities
76 // ======================================================================
77 // See : http://www.techbytes.ca/techbyte103.html for more O.S.
78 static bool FileExists(std::string strFilename);
80 // =====================================================================
82 static std::string ExtractPackageName(const std::string &name,
85 //=====================================================================
86 static std::string ExtractScriptName(const std::string &name,
89 // ========================================================================
91 static std::string ExpandLibName(const std::string &name, bool verbose);
93 // ===================================================================================
95 static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
97 // ===================================================================================
99 static std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt);
100 //========================================================================
102 // =======================================================================
103 /// Builds the complete path to the file 'name' located
104 /// in user settings dir, e.g. /home/username/.bbtk/
105 static std::string MakeUserSettingsFullFileName(const std::string& name);
108 static bool IsAtRoot(std::string cwd);
109 // ======================================================================
111 static bool IsDirectory(std::string const &dirName);
112 // ===================================================================================
114 static void SplitAroundFirstDot( const std::string& in,
117 //=======================================================================
118 static void SplitString ( const std::string& str,
119 const std::string& delimiters,
120 std::vector<std::string>& tokens);
121 //=======================================================================
124 // ===================================================================================
126 static std::string get_file_name(const std::string& s) ;
129 // ===================================================================================
131 * \brief Explore a directory with possibility of recursion
132 * return number of files read
133 * @param dirpath directory to explore
134 * @param recursive whether we want recursion or not
136 static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
139 //=======================================================================
140 // Replaces substrings "\\n" by a real carriage return "\n"
141 static void SubsBackslashN ( std::string& s );
142 //=======================================================================
145 //========================================================================
146 // Usefull functions for html generation
147 //========================================================================
149 static inline void replace( std::string& str,
150 const std::string& what,
151 const std::string& with )
153 std::string::size_type pos = str.find( what );
154 while ( pos != std::string::npos )
156 str.replace( pos, what.size(), with );
157 pos = str.find( what, pos+what.size()-1 );
160 //========================================================================
162 static inline void html_format(std::string& str)
164 replace( str, "&", "&" );
165 replace( str, "<", "<" );
166 replace( str, ">", ">" );
170 //========================================================================
171 // Usefull functions OPTIONS string
172 //========================================================================
175 static bool loosematch(std::string stdLine,std::string stdOptions);
185 #endif //#ifndef __bbtkUtilities_h_INCLUDED__