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 # ------------------------------------------------------------------------
31 * Created on: Nov 23, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #ifndef CDMUTILITIES_H_
36 #define CDMUTILITIES_H_
42 namespace CDMUtilities
49 static std::string SLASH = "\\";
52 static std::string SLASH = "/";
54 static std::string SLASH = "/";
62 static std::string TEXT_EDITOR = "notepad";
65 //TODO: implementation for apple
67 static std::string TEXT_EDITOR = "gedit";
71 * File explorer program
75 static std::string FILE_EXPLORER = "explorer";
78 //TODO: implementation for apple
80 static std::string FILE_EXPLORER = "nautilus";
88 static std::string TERMINAL = "start cmd.exe";
91 //TODO: implementation for apple
93 static std::string TERMINAL = "gnome-terminal";
100 static std::string BUILD_COMMAND = "make";
104 * Structure that handles the split method for c++
105 * It calls the split method to split a string given certain delimiters.
110 * Enum to allow or not empty resulting strings after performing splits.
112 enum empties_t { empties_ok, no_empties };
114 * Method to split a string given a set of delimiter characters.
115 * @param result Resulting container.
116 * @param s String to be splitted.
117 * @param delimiters Delimiter characters to split the string.
118 * @param empties Either allow or not empty resulting strings after performing split.
119 * @return Resulting container.
121 template <typename Container>
122 static Container& split
125 const typename Container::value_type& s,
126 const typename Container::value_type& delimiters,
127 empties_t empties = empties_ok
135 if (empties == no_empties)
137 next = s.find_first_not_of(delimiters, next + 1);
138 if (next == Container::value_type::npos)
145 next = s.find_first_of(delimiters, current);
146 result.push_back(s.substr(current, next - current));
148 while (next != Container::value_type::npos);
154 * Fixes a given path to avoid double slash directories
155 * @param path Unfixed path.
156 * @return Fixed path.
158 const std::string fixPath(const std::string& path);
161 * Opens the default text editor. If a file is given, then it tries to open the given file.
162 * @param file Full path to the file.
163 * @return True if there was an error on the execution of the operation.
165 int openTextEditor(const std::string& file = "");
167 * Opens the system file explorer on the given file path
168 * @param file Path of the desired folder to open.
169 * @return True if there was an error on the execution of the operation.
171 int openFileExplorer(const std::string& file = "");
173 * Opens a file with a given command.
174 * @param file Full path of the file to open.
175 * @param command Command to execute the file with.
176 * @return True if there was an error on the execution of the operation.
178 int openFileWithCommand(const std::string& file, const std::string& command);
180 * Opens the BBTK Graphical Editor
181 * @return True if there was an error on the execution of the operation.
185 * Opens the minitools or the creaTools
186 * @return True if there was an error on the execution of the operation.
188 int openCreaToolsTools();
190 * Open a command line interpreter and executes the given command if any.
191 * @param command Command to execute.
192 * @return True if there was an error on the execution of the operation.
194 int openTerminal(const std::string& command = "");
196 * Creates a blank class(.h and .cpp files).
197 * @param name Name of the new class.
198 * @param path Path where the class is to be created.
199 * @return True if the class was successfully created.
201 bool createEmptyClass(const std::string& name, const std::string& path);
203 * Creates a string replacing each \ by double \ .
204 * @param line String to stringify.
205 * @return line stringified.
207 std::string stringify(const std::string& line);
209 //CMakeLists file handling
211 * Type definition for the value of a syntax element for CMakeLists files
213 typedef std::vector<std::string> cmdValue;
216 * Type definition for the type of a syntax element for CMakeLists files
218 typedef std::string cmdType;
221 * Type definition for syntax elements of a CMakeLists file
223 typedef std::pair<cmdType,cmdValue> syntaxElement;
226 * Type definition for describing a CMakeLists file content
228 typedef std::vector<syntaxElement> CMLFile;
231 * Reads a file as string and returns the read data.
232 * @param file_path Full path of the CMakeLists file.
233 * @return A string with the contents of the given file.
235 std::string readFile(const std::string& file_path);
237 * Writes the given string into a file and returns whether the operation is successful.
238 * @param file_path Full path of the CMakeLists file.
239 * @param st string to write.
240 * @return True if the operation was successful.
242 bool writeFile(const std::string& file_path, const std::string& st);
245 * Reads a CMakeLists file and returns the read data.
246 * @param file_path Full path of the CMakeLists file.
247 * @return A CMLFile with the contents of the given file.
249 CMLFile readCMLFile(const std::string& file_path);
252 * Writes the given data into specified CMakeLists file.
253 * @param file_path Full path of the CMakeLists file.
254 * @param data CMakeLists data.
255 * @return True if the operation was successful.
257 bool writeCMLFile(const std::string& file_path, const CMLFile& data);
260 * @param st Strips all space character at the beginning and at the end of the string.
262 void normalizeStr(std::string& st);
266 #endif /* CDMUTILITIES_H_ */