2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkUtilities.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.20 $
34 =========================================================================*/
42 * \brief struct bbtk::Utilities : various usefull methods
46 * \class bbtk::Utilities
47 * \brief various usefull methods
50 #ifndef __bbtkUtilities_h_INCLUDED__
51 #define __bbtkUtilities_h_INCLUDED__
53 #include "bbtkConfigurationFile.h"
54 #include "bbtkSystem.h"
57 #ifdef CMAKE_HAVE_TERMIOS_H
59 #define BBTK_USE_TERMIOS_BASED_PROMPT
67 #include <sys/types.h>
70 #include <cctype> // std::toupper
71 //#include "bbtkMessageManager.h"
73 #if defined(__GNUC__) // gcc 4.3
79 /// Holds various usefull methods
80 struct BBTK_EXPORT Utilities
82 // ======================================================================
83 static std::string GetExecutablePath();
85 // ======================================================================
86 // See : http://www.techbytes.ca/techbyte103.html for more O.S.
87 static bool FileExists(std::string strFilename);
89 // =====================================================================
90 static std::string ExtractPackageName(const std::string &name,
93 //=====================================================================
94 static std::string ExtractScriptName(const std::string &name,
97 // ========================================================================
98 static std::string ExpandLibName(const std::string &name, bool verbose);
100 // =======================================================================
101 static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
103 // =====================================================================
104 static std::string MakePkgnameFromPath(std::string path,
105 std::string pkgname, bool addExt);
106 //========================================================================
109 // =======================================================================
110 /// Makes a valid filename with string (replaces invalid file seps
112 static inline void MakeValidFileName(std::string& name)
115 INVALID_FILE_SEPARATOR ,
116 VALID_FILE_SEPARATOR);
119 // =======================================================================
120 /// Returns the user settings dir, e.g. /home/username/.bbtk
121 static std::string GetUserSettingsDir();
123 // =======================================================================
124 /// Builds the complete path to the file 'name' located
125 /// in user settings dir, e.g. /home/username/.bbtk/
126 static std::string MakeUserSettingsFullFileName(const std::string& name);
129 static bool IsAtRoot(std::string cwd);
130 // ======================================================================
132 static bool IsDirectory(std::string const &dirName);
134 static void CreateDirectoryIfNeeded( std::string const &dirName);
135 // =======================================================================
137 static void SplitAroundFirstDot( const std::string& in,
140 //======================================================================
141 static void SplitString ( const std::string& str,
142 const std::string& delimiters,
143 std::vector<std::string>& tokens);
144 //====================================================================
147 // ====================================================================
149 static std::string get_file_name(const std::string& s) ;
152 // ====================================================================
154 * \brief Explore a directory with possibility of recursion
155 * return number of files read
156 * @param dirpath directory to explore
157 * @param recursive whether we want recursion or not
159 static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
162 //=======================================================================
163 // Replaces substrings "\\n" by a real carriage return "\n"
164 static void SubsBackslashN ( std::string& s );
165 //=======================================================================
168 //========================================================================
169 // Usefull functions for html generation
170 //========================================================================
172 static inline void replace( std::string& str,
173 const std::string& what,
174 const std::string& with )
176 std::string::size_type pos = str.find( what );
177 while ( pos != std::string::npos )
179 str.replace( pos, what.size(), with );
180 pos = str.find( what, pos+what.size()-1 );
183 //========================================================================
185 static inline void html_format(std::string& str)
187 replace( str, "&", "&" );
188 replace( str, "<", "<" );
189 replace( str, ">", ">" );
193 //========================================================================
194 // Usefull functions OPTIONS string
195 //========================================================================
198 static bool loosematch(std::string stdLine,std::string stdOptions);
208 std::vector<NodeTreeC> childs;
211 NodeTreeC(std::string _data);
213 void insertChild(std::string _data);
215 void setData(std::string _data);
224 TreeC(std::string _data);
226 void insertRoot(std::string _data);
228 void insertData(std::string _data);
235 #endif //#ifndef __bbtkUtilities_h_INCLUDED__