/* # --------------------------------------------------------------------- # # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image # pour la Sant�) # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton # Previous Authors : Laurent Guigues, Jean-Pierre Roux # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil # # This software is governed by the CeCILL-B license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL-B # license as circulated by CEA, CNRS and INRIA at the following URL # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html # or in the file LICENSE.txt. # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ /* * CDMUtilities.h * * Created on: Nov 23, 2012 * Author: Daniel Felipe Gonzalez Obando */ #ifndef CDMUTILITIES_H_ #define CDMUTILITIES_H_ #include #include namespace CDMUtilities { /** * Path slash */ #ifdef _WIN32 // ------ Windows static std::string SLASH = "\\"; #elif __APPLE__ // ------ Apple static std::string SLASH = "/"; #else static std::string SLASH = "/"; #endif /** * Text editor program */ #ifdef _WIN32 // ------ Windows static std::string TEXT_EDITOR = "notepad"; #elif __APPLE__ // ------ Apple //TODO: implementation for apple #else static std::string TEXT_EDITOR = "gedit"; #endif /** * File explorer program */ #ifdef _WIN32 // ------ Windows static std::string FILE_EXPLORER = "explorer"; #elif __APPLE__ // ------ Apple //TODO: implementation for apple #else static std::string FILE_EXPLORER = "nautilus"; #endif /** * Terminal program */ #ifdef _WIN32 // ------ Windows static std::string TERMINAL = "start cmd.exe"; #elif __APPLE__ // ------ Apple //TODO: implementation for apple #else static std::string TERMINAL = "gnome-terminal"; #endif /** * Structure that handles the split method for c++ * It calls the split method to split a string given certain delimiters. */ struct splitter { /** * Enum to allow or not empty resulting strings after performing splits. */ enum empties_t { empties_ok, no_empties }; /** * Method to split a string given a set of delimiter characters. * @param result Resulting container. * @param s String to be splitted. * @param delimiters Delimiter characters to split the string. * @param empties Either allow or not empty resulting strings after performing split. * @return Resulting container. */ template static Container& split ( Container& result, const typename Container::value_type& s, const typename Container::value_type& delimiters, empties_t empties = empties_ok ); }; /** * Fixes a given path to avoid double slash directories * @param path Unfixed path. * @return Fixed path. */ const std::string fixPath(const std::string& path); /** * Opens the default text editor. If a file is given, then it tries to open the given file. * @param file Full path to the file. * @return True if there was an error on the execution of the operation. */ int openTextEditor(const std::string& file = ""); /** * Opens the system file explorer on the given file path * @param file Path of the desired folder to open. * @return True if there was an error on the execution of the operation. */ int openFileExplorer(const std::string& file = ""); /** * Opens a file with a given command. * @param file Full path of the file to open. * @param command Command to execute the file with. * @return True if there was an error on the execution of the operation. */ int openFileWithCommand(const std::string& file, const std::string& command); /** * Opens the BBTK Graphical Editor * @return True if there was an error on the execution of the operation. */ int openBBEditor(); /** * Opens the minitools or the creaTools * @return True if there was an error on the execution of the operation. */ int openCreaToolsTools(); /** * Open a command line interpreter and executes the given command if any. * @param command Command to execute. * @return True if there was an error on the execution of the operation. */ int openTerminal(const std::string& command = ""); /** * Creates a blank class(.h and .cpp files). * @param name Name of the new class. * @param path Path where the class is to be created. * @return True if the class was successfully created. */ bool createEmptyClass(const std::string& name, const std::string& path); /** * Creates a string replacing each \ by \\. * @param line String to stringify. * @return line stringified. */ std::string stringify(const std::string& line); }; #endif /* CDMUTILITIES_H_ */