bbtkUtilities.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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>
00064
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 static std::string GetExecutablePath();
00077
00078
00079
00080 static bool FileExists(std::string strFilename);
00081
00082
00083 static std::string ExtractPackageName(const std::string &name,
00084 std::string& path);
00085
00086
00087 static std::string ExtractScriptName(const std::string &name,
00088 std::string& path);
00089
00090
00091 static std::string ExpandLibName(const std::string &name, bool verbose);
00092
00093
00094 static std::string MakeLibnameFromPath(std::string path, std::string pkgname);
00095
00096
00097 static std::string MakePkgnameFromPath(std::string path,
00098 std::string pkgname, bool addExt);
00099
00100
00101
00102
00105 static inline void MakeValidFileName(std::string& name)
00106 {
00107 replace( name,
00108 INVALID_FILE_SEPARATOR ,
00109 VALID_FILE_SEPARATOR);
00110 }
00111
00112
00114 static std::string GetUserSettingsDir();
00115
00116
00119 static std::string MakeUserSettingsFullFileName(const std::string& name);
00120
00121
00122 static bool IsAtRoot(std::string cwd);
00123
00124
00125 static bool IsDirectory(std::string const &dirName);
00126
00127 static void CreateDirectoryIfNeeded( std::string const &dirName);
00128
00129
00130 static void SplitAroundFirstDot( const std::string& in,
00131 std::string& left,
00132 std::string& right);
00133
00134 static void SplitString ( const std::string& str,
00135 const std::string& delimiters,
00136 std::vector<std::string>& tokens);
00137
00138
00139
00140
00141
00142 static std::string get_file_name(const std::string& s) ;
00143
00144
00145
00152 static int Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames);
00153
00154
00155
00156
00157 static void SubsBackslashN ( std::string& s );
00158
00159
00160
00161
00162
00163
00164
00165 static inline void replace( std::string& str,
00166 const std::string& what,
00167 const std::string& with )
00168 {
00169 std::string::size_type pos = str.find( what );
00170 while ( pos != std::string::npos )
00171 {
00172 str.replace( pos, what.size(), with );
00173 pos = str.find( what, pos+what.size()-1 );
00174 }
00175 }
00176
00177
00178 static inline void html_format(std::string& str)
00179 {
00180 replace( str, "&", "&" );
00181 replace( str, "<", "<" );
00182 replace( str, ">", ">" );
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 static bool loosematch(std::string stdLine,std::string stdOptions);
00192
00193
00194
00195
00196 };
00197
00198
00199 }
00200
00201 #endif //#ifndef __bbtkUtilities_h_INCLUDED__
00202