1 /*=========================================================================
4 Module: $RCSfile: bbtkUtilities.h,v $
6 Date: $Date: 2008/09/10 07:25:23 $
7 Version: $Revision: 1.16 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See doc/license.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 * \brief struct bbtk::Utilities : various usefull methods
26 * \class bbtk::Utilities
27 * \brief various usefull methods
30 #ifndef __bbtkUtilities_h_INCLUDED__
31 #define __bbtkUtilities_h_INCLUDED__
33 #include "bbtkConfigurationFile.h"
34 #include "bbtkSystem.h"
37 #ifdef CMAKE_HAVE_TERMIOS_H
39 #define BBTK_USE_TERMIOS_BASED_PROMPT
47 #include <sys/types.h>
50 #include <cctype> // std::toupper
51 //#include "bbtkMessageManager.h"
55 /// Holds various usefull methods
56 struct BBTK_EXPORT Utilities
59 // ======================================================================
60 // See : http://www.techbytes.ca/techbyte103.html for more O.S.
61 static bool FileExists(std::string strFilename);
63 // =====================================================================
65 static std::string ExtractPackageName(const std::string &name,
68 //=====================================================================
69 static std::string ExtractScriptName(const std::string &name,
72 // ========================================================================
74 static std::string ExpandLibName(const std::string &name, bool verbose);
76 // ===================================================================================
78 static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
80 // ===================================================================================
82 static std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt);
83 //========================================================================
85 // =======================================================================
86 /// Builds the complete path to the file 'name' located
87 /// in user settings dir, e.g. /home/username/.bbtk/
88 static std::string MakeUserSettingsFullFileName(const std::string& name);
91 static bool IsAtRoot(std::string cwd);
92 // ======================================================================
94 static bool IsDirectory(std::string const &dirName);
95 // ===================================================================================
97 static void SplitAroundFirstDot( const std::string& in,
100 //=======================================================================
101 static void SplitString ( const std::string& str,
102 const std::string& delimiters,
103 std::vector<std::string>& tokens);
104 //=======================================================================
107 // ===================================================================================
109 static std::string get_file_name(const std::string& s) ;
112 // ===================================================================================
114 * \brief Explore a directory with possibility of recursion
115 * return number of files read
116 * @param dirpath directory to explore
117 * @param recursive whether we want recursion or not
119 static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
122 //=======================================================================
123 // Replaces substrings "\\n" by a real carriage return "\n"
124 static void SubsBackslashN ( std::string& s );
125 //=======================================================================
128 //========================================================================
129 // Usefull functions for html generation
130 //========================================================================
132 static inline void replace( std::string& str,
133 const std::string& what,
134 const std::string& with )
136 std::string::size_type pos = str.find( what );
137 while ( pos != std::string::npos )
139 str.replace( pos, what.size(), with );
140 pos = str.find( what, pos+what.size()-1 );
143 //========================================================================
145 static inline void html_format(std::string& str)
147 replace( str, "&", "&" );
148 replace( str, "<", "<" );
149 replace( str, ">", ">" );
153 //========================================================================
154 // Usefull functions OPTIONS string
155 //========================================================================
158 static bool loosematch(std::string stdLine,std::string stdOptions);
168 #endif //#ifndef __bbtkUtilities_h_INCLUDED__