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 # ------------------------------------------------------------------------ */
30 bool checknum(std::string s)
32 std::istringstream iss(s);
33 std::ostringstream oss;
46 std::string StringClear(std::string in, std::vector<std::string> no)
50 for (int i=0; i<no.size(); i++)
52 std::string viejo = no.at(i);
54 while (found!=std::string::npos)
57 int inicio = int(found);
58 in.replace(found,viejo.length(),"");
65 std::string StringReplace(std::string in, std::string viejo, std::string nuevo)
69 // different member versions of find in the same order as above:
71 while (found!=std::string::npos)
74 //int inicio = int(found); // JPR
75 in.replace(found,viejo.length(),nuevo);
81 std::vector < std::string > StringSplit(std::string str, std::string delim)
83 std::vector<std::string> results;
85 while( (cutAt = (int)str.find_first_of(delim)) != str.npos )
89 results.push_back(str.substr(0,cutAt));
91 str = str.substr(cutAt+1);
95 results.push_back(str);
100 std::string generateFileName(std::string input, int number, std::string prefix)
104 int position = input.find( "\\" ); // find first space
105 while ( position != std::string::npos )
107 input.replace( position, 1, "/" );
108 position = input.find( "\\", position + 1 );
111 bool comienza_con_slash = false;
113 if (input.at(0) == '/')
114 comienza_con_slash = true;
116 std::vector< std::string > partes = StringSplit(input, "/");
118 std::stringstream number_str;
119 number_str << number;
120 std::string number_str_texto = number_str.str();
123 int tamanio = number_str_texto.size();
124 int diferencia = ceros-tamanio;
125 for (int i=0; i<diferencia ; i++)
126 number_str_texto="0"+number_str_texto;
128 std::string rta = partes[0];
130 for (unsigned int i=1; i<partes.size(); i++)
132 if (i==partes.size()-1)
134 std::vector<std::string> partes_punto;
135 partes_punto = StringSplit(partes[i], ".");
137 La extension es: partes_punto[partes_punto.size()-1]
139 std::string oldname = "";
140 for (unsigned int h=0; h<partes_punto.size();h++)
142 oldname += partes_punto.at(h)+"_";
144 if (partes_punto.size() > 1)
145 rta+="/"+prefix+"_"+oldname+"_"+number_str_texto+"."+partes_punto[partes_punto.size()-1];
147 rta+="/"+prefix+"_"+oldname+"_"+number_str_texto;
154 if (comienza_con_slash)
159 bool existFile(std::string myFileName)
162 inp.open(myFileName.c_str(), std::ifstream::in);
172 std::string guessName(std::string nombre)
175 int max_iter = 10000;
177 while(iterador < max_iter)
179 std::string nuevo = generateFileName(nombre, iterador, "Data");
181 if (existFile(nuevo))
187 std::cout << nuevo << std::endl;
191 std::cout << nombre << std::endl;
195 std::string guessExistent(std::string nombre, int* actual, bool* hay)
197 std::string nada = "";
198 if (actual == NULL || hay == NULL)
200 int iterador = *actual;
203 while(iterador < max_iter)
205 std::string nuevo = generateFileName(nombre, iterador, "Data");
207 if (existFile(nuevo))