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 #include "CDMUtilities.h"
44 namespace CDMUtilities
46 template <typename Container>
47 Container& splitter::split
50 const typename Container::value_type& s,
51 const typename Container::value_type& delimiters,
60 if (empties == no_empties)
62 next = s.find_first_not_of(delimiters, next + 1);
63 if (next == Container::value_type::npos)
70 next = s.find_first_of(delimiters, current);
71 result.push_back(s.substr(current, next - current));
73 while (next != Container::value_type::npos);
77 const std::string fixPath(const std::string& path)
79 std::string pathFixed = "";
83 std::vector<std::string> pathSplit;
85 splitter::split(pathSplit, path, CDMUtilities::SLASH, splitter::no_empties);
87 if(0 < pathSplit.size())
88 pathFixed = pathSplit[0];
90 for (int i = 1; i < (int)(pathSplit.size()); i++)
92 pathFixed += CDMUtilities::SLASH + pathSplit[i];
95 // ------ LINUX / MacOS
96 //break path into folders
97 std::vector<std::string> pathSplit;
99 splitter::split(pathSplit, path, CDMUtilities::SLASH, splitter::no_empties);
101 for (int i = 0; i < pathSplit.size(); i++)
103 pathFixed += CDMUtilities::SLASH + pathSplit[i];
110 int openTextEditor(const std::string& file)
112 std::string command = TEXT_EDITOR;
115 command += " \"" + file + "\"";
118 return system(command.c_str());
121 int openFileExplorer(const std::string& file)
123 std::string command = FILE_EXPLORER;
126 command += " \"" + file + "\"";
129 return system(command.c_str());
132 int openFileWithCommand(const std::string& file, const std::string& command)
134 std::string comm = command;
136 comm += " \"" + file + "\"";
139 return system(comm.c_str());
144 std::string comm = "bbEditor &";
145 return system(comm.c_str());
148 int openCreaToolsTools()
151 std::string comm = "creaTools &";
153 std::string comm = "creaTools.sh &";
156 return system(comm.c_str());
159 int openTerminal(const std::string& command)
161 std::string comm = TERMINAL;
163 comm += + " " + command;
165 return system(comm.c_str());
168 bool createEmptyClass(const std::string& name, const std::string& path)
170 std::vector<std::string> words;
171 splitter::split(words,name," \\/\",.'`",splitter::no_empties);
172 std::string fixedName = "";
173 for (int i = 0; i < (int)(words.size()); i++)
175 fixedName += words[i];
178 if(fixedName == "" || path == "")
183 std::string nameupper = fixedName;
184 std::transform(nameupper.begin(), nameupper.end(),nameupper.begin(),::toupper);
186 std::ofstream out((path + SLASH + fixedName + ".h").c_str());
192 out << "/*" << std::endl;
193 out << "# ---------------------------------------------------------------------" << std::endl;
194 out << "#" << std::endl;
195 out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
196 out << "# pour la Sante)" << std::endl;
197 out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
198 out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
199 out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
200 out << "#" << std::endl;
201 out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
202 out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
203 out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
204 out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
205 out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
206 out << "# or in the file LICENSE.txt." << std::endl;
207 out << "#" << std::endl;
208 out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
209 out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
210 out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
211 out << "# economic rights, and the successive licensors have only limited" << std::endl;
212 out << "# liability." << std::endl;
213 out << "#" << std::endl;
214 out << "# The fact that you are presently reading this means that you have had" << std::endl;
215 out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
216 out << "# ------------------------------------------------------------------------" << std::endl;
217 out << "*/" << std::endl;
218 out << "" << std::endl;
219 out << "#ifndef _" << nameupper << "_H_" << std::endl;
220 out << "#define _" << nameupper << "_H_" << std::endl;
221 out << "" << std::endl;
222 out << "//---------------------------------------------" << std::endl;
223 out << "// Class Name: " << fixedName << "" << std::endl;
224 out << "// [classdescription]" << std::endl;
225 out << "//---------------------------------------------" << std::endl;
226 out << "" << std::endl;
227 out << "class " << fixedName << "" << std::endl;
228 out << "{" << std::endl;
229 out << "" << std::endl;
230 out << "//---------------------------------------------" << std::endl;
231 out << "//Methods and attributes exposed to other classes" << std::endl;
232 out << "//---------------------------------------------" << std::endl;
233 out << "public :" << std::endl;
234 out << " " << fixedName << "();" << std::endl;
235 out << " ~" << fixedName << "();" << std::endl;
236 out << "" << std::endl;
237 out << "//--Method template----------------------------" << std::endl;
238 out << "// void FunctionName(int& parameterA);" << std::endl;
239 out << "" << std::endl;
240 out << "" << std::endl;
241 out << "//---------------------------------------------" << std::endl;
242 out << "//Methods and attributes exposed only to classes" << std::endl;
243 out << "//that are derived from this class" << std::endl;
244 out << "//---------------------------------------------" << std::endl;
245 out << "protected:" << std::endl;
246 out << "" << std::endl;
247 out << "//---------------------------------------------" << std::endl;
248 out << "//Methods and attributes only visible by this class" << std::endl;
249 out << "//---------------------------------------------" << std::endl;
250 out << "private:" << std::endl;
251 out << "" << std::endl;
252 out << "};" << std::endl;
253 out << "" << std::endl;
254 out << "//-end of _" << nameupper << "_H_------------------------------------------------------" << std::endl;
255 out << "#endif" << std::endl;
259 out.open((path + CDMUtilities::SLASH + fixedName + ".cpp").c_str());
265 out << "/*" << std::endl;
266 out << "# ---------------------------------------------------------------------" << std::endl;
267 out << "#" << std::endl;
268 out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
269 out << "# pour la Sante)" << std::endl;
270 out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
271 out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
272 out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
273 out << "#" << std::endl;
274 out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
275 out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
276 out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
277 out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
278 out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
279 out << "# or in the file LICENSE.txt." << std::endl;
280 out << "#" << std::endl;
281 out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
282 out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
283 out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
284 out << "# economic rights, and the successive licensors have only limited" << std::endl;
285 out << "# liability." << std::endl;
286 out << "#" << std::endl;
287 out << "# The fact that you are presently reading this means that you have had" << std::endl;
288 out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
289 out << "# ------------------------------------------------------------------------" << std::endl;
290 out << "*/" << std::endl;
291 out << "" << std::endl;
292 out << "#include \"" << fixedName << ".h\"" << std::endl;
293 out << "" << std::endl;
294 out << "" << fixedName << "::" << fixedName << "()" << std::endl;
295 out << "{" << std::endl;
296 out << "}" << std::endl;
297 out << "" << std::endl;
298 out << "" << fixedName << "::~" << fixedName << "()" << std::endl;
299 out << "{" << std::endl;
300 out << "}" << std::endl;
301 out << "" << std::endl;
302 out << "//---------------------------------------------" << std::endl;
303 out << "//Method template" << std::endl;
304 out << "//---------------------------------------------" << std::endl;
305 out << "/*" << std::endl;
306 out << "void " << fixedName << "::FunctionName(int& parameterA)" << std::endl;
307 out << "{" << std::endl;
308 out << " parameterA = 2 * parameterA;" << std::endl;
309 out << " return;" << std::endl;
310 out << "}" << std::endl;
311 out << "*/" << std::endl;
316 std::string stringify(const std::string& line)
319 for (int i = 0; i < (int)(line.size()); i++)
325 res.push_back(line[i]);