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 //TODO: implementation for windows
85 // ------ LINUX / MacOS
86 //break path into folders
87 std::vector<std::string> pathSlpit;
89 splitter::split(pathSlpit, path, CDMUtilities::SLASH, splitter::no_empties);
91 for (int i = 0; i < pathSlpit.size(); i++)
93 pathFixed += CDMUtilities::SLASH + pathSlpit[i];
100 int openTextEditor(const std::string& file)
102 std::string command = TEXT_EDITOR;
105 command += " \"" + file + "\" &";
107 return system(command.c_str());
110 int openFileExplorer(const std::string& file)
112 std::string command = FILE_EXPLORER;
115 command += " \"" + file + "\" &";
117 return system(command.c_str());
120 int openFileWithCommand(const std::string& file, const std::string& command)
122 std::string comm = command;
124 comm += " \"" + file + "\" &";
126 return system(comm.c_str());
131 std::string comm = "bbEditor &";
132 return system(comm.c_str());
135 int openCreaToolsTools()
137 std::string comm = "creaTools.sh &";
138 return system(comm.c_str());
141 int openTerminal(const std::string& command)
143 std::string comm = TERMINAL;
145 comm += + " " + command;
147 return system(comm.c_str());
150 bool createEmptyClass(const std::string& name, const std::string& path)
152 std::vector<std::string> words;
153 splitter::split(words,name," \\/\",.'`",splitter::no_empties);
154 std::string fixedName = "";
155 for (int i = 0; i < words.size(); i++)
157 fixedName += words[i];
160 if(fixedName == "" || path == "")
165 std::string nameupper = fixedName;
166 std::transform(nameupper.begin(), nameupper.end(),nameupper.begin(),::toupper);
168 std::ofstream out((path + SLASH + fixedName + ".h").c_str());
174 out << "/*" << std::endl;
175 out << "# ---------------------------------------------------------------------" << std::endl;
176 out << "#" << std::endl;
177 out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
178 out << "# pour la Sante)" << std::endl;
179 out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
180 out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
181 out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
182 out << "#" << std::endl;
183 out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
184 out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
185 out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
186 out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
187 out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
188 out << "# or in the file LICENSE.txt." << std::endl;
189 out << "#" << std::endl;
190 out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
191 out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
192 out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
193 out << "# economic rights, and the successive licensors have only limited" << std::endl;
194 out << "# liability." << std::endl;
195 out << "#" << std::endl;
196 out << "# The fact that you are presently reading this means that you have had" << std::endl;
197 out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
198 out << "# ------------------------------------------------------------------------" << std::endl;
199 out << "*/" << std::endl;
200 out << "" << std::endl;
201 out << "#ifndef _" << nameupper << "_H_" << std::endl;
202 out << "#define _" << nameupper << "_H_" << std::endl;
203 out << "" << std::endl;
204 out << "//---------------------------------------------" << std::endl;
205 out << "// Class Name: " << fixedName << "" << std::endl;
206 out << "// [classdescription]" << std::endl;
207 out << "//---------------------------------------------" << std::endl;
208 out << "" << std::endl;
209 out << "class " << fixedName << "" << std::endl;
210 out << "{" << std::endl;
211 out << "" << std::endl;
212 out << "//---------------------------------------------" << std::endl;
213 out << "//Methods and attributes exposed to other classes" << std::endl;
214 out << "//---------------------------------------------" << std::endl;
215 out << "public :" << std::endl;
216 out << " " << fixedName << "();" << std::endl;
217 out << " ~" << fixedName << "();" << std::endl;
218 out << "" << std::endl;
219 out << "//--Method template----------------------------" << std::endl;
220 out << "// void FunctionName(int& parameterA);" << std::endl;
221 out << "" << std::endl;
222 out << "" << std::endl;
223 out << "//---------------------------------------------" << std::endl;
224 out << "//Methods and attributes exposed only to classes" << std::endl;
225 out << "//that are derived from this class" << std::endl;
226 out << "//---------------------------------------------" << std::endl;
227 out << "protected:" << std::endl;
228 out << "" << std::endl;
229 out << "//---------------------------------------------" << std::endl;
230 out << "//Methods and attributes only visible by this class" << std::endl;
231 out << "//---------------------------------------------" << std::endl;
232 out << "private:" << std::endl;
233 out << "" << std::endl;
234 out << "};" << std::endl;
235 out << "" << std::endl;
236 out << "//-end of _" << nameupper << "_H_------------------------------------------------------" << std::endl;
237 out << "#endif" << std::endl;
241 out.open((path + CDMUtilities::SLASH + fixedName + ".cpp").c_str());
247 out << "/*" << std::endl;
248 out << "# ---------------------------------------------------------------------" << std::endl;
249 out << "#" << std::endl;
250 out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
251 out << "# pour la Sante)" << std::endl;
252 out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
253 out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
254 out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
255 out << "#" << std::endl;
256 out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
257 out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
258 out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
259 out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
260 out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
261 out << "# or in the file LICENSE.txt." << std::endl;
262 out << "#" << std::endl;
263 out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
264 out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
265 out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
266 out << "# economic rights, and the successive licensors have only limited" << std::endl;
267 out << "# liability." << std::endl;
268 out << "#" << std::endl;
269 out << "# The fact that you are presently reading this means that you have had" << std::endl;
270 out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
271 out << "# ------------------------------------------------------------------------" << std::endl;
272 out << "*/" << std::endl;
273 out << "" << std::endl;
274 out << "#include \"" << fixedName << ".h\"" << std::endl;
275 out << "" << std::endl;
276 out << "" << fixedName << "::" << fixedName << "()" << std::endl;
277 out << "{" << std::endl;
278 out << "}" << std::endl;
279 out << "" << std::endl;
280 out << "" << fixedName << "::~" << fixedName << "()" << std::endl;
281 out << "{" << std::endl;
282 out << "}" << std::endl;
283 out << "" << std::endl;
284 out << "//---------------------------------------------" << std::endl;
285 out << "//Method template" << std::endl;
286 out << "//---------------------------------------------" << std::endl;
287 out << "/*" << std::endl;
288 out << "void " << fixedName << "::FunctionName(int& parameterA)" << std::endl;
289 out << "{" << std::endl;
290 out << " parameterA = 2 * parameterA;" << std::endl;
291 out << " return;" << std::endl;
292 out << "}" << std::endl;
293 out << "*/" << std::endl;