1 /*=========================================================================
3 Module: $RCSfile: bbtkUtilities.h,v $
5 Date: $Date: 2008/10/17 08:18:14 $
6 Version: $Revision: 1.17 $
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"
68 /// Holds various usefull methods
69 struct BBTK_EXPORT Utilities
72 // ======================================================================
73 // See : http://www.techbytes.ca/techbyte103.html for more O.S.
74 static bool FileExists(std::string strFilename);
76 // =====================================================================
78 static std::string ExtractPackageName(const std::string &name,
81 //=====================================================================
82 static std::string ExtractScriptName(const std::string &name,
85 // ========================================================================
87 static std::string ExpandLibName(const std::string &name, bool verbose);
89 // ===================================================================================
91 static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
93 // ===================================================================================
95 static std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt);
96 //========================================================================
98 // =======================================================================
99 /// Builds the complete path to the file 'name' located
100 /// in user settings dir, e.g. /home/username/.bbtk/
101 static std::string MakeUserSettingsFullFileName(const std::string& name);
104 static bool IsAtRoot(std::string cwd);
105 // ======================================================================
107 static bool IsDirectory(std::string const &dirName);
108 // ===================================================================================
110 static void SplitAroundFirstDot( const std::string& in,
113 //=======================================================================
114 static void SplitString ( const std::string& str,
115 const std::string& delimiters,
116 std::vector<std::string>& tokens);
117 //=======================================================================
120 // ===================================================================================
122 static std::string get_file_name(const std::string& s) ;
125 // ===================================================================================
127 * \brief Explore a directory with possibility of recursion
128 * return number of files read
129 * @param dirpath directory to explore
130 * @param recursive whether we want recursion or not
132 static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
135 //=======================================================================
136 // Replaces substrings "\\n" by a real carriage return "\n"
137 static void SubsBackslashN ( std::string& s );
138 //=======================================================================
141 //========================================================================
142 // Usefull functions for html generation
143 //========================================================================
145 static inline void replace( std::string& str,
146 const std::string& what,
147 const std::string& with )
149 std::string::size_type pos = str.find( what );
150 while ( pos != std::string::npos )
152 str.replace( pos, what.size(), with );
153 pos = str.find( what, pos+what.size()-1 );
156 //========================================================================
158 static inline void html_format(std::string& str)
160 replace( str, "&", "&" );
161 replace( str, "<", "<" );
162 replace( str, ">", ">" );
166 //========================================================================
167 // Usefull functions OPTIONS string
168 //========================================================================
171 static bool loosematch(std::string stdLine,std::string stdOptions);
181 #endif //#ifndef __bbtkUtilities_h_INCLUDED__