/*========================================================================= Program: bbtk Module: $RCSfile: bbtkUtilities.h,v $ Language: C++ Date: $Date: 2008/09/10 07:25:23 $ Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ /** * \file * \brief struct bbtk::Utilities : various usefull methods */ /** * \class bbtk::Utilities * \brief various usefull methods */ #ifndef __bbtkUtilities_h_INCLUDED__ #define __bbtkUtilities_h_INCLUDED__ #include "bbtkConfigurationFile.h" #include "bbtkSystem.h" #include #include #ifdef CMAKE_HAVE_TERMIOS_H #include #define BBTK_USE_TERMIOS_BASED_PROMPT #endif #ifdef _MSC_VER #include #include #else #include #include #endif #include // std::toupper //#include "bbtkMessageManager.h" namespace bbtk { /// Holds various usefull methods struct BBTK_EXPORT Utilities { // ====================================================================== // See : http://www.techbytes.ca/techbyte103.html for more O.S. static bool FileExists(std::string strFilename); // ===================================================================== static std::string ExtractPackageName(const std::string &name, std::string& path); //===================================================================== static std::string ExtractScriptName(const std::string &name, std::string& path); // ======================================================================== static std::string ExpandLibName(const std::string &name, bool verbose); // =================================================================================== static std::string MakeLibnameFromPath(std::string path, std::string pkgname); // =================================================================================== static std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt); //======================================================================== // ======================================================================= /// Builds the complete path to the file 'name' located /// in user settings dir, e.g. /home/username/.bbtk/ static std::string MakeUserSettingsFullFileName(const std::string& name); static bool IsAtRoot(std::string cwd); // ====================================================================== static bool IsDirectory(std::string const &dirName); // =================================================================================== static void SplitAroundFirstDot( const std::string& in, std::string& left, std::string& right); //======================================================================= static void SplitString ( const std::string& str, const std::string& delimiters, std::vector& tokens); //======================================================================= // =================================================================================== static std::string get_file_name(const std::string& s) ; // =================================================================================== /** * \brief Explore a directory with possibility of recursion * return number of files read * @param dirpath directory to explore * @param recursive whether we want recursion or not */ static int Explore(std::string const &dirpath, bool recursive, std::vector &Filenames); //======================================================================= // Replaces substrings "\\n" by a real carriage return "\n" static void SubsBackslashN ( std::string& s ); //======================================================================= //======================================================================== // Usefull functions for html generation //======================================================================== static inline void replace( std::string& str, const std::string& what, const std::string& with ) { std::string::size_type pos = str.find( what ); while ( pos != std::string::npos ) { str.replace( pos, what.size(), with ); pos = str.find( what, pos+what.size()-1 ); } } //======================================================================== static inline void html_format(std::string& str) { replace( str, "&", "&" ); replace( str, "<", "<" ); replace( str, ">", ">" ); } //======================================================================== // Usefull functions OPTIONS string //======================================================================== static bool loosematch(std::string stdLine,std::string stdOptions); }; } // namespace bbtk #endif //#ifndef __bbtkUtilities_h_INCLUDED__ //EOF