CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gOptions.cc
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
32 #include "gVariables.hh"
33 #include "gOptions.hh"
34 #include "sOutputManager.hh"
35 // For error handling
36 #include <errno.h>
37 #include <limits.h>
38 #ifdef _WIN32
39 // Avoid compilation errors due to mix up between std::min()/max() and
40 // min max macros
41 #undef min
42 #undef max
43 #endif
44 
45 // =====================================================================
46 // ---------------------------------------------------------------------
47 // ---------------------------------------------------------------------
48 // =====================================================================
49 /*
50  \fn ReadStringOption
51  \param a_input : string to parse
52  \param ap_return : (templated) array in which the parsed elements will be returned
53  \param a_nbElts : a number of elements to parse
54  \param sep : the separator (usually comma)
55  \param a_option : string indicating from where the function has been called
56  \brief Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator.
57  The results are returned in the templated 'ap_return' dynamic templated array.
58  Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert
59  \return 0 if success, and positive value otherwise.
60 */
61 template<class T>
62 int ReadStringOption(const string& a_input, T* ap_return, int a_nbElts, const string& sep, const string& a_option)
63 {
64 
65  size_t pos = 0;
66  size_t pos2 = a_input.find_first_of(sep, 0);
67 
68  if (a_nbElts>1 && pos2 == string::npos)
69  {
70  Cerr("***** gOptions::ReadStringOption() -> Error : '" << sep << "' not found in option: " << a_option << endl);
71  return 1;
72  }
73  else
74  {
75  for (int i=0 ; i<a_nbElts ; i++)
76  {
77  string elt = a_input.substr(pos, pos2-pos); //substr(position, nbEltToRead)
78 
79  if(ConvertFromString(elt, &ap_return[i]))
80  {
81  Cerr("***** gOptions::ReadStringOption() -> Error when trying to read input data for option: " << a_option << endl);
82  return 1;
83  }
84 
85  pos = pos2+1;
86  pos2 = a_input.find_first_of(sep, pos);
87 
88  // TODO Errors in case of too many/few elements in the string
89  }
90  }
91  return 0;
92 }
93 
94 
95 
96 
97 // =====================================================================
98 // ---------------------------------------------------------------------
99 // ---------------------------------------------------------------------
100 // =====================================================================
101 /*
102  \fn ReadDataASCIIFile
103  \param a_file : string containing the path to the ASCII file
104  \param a_keyword : key related to the data we want to recover
105  \param ap_return : templated array in which the data will be returned
106  the recovered data will be converted to its type
107  its size should be equal to the number of elts to recover
108  \param a_nbElts : number of elements to recover
109  \param a_mandatoryFlag : boolean indicating the data to recover is
110  mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
111  or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)
112  \brief Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter
113  and return the corresponding value(s) in the "ap_return" templated array.
114  This function expects the following parsing :
115  KEY : elt1,elt2,...,eltN
116  \details This function assumes the following separators :
117  ":" is used as separator between the keyworld and the value
118  "#" is used for comment. Every following characters will be discarded
119  "," is used to separate elements if more than one are required
120  \return 0 if success, and positive value otherwise (1 if error, 2 if tag not found).
121 */
122 template<class T>
123 int ReadDataASCIIFile(const string& a_file, const string& a_keyword, T* ap_return, int a_nbElts, bool a_mandatoryFlag)
124 {
125  ifstream input_file(a_file.c_str(), ios::in);
126  string line;
127  string sep = ":";
128  string sep_comment = "#";
129  string sep_elt = ",";
130 
131  // Check file
132  if (input_file)
133  {
134  while(!input_file.eof())
135  {
136  getline(input_file, line);
137 
138  //remove comment
139  if (line.find(sep_comment) != string::npos) line = line.substr(0, line.find_first_of(sep_comment)) ;
140 
141  if (line.find(a_keyword) != string::npos)
142  //if (line.compare(a_keyword) == 0)
143  {
144  //remove field in string
145  line = line.substr(line.find_first_of(sep)+1);
146 
147  //clear every spaces in the line string;
148  //line.erase(remove_if(line.begin(), line.end(), (int(*)(int))isspace), line.end()); // Explicit type (int(*)(int)) is required to tell compiler which function to take the address of.
149 
150  // Erase all blank stuff before first character
151  line.erase(0, line.find_first_not_of(" !\t\r\n")); // Erase all blank stuff before first character
152  line.erase(line.find_last_not_of(" \t\r\n")+1 , line.length());
153 
154  size_t pos = 0;
155  size_t pos2 = line.find_first_of(sep_elt, pos);
156 
157  // Check if separators were found
158  if (a_nbElts>1 && pos2 == string::npos)
159  {
160  Cerr("***** gOptions::ReadDataASCIIFile() -> The required separator : '" << sep_elt << "' not found for tag: " << a_keyword << endl);
161  return 1;
162  }
163  else // Read one element, or several (a_nbElts) elements separated with ','
164  {
165  for (int i=0 ; i<a_nbElts ; i++)
166  {
167  // Check if we reach the end of the line before initializing all elements
168  // SS: corrected this incorrect line: if(pos<0)
169  if (pos==string::npos)
170  {
171  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file '" << a_file << "'." << endl);
172  Cerr("***** Expected to read " << a_nbElts << " elements, but only " << i+1 << " were found." << endl);
173  return 1;
174  }
175 
176  // Parse the line only if more than 1 elt are requested. Just pick the line otherwise
177  string elt = (a_nbElts>1) ? line.substr(pos, pos2-pos) : line ;
178 
179  if (ConvertFromString(elt, &ap_return[i]))
180  {
181  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file '" << a_file << "'." << endl);
182  return 1;
183  }
184 
185 
186  //pos = pos2+1;
187  // return string::npos if pos2 not found, meaning we reach the end of the line
188  // SS: corrected this incorrect line pos = (pos2<0) ? -1 : pos2+1 ;
189  pos = (pos2==string::npos) ? string::npos : pos2+1;
190  pos2 = line.find_first_of(sep_elt, pos);
191 
192  }
193  }
194  return 0;
195  }
196 
197  }
198  // Throw an error message if the tag is mandatory
199  if (a_mandatoryFlag == true)
200  {
201  Cerr("***** gOptions::ReadDataASCIIFile() -> Error when reading file '" << a_file << "'. Tag '" << a_keyword << "' was not found." << endl);
203  }
204  else
205  {
207  }
208  }
209  else
210  {
211  Cerr("***** gOptions::ReadDataASCIIFile() -> Couldn't find or read data-file '"<< a_file << "' !" << endl);
212  return 1;
213  }
214 }
215 
216 
217 
218 
219 // =====================================================================
220 // ---------------------------------------------------------------------
221 // ---------------------------------------------------------------------
222 // =====================================================================
223 /*
224  \fn ReadDataASCIIFile
225  \param a_file : string containing the path to the ASCII file
226  \param a_keyword : key related to the data we want to recover
227  \param ap_return : templated array in which the data will be returned
228  the recovered data will be converted to its type
229  its size should be equal to the nb of lines*nb of elts to recover
230  \param a_nbElts : number of elements to recover (on each line)
231  \param a_nbLines : number of lines to recover
232  \param a_mandatoryFlag : boolean indicating the data to recover is
233  mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
234  or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)
235  \brief Look for "a_nbLines" lines of "a_nbElts" elts in the 'a_file' file matching the "a_keyword" string
236  passed as parameter and return the corresponding value(s) in the "ap_return" templated 1D array.
237  This function expects the following parsing :
238  KEY :
239  line1 : elt1,elt2,...,eltN
240  line2 : elt1,elt2,...,eltN
241  (...)
242  lineN : elt1,elt2,...,eltN
243  \details This function assumes the following separators :
244  ":" is used as separator between the keyworld and the value
245  "#" is used for comment. Every following characters will be discarded
246  "," is used to separate elements if more than one are required
247  \return 0 if success, and positive value otherwise (1 if error, 2 if tag not found).
248 */
249 template<class T>
250 int ReadDataASCIIFile(const string& a_file, const string& a_keyword, T* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag)
251 {
252  ifstream input_file(a_file.c_str(), ios::in);
253  string line;
254  string sep = ":";
255  string sep_comment = "#";
256  string sep_elt = ",";
257 
258  // Check file
259  if (input_file)
260  {
261  while (!input_file.eof())
262  {
263  getline(input_file, line);
264 
265  //remove comment
266  if (line.find(sep_comment)) line = line.substr(0, line.find_first_of(sep_comment));
267 
268  if (line.find(a_keyword) != string::npos)
269  //if (line.compare(a_keyword) == 0)
270  {
271  for (int l=0 ; l<a_nbLines ; l++)
272  {
273  getline(input_file, line);
274  //remove field in string
275  line = line.substr(line.find_first_of(sep)+1);
276 
277  //clear the space before the first element in the line string;
278  //line.erase(remove_if(line.begin(), line.end(), (int(*)(int))isspace), line.end()); // Explicit type (int(*)(int)) is required to tell compiler which function to take the address of.
279 
280  // Erase all blank stuff before first character
281  line.erase(0, line.find_first_not_of(" !\t\r\n")); // Erase all blank stuff before first character
282  line.erase(line.find_last_not_of(" \t\r\n")+1 , line.length());
283 
284  size_t pos = 0;
285  size_t pos2 = line.find_first_of(sep_elt, pos);
286 
287  // Check if separators were found
288  if (a_nbElts>1 && pos2 == string::npos)
289  {
290  Cerr("***** gOptions::ReadDataASCIIFile() -> The required separator : '" << sep_elt << "' not found for tag: " << a_keyword << endl);
291  return 1;
292  }
293  else // Read one element, or several (a_nbElts) elements separated with ','
294  {
295  for (int i=0 ; i<a_nbElts ; i++)
296  {
297  // Check if we reach the end of the line before initializing all elements
298  // SS: corrected this incorrect line: if(pos<0)
299  if (pos==string::npos)
300  {
301  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file '" << a_file << "'." << endl);
302  Cerr("***** Expected to read " << a_nbElts << " elements, but only " << i+1 << " were found." << endl);
303  return 1;
304  }
305 
306  // Parse the line only if more than 1 elt are requested. Just pick the line otherwise
307  string elt = (a_nbElts>1) ? line.substr(pos, pos2-pos) : line ;
308 
309  if (ConvertFromString(elt, &ap_return[l*a_nbElts+i]))
310  {
311  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file " << a_file << endl);
312  return 1;
313  }
314 
315  //pos = pos2+1;
316  // return string::npos if pos2 not found, meaning we reach the end of the line
317  // SS: corrected this incorrect line pos = (pos2<0) ? -1 : pos2+1 ;
318  pos = (pos2==string::npos) ? string::npos : pos2+1;
319  pos2 = line.find_first_of(sep_elt, pos);
320  }
321  }
322  }
323  return 0;
324  }
325  }
326 
327  // Throw an error message if the tag is mandatory
328  if (a_mandatoryFlag == true)
329  {
330  Cerr("***** gOptions::ReadDataASCIIFile() -> Error when reading file '" << a_file << "'. Tag '" << a_keyword << "' was not found." << endl);
332  }
333  else
334  {
336  }
337  }
338  else
339  {
340  Cerr("***** gOptions::ReadDataASCIIFile() -> Couldn't find or read data-file '" << a_file << "' !" << endl);
341  return 1;
342  }
343 }
344 
345 
346 
347 
348 // =====================================================================
349 // ---------------------------------------------------------------------
350 // ---------------------------------------------------------------------
351 // =====================================================================
352 /*
353  \fn ReadDataASCIIFile
354  \param a_file : string containing the path to the ASCII file
355  \param a_keyword : key related to the data we want to recover
356  \param a2p_return : 2D templated array in which the data will be returned
357  the recovered data will be converted to its type
358  its size should be equal [nb of lines][nb of elts to recover]
359  \param a_nbElts : number of elements to recover (on each line)
360  \param a_nbLines : number of lines to recover
361  \param a_mandatoryFlag : boolean indicating the data to recover is
362  mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
363  or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)
364  \brief Look for "a_nbLines" lines of "a_nbElts" elts in the 'a_file' file matching the "a_keyword" string
365  passed as parameter and return the corresponding value(s) in the "a2p_return" 2D array.
366  The first and second dimensions of "a2p_return" correspond to the line and elements respectively
367  This function expects the following parsing :
368  KEY :
369  line1 : elt1,elt2,...,eltN
370  line2 : elt1,elt2,...,eltN
371  (...)
372  lineN : elt1,elt2,...,eltN
373  \details This function assumes the following separators :
374  ":" is used as separator between the keyworld and the value
375  "#" is used for comment. Every following characters will be discarded
376  "," is used to separate elements if more than one are required
377  \return 0 if success, and positive value otherwise (1 if error, 2 if tag not found).
378 */
379 template<class T>
380 int ReadDataASCIIFile(const string& a_file, const string& a_keyword, T** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag)
381 {
382  ifstream input_file(a_file.c_str(), ios::in);
383  string line;
384  string sep = ":";
385  string sep_comment = "#";
386  string sep_elt = ",";
387 
388  // Check file
389  if (input_file)
390  {
391  while (!input_file.eof())
392  {
393  getline(input_file, line);
394 
395  //remove comment
396  if (line.find(sep_comment)) line = line.substr(0, line.find_first_of(sep_comment));
397 
398  if (line.find(a_keyword) != string::npos)
399  //if (line.compare(a_keyword) == 0)
400  {
401  for (int l=0 ; l<a_nbLines ; l++)
402  {
403  getline(input_file, line);
404  //remove field in string
405  line = line.substr(line.find_first_of(sep)+1);
406 
407  //clear the space before the first element in the line string;
408  //line.erase(remove_if(line.begin(), line.end(), (int(*)(int))isspace), line.end()); // Explicit type (int(*)(int)) is required to tell compiler which function to take the address of.
409 
410  // Erase all blank stuff before first character
411  line.erase(0, line.find_first_not_of(" !\t\r\n")); // Erase all blank stuff before first character
412  line.erase(line.find_last_not_of(" \t\r\n")+1 , line.length());
413 
414  size_t pos = 0;
415  size_t pos2 = line.find_first_of(sep_elt, pos);
416 
417  // Check if separators were found
418  if (a_nbElts>1 && pos2 == string::npos)
419  {
420  Cerr("***** gOptions::ReadDataASCIIFile() -> The required separator : '" << sep_elt << "' not found for tag: " << a_keyword << endl);
421  return 1;
422  }
423  else // Read one element, or several (a_nbElts) elements separated with ','
424  {
425  for (int i=0 ; i<a_nbElts ; i++)
426  {
427  // Check if we reach the end of the line before initializing all elements
428  // SS: corrected this incorrect line: if(pos<0)
429  if (pos==string::npos)
430  {
431  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file '" << a_file << "'." << endl);
432  Cerr("***** Expected to read " << a_nbElts << " elements, but only " << i+1 << " were found." << endl);
433  return 1;
434  }
435 
436  // Parse the line only if more than 1 elt are requested. Just pick the line otherwise
437  string elt = (a_nbElts>1) ? line.substr(pos, pos2-pos) : line ;
438 
439  if (ConvertFromString(elt, &a2p_return[l][i]))
440  {
441  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file " << a_file << endl);
442  return 1;
443  }
444 
445  //pos = pos2+1;
446  // return string::npos if pos2 not found, meaning we reach the end of the line
447  // SS: corrected this incorrect line pos = (pos2<0) ? -1 : pos2+1 ;
448  pos = (pos2==string::npos) ? string::npos : pos2+1;
449  pos2 = line.find_first_of(sep_elt, pos);
450  }
451  }
452  }
453  return 0;
454  }
455  }
456 
457  // Throw an error message if the tag is mandatory
458  if (a_mandatoryFlag == true )
459  {
460  Cerr("***** gOptions::ReadDataASCIIFile() -> Error when reading file '" << a_file << "'. Tag '" << a_keyword << "' was not found." << endl);
462  }
463  else
464  {
466  }
467  }
468  else
469  {
470  Cerr("***** gOptions::ReadDataASCIIFile() -> Couldn't find or read data-file '" << a_file << "' !" << endl);
471  return 1;
472  }
473 }
474 
475 
476 
477 
478 // =====================================================================
479 // ---------------------------------------------------------------------
480 // ---------------------------------------------------------------------
481 // =====================================================================
482 
483 /*
484  \fn ReadDataASCIIFile
485  \param a_file : string containing the path to the ASCII file
486  \param a_keyword : key related to the data we want to recover
487  \param ap_return : templated array in which the data will be returned
488  the recovered data will be converted to its type
489  its size should be equal to the number of elts to recover
490  \param a_nbElts : number of elements to recover
491  \param a_mandatoryFlag : boolean indicating the data to recover is
492  mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
493  or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)
494  \param a_firstTag : the requested key will be looked for after the first occurence of this string
495  \param a_lastTag : the requested key will be looked for before the first occurence of this string
496  \brief Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter
497  and return the corresponding value(s) in the "ap_return" templated array.
498  Additionnal two parameters allow to search within two specific tags
499  This function expects the following parsing :
500  FIRST_TAG
501  (...)
502  KEY : elt1,elt2,...,eltN
503  (...)
504  LAST_TAG
505  \details This function assumes the following separators :
506  ":" is used as separator between the keyworld and the value
507  "#" is used for comment. Every following characters will be discarded
508  "," is used to separate elements if more than one are required
509  \return 0 if success, and positive value otherwise (1 if error, 2 if tag not found).
510 */
511 template<class T>
512 int ReadDataASCIIFile(const string& a_file, const string& a_keyword, T* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag)
513 {
514  ifstream input_file(a_file.c_str(), ios::in);
515  string line;
516  string sep = ":";
517  string sep_comment = "#";
518  string sep_elt = ",";
519  bool search_on = false;
520 
521  // Check file
522  if(input_file)
523  {
524  while(!input_file.eof())
525  {
526  getline(input_file, line);
527 
528  //remove comment
529  if (line.find(sep_comment) != string::npos) line = line.substr(0, line.find_first_of(sep_comment)) ;
530 
531  if( line.find(a_firstTag) != string::npos) search_on = true;
532  if( line.find(a_lastTag) != string::npos || line.find("eof") != string::npos ) search_on = false;
533 
534  if( search_on )
535  {
536  if (line.find(a_keyword) != string::npos)
537  //if (line.compare(a_keyword) == 0)
538  {
539  //remove field in string
540  line = line.substr(line.find_first_of(sep)+1);
541 
542  //clear the space before the first element in the line string;
543  //line.erase(remove_if(line.begin(), line.end(), (int(*)(int))isspace), line.end()); // Explicit type (int(*)(int)) is required to tell compiler which function to take the address of.
544 
545  // Erase all blank stuff before first character
546  line.erase(0, line.find_first_not_of(" !\t\r\n")); // Erase all blank stuff before first character
547  line.erase(line.find_last_not_of(" \t\r\n")+1 , line.length());
548 
549  size_t pos = 0;
550  size_t pos2 = line.find_first_of(sep_elt, pos);
551 
552  // Check if separators were found
553  if (a_nbElts>1 && pos2 == string::npos)
554  {
555  Cerr("***** gOptions::ReadDataASCIIFile() -> The required separator : '" << sep_elt << "' not found for tag: " << a_keyword << endl);
556  return 1;
557  }
558  else // Read one element, or several (a_nbElts) elements separated with ','
559  {
560  for (int i=0 ; i<a_nbElts ; i++)
561  {
562 
563  // Check if we reach the end of the line before initializing all elements
564  // SS: corrected this incorrect line: if(pos<0)
565  if (pos==string::npos)
566  {
567  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file '" << a_file << "'." << endl);
568  Cerr("***** Expected to read " << a_nbElts << " elements, but only " << i+1 << " were found." << endl);
569  return 1;
570  }
571 
572  // Parse the line only if more than 1 elt are requested. Just pick the line otherwise
573  string elt = (a_nbElts>1) ? line.substr(pos, pos2-pos) : line ;
574 
575  if(ConvertFromString(elt, &ap_return[i]))
576  {
577  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file '" << a_file << "'." << endl);
578  return 1;
579  }
580 
581  //pos = pos2+1;
582  // return string::npos if pos2 not found, meaning we reach the end of the line
583  // SS: corrected this incorrect line pos = (pos2<0) ? -1 : pos2+1 ;
584  pos = (pos2==string::npos) ? string::npos : pos2+1;
585  pos2 = line.find_first_of(sep_elt, pos);
586  }
587  }
588  return 0;
589  }
590  }
591 
592 
593 
594 
595 
596  }
597  // Throw an error message if the tag is mandatory
598  if(a_mandatoryFlag == true)
599  {
600  Cerr("***** gOptions::ReadDataASCIIFile() -> Error when reading file '" << a_file << "'. Tag '" << a_keyword << "' was not found." << endl);
602  }
603  else
604  {
606  }
607  }
608  else
609  {
610  Cerr("***** gOptions::ReadDataASCIIFile() -> Couldn't find or read data-file '"<< a_file << "' !" << endl);
611  return 1;
612  }
613 }
614 
615 
616 
617 
618 // =====================================================================
619 // ---------------------------------------------------------------------
620 // ---------------------------------------------------------------------
621 // =====================================================================
622 /*
623  \fn ReadDataASCIIFile
624  \param a_file : string containing the path to the ASCII file
625  \param a_keyword : key related to the data we want to recover
626  \param a2p_return : 2D templated array in which the data will be returned
627  the recovered data will be converted to its type
628  its size should be equal [nb of lines][nb of elts to recover]
629  \param a_nbElts : number of elements to recover (on each line)
630  \param a_nbLines : number of lines to recover
631  \param a_mandatoryFlag : boolean indicating the data to recover is
632  mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
633  or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)
634  \param a_firstTag : the requested key will be looked for after the first occurence of this string
635  \param a_lastTag : the requested key will be looked for before the first occurence of this string
636  \brief Look for "a_nbLines" lines of "a_nbElts" elts in the "a_file" file matching the "a_keyword" string
637  passed as parameter and return the corresponding value(s) in the "a2p_return" templated 2D array.
638  The first and second dimensions of "a2p_return" correspond to the line and elements respectively
639  Additionnal two parameters allow to search within two specific tags
640  This function expects the following parsing :
641  KEY :
642  FIRST_TAG
643  (...)
644  line1 : elt1,elt2,...,eltN
645  line2 : elt1,elt2,...,eltN
646  (...)
647  lineN : elt1,elt2,...,eltN
648  (...)
649  LAST_TAG
650  \details This function assumes the following separators :
651  ":" is used as separator between the keyworld and the value
652  "#" is used for comment. Every following characters will be discarded
653  "," is used to separate elements if more than one are required
654  \return 0 if success, and positive value otherwise (1 if error, 2 if tag not found).
655 */
656 template<class T>
657 int ReadDataASCIIFile(const string& a_file, const string& a_keyword, T** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag)
658 {
659  ifstream input_file(a_file.c_str(), ios::in);
660  string line;
661  string sep = ":";
662  string sep_comment = "#";
663  string sep_elt = ",";
664  bool search_on = false;
665 
666  // Check file
667  if(input_file)
668  {
669  while(!input_file.eof())
670  {
671  getline(input_file, line);
672 
673  //remove comment
674  if (line.find(sep_comment) != string::npos) line = line.substr(0, line.find_first_of(sep_comment)) ;
675 
676  if( line.find(a_firstTag) != string::npos) search_on = true;
677  if( line.find(a_lastTag) != string::npos || line.find("eof") != string::npos ) search_on = false;
678 
679  if( search_on )
680  {
681  for (int l=0 ; l<a_nbLines ; l++)
682  {
683  getline(input_file, line);
684  //remove field in string
685  line = line.substr(line.find_first_of(sep)+1);
686 
687  //clear the space before the first element in the line string;
688  //line.erase(remove_if(line.begin(), line.end(), (int(*)(int))isspace), line.end()); // Explicit type (int(*)(int)) is required to tell compiler which function to take the address of.
689 
690  // Erase all blank stuff before and after first character
691  line.erase(0, line.find_first_not_of(" !\t\r\n"));
692  line.erase(line.find_last_not_of(" \t\r\n")+1 , line.length());
693 
694  size_t pos = 0;
695  size_t pos2 = line.find_first_of(sep_elt, pos);
696 
697  // Check if separators were found
698  if (a_nbElts>1 && pos2 == string::npos)
699  {
700  Cerr("***** gOptions::ReadDataASCIIFile() -> The required separator : '" << sep_elt << "' not found for tag: " << a_keyword << endl);
701  return 1;
702  }
703  else // Read one element, or several (a_nbElts) elements separated with ','
704  {
705  for (int i=0 ; i<a_nbElts ; i++)
706  {
707  // Check if we reach the end of the line before initializing all elements
708  // SS: corrected this incorrect line: if(pos<0)
709  if (pos==string::npos)
710  {
711  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file '" << a_file << "'." << endl);
712  Cerr("***** Expected to read " << a_nbElts << " elements, but only " << i+1 << " were found." << endl);
713  return 1;
714  }
715 
716  // Parse the line only if more than 1 elt are requested. Just pick the line otherwise
717  string elt = (a_nbElts>1) ? line.substr(pos, pos2-pos) : line ;
718 
719  if (ConvertFromString(elt, &a2p_return[l][i]))
720  {
721  Cerr("***** gOptions::ReadDataASCIIFile() -> Exception when trying to read tag '" << a_keyword << "' in file " << a_file << endl);
722  return 1;
723  }
724 
725  //pos = pos2+1;
726  // return string::npos if pos2 not found, meaning we reach the end of the line
727  // SS: corrected this incorrect line pos = (pos2<0) ? -1 : pos2+1 ;
728  pos = (pos2==string::npos) ? string::npos : pos2+1;
729  pos2 = line.find_first_of(sep_elt, pos);
730  }
731  }
732 
733  }
734  return 0;
735  }
736  }
737  // Throw an error message if the tag is mandatory
738  if(a_mandatoryFlag == true)
739  {
740  Cerr("***** gOptions::ReadDataASCIIFile() -> Error when reading file '" << a_file << "'. Tag '" << a_keyword << "' was not found." << endl);
742  }
743  else
744  {
746  }
747  }
748  else
749  {
750  Cerr("***** gOptions::ReadDataASCIIFile() -> Couldn't find or read data-file '"<< a_file << "' !" << endl);
751  return 1;
752  }
753 }
754 
755 
756 
757 
758 // =====================================================================
759 // ---------------------------------------------------------------------
760 // ---------------------------------------------------------------------
761 // =====================================================================
762 /*
763  \fn ConvertFromString
764  \param a_str : string to convert
765  \param a_result : variable which will recover the result
766  \brief Copy the 'a_str' string in the position pointed by 'a_result'
767  \details The only purposes of this function is to have an
768  unified templated conversion function for each type
769  \return 0 if success, and positive value otherwise
770 */
771 int ConvertFromString(const string& a_str, string* a_result)
772 {
773  *a_result = a_str.c_str();
774  return 0;
775 }
776 
777 
778 
779 
780 // =====================================================================
781 // ---------------------------------------------------------------------
782 // ---------------------------------------------------------------------
783 // =====================================================================
784 /*
785  \fn ConvertFromString
786  \param a_str : string to convert
787  \param a_result : variable which will recover the result
788  \brief Convert the 'a_str' string in float and copy the result in the variable pointed by 'a_result'
789  \details Uses strtod to check errors with str to float conversion
790  (implementation similar to c++11 std::stof() ).
791  \return 0 if success, and positive value otherwise
792 */
793 int ConvertFromString(const string& a_str, float* a_result)
794 {
795  const char* p = a_str.c_str();
796  char* end;
797  errno = 0;
798  double val = strtod(p, &end);
799 
800  if (p == end)
801  {
802  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into float " << endl);
803  return 1;
804  }
805  if (errno == ERANGE)
806  {
807  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into float " << endl);
808  return 1;
809  }
810 
811  *a_result = static_cast<float>(val);
812 
813  return 0;
814 }
815 
816 
817 
818 
819 // =====================================================================
820 // ---------------------------------------------------------------------
821 // ---------------------------------------------------------------------
822 // =====================================================================
823 /*
824  \fn ConvertFromString
825  \param a_str : string to convert
826  \param a_result : variable which will recover the result
827  \brief Convert the 'a_str' string in double and copy the result in the position pointed by 'a_result'
828  \details Uses strtod to check errors with str to double conversion
829  (implementation similar to c++11 std::stod() ).
830  \return 0 if success, and positive value otherwise
831 */
832 int ConvertFromString(const string& a_str, double* a_result)
833 {
834  const char* p = a_str.c_str();
835  char* end;
836  errno = 0;
837  double val = strtod(p, &end);
838 
839  if (p == end)
840  {
841  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into double " << endl);
842  return 1;
843  }
844  if (errno == ERANGE)
845  {
846  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into double " << endl);
847  return 1;
848  }
849 
850  *a_result = val;
851 
852  return 0;
853 }
854 
855 
856 
857 
858 // =====================================================================
859 // ---------------------------------------------------------------------
860 // ---------------------------------------------------------------------
861 // =====================================================================
862 /*
863  \fn ConvertFromString
864  \param a_str : string to convert
865  \param a_result : variable which will recover the result
866  \brief Convert the 'a_str' string in long double and copy the result in the position pointed by 'a_result'
867  \details Uses strtod to check errors with str to ldouble conversion
868  (implementation similar to c++11 std::stod() ).
869  \return 0 if success, and positive value otherwise
870 */
871 int ConvertFromString(const string& a_str, long double* a_result)
872 {
873  const char* p = a_str.c_str();
874  char* end;
875  errno = 0;
876  long double val = strtold(p, &end);
877 
878  if (p == end)
879  {
880  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into double " << endl);
881  return 1;
882  }
883  if (errno == ERANGE)
884  {
885  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into double " << endl);
886  return 1;
887  }
888 
889  *a_result = val;
890 
891  return 0;
892 }
893 
894 
895 
896 
897 // =====================================================================
898 // ---------------------------------------------------------------------
899 // ---------------------------------------------------------------------
900 // =====================================================================
901 /*
902  \fn ConvertFromString
903  \param a_str : string to convert
904  \param a_result : variable which will recover the result
905  \brief Convert the 'a_str' string in int and copy the result in the position pointed by 'a_result'
906  \details Uses strtol to check errors with str to int conversion
907  (implementation similar to c++11 std::stoi() ).
908  \return 0 if success, and positive value otherwise
909 */
910 int ConvertFromString(const string& a_str, int* a_result)
911 {
912  const char* p = a_str.c_str();
913  char* end;
914  errno = 0;
915  int64_t val = strtol(p, &end, 10);
916 
917  if (p == end)
918  {
919  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into int " << endl);
920  return 1;
921  }
922  if (errno==ERANGE || val<INT_MIN || val>INT_MAX)
923  {
924  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into int " << endl);
925  return 1;
926  }
927 
928  *a_result = static_cast<int>(val);
929 
930  return 0;
931 }
932 
933 
934 
935 
936 // =====================================================================
937 // ---------------------------------------------------------------------
938 // ---------------------------------------------------------------------
939 // =====================================================================
940 /*
941  \fn ConvertFromString
942  \param a_str : string to convert
943  \param a_result : variable which will recover the result
944  \brief Convert the 'a_str' string in int64_t and copy the result in the position pointed by 'a_result'
945  \details Uses strtol to check errors with str to lint conversion
946  (implementation similar to c++11 std::stol() ).
947  \return 0 if success, and positive value otherwise
948 */
949 int ConvertFromString(const string& a_str, int64_t* a_result)
950 {
951  const char* p = a_str.c_str();
952  char* end;
953  errno = 0;
954  int64_t val = strtol(p, &end, 10);
955 
956  if (p == end)
957  {
958  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into int64_t " << endl);
959  return 1;
960  }
961  if (errno == ERANGE)
962  {
963  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into int64_t " << endl);
964  return 1;
965  }
966 
967  *a_result = val;
968 
969  return 0;
970 }
971 
972 
973 
974 
975 // =====================================================================
976 // ---------------------------------------------------------------------
977 // ---------------------------------------------------------------------
978 // =====================================================================
979 /*
980  \fn ConvertFromString
981  \param a_str : string to convert
982  \param a_result : variable which will recover the result
983  \brief Convert the 'a_str' string in uint16_t and copy the result in the position pointed by 'a_result'
984  \details Uses strtol to check errors with str to uint8 conversion
985  (implementation similar to c++11 std::stoi() ).
986  \return 0 if success, and positive value otherwise
987 */
988 int ConvertFromString(const string& a_str, uint8_t* a_result)
989 {
990  const char* p = a_str.c_str();
991  char* end;
992  errno = 0;
993  int64_t val = strtol(p, &end, 10);
994 
995  if (p == end)
996  {
997  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into uint16 " << endl);
998  return 1;
999  }
1000  if (errno == ERANGE || val<0 || val>UCHAR_MAX)
1001  {
1002  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into uint16 " << endl);
1003  return 1;
1004  }
1005 
1006  *a_result = val;
1007 
1008  return 0;
1009 }
1010 
1011 
1012 
1013 
1014 // =====================================================================
1015 // ---------------------------------------------------------------------
1016 // ---------------------------------------------------------------------
1017 // =====================================================================
1018 /*
1019  \fn ConvertFromString
1020  \param a_str : string to convert
1021  \param a_result : variable which will recover the result
1022  \brief Convert the 'a_str' string in uint16_t and copy the result in the position pointed by 'a_result'
1023  \details Uses strtol to check errors with str to uint16 conversion
1024  (implementation similar to c++11 std::stoi() ).
1025  \return 0 if success, and positive value otherwise
1026 */
1027 int ConvertFromString(const string& a_str, uint16_t* a_result)
1028 {
1029  const char* p = a_str.c_str();
1030  char* end;
1031  errno = 0;
1032  int64_t val = strtol(p, &end, 10);
1033 
1034  if (p == end)
1035  {
1036  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into uint16 " << endl);
1037  return 1;
1038  }
1039  if (errno == ERANGE || val<0 || val>USHRT_MAX)
1040  {
1041  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into uint16 " << endl);
1042  return 1;
1043  }
1044 
1045  *a_result = val;
1046 
1047  return 0;
1048 }
1049 
1050 
1051 
1052 
1053 // =====================================================================
1054 // ---------------------------------------------------------------------
1055 // ---------------------------------------------------------------------
1056 // =====================================================================
1057 /*
1058  \fn ConvertFromString
1059  \param a_str : string to convert
1060  \param a_result : variable which will recover the result
1061  \brief Convert the 'a_str' string in uint32_t and copy the result in the position pointed by 'a_result'
1062  \details Uses strtol to check errors with str to uint32 conversion
1063  (implementation similar to c++11 std::stoi() ).
1064  \return 0 if success, and positive value otherwise
1065 */
1066 int ConvertFromString(const string& a_str, uint32_t* a_result)
1067 {
1068  const char* p = a_str.c_str();
1069  char* end;
1070  errno = 0;
1071  int64_t val = strtol(p, &end, 10);
1072 
1073  if (p == end)
1074  {
1075  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into uint32 " << endl);
1076  return 1;
1077  }
1078  if (errno == ERANGE || val<0 || val>UINT_MAX)
1079  {
1080  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into uint32 " << endl);
1081  return 1;
1082  }
1083 
1084  *a_result = val;
1085 
1086  return 0;
1087 }
1088 
1089 
1090 
1091 
1092 // =====================================================================
1093 // ---------------------------------------------------------------------
1094 // ---------------------------------------------------------------------
1095 // =====================================================================
1096 /*
1097  \fn ConvertFromString
1098  \param a_str : string to convert
1099  \param a_result : variable which will recover the result
1100  \brief Convert the 'a_str' string in bool and copy the result in the position pointed by 'a_result'
1101  \details Uses strtol to check errors with str to bool conversion
1102  (implementation similar to c++11 std::stoi() ).
1103  \return 0 if success, and positive value otherwise
1104 */
1105 int ConvertFromString(const string& a_str, bool* a_result)
1106 {
1107  const char* p = a_str.c_str();
1108  char* end;
1109  errno = 0;
1110  int64_t val = strtol(p, &end, 10);
1111 
1112  if (p == end)
1113  {
1114  Cerr("***** gOptions::ConvertFromString() -> Invalid argument exception while trying to convert '" << a_str << "' into bool " << endl);
1115  return 1;
1116  }
1117  if (errno == ERANGE || val<0 || val>1)
1118  {
1119  Cerr("***** gOptions::ConvertFromString() -> Out of range exception while trying to convert '" << a_str << "' into bool " << endl);
1120  return 1;
1121  }
1122 
1123  *a_result = val;
1124 
1125  return 0;
1126 }
1127 
1128 
1129 
1130 
1131 // =====================================================================
1132 // ---------------------------------------------------------------------
1133 // ---------------------------------------------------------------------
1134 // =====================================================================
1135 /*
1136  \fn GetFileFromPath()
1137  \param a_pathToFile
1138  \brief Simply return the file from a path string passed in parameter
1139  \return The path.
1140 */
1141 string GetFileFromPath(const string& a_pathToFile)
1142 {
1143  string path = a_pathToFile;
1144 
1145  int pos = path.find_last_of(OS_SEP);
1146  if (path.find_last_of(OS_SEP) == string::npos)
1147  return path;
1148 
1149  path = path.substr(pos+1);
1150  return path;
1151 }
1152 
1153 
1154 
1155 
1156 // =====================================================================
1157 // ---------------------------------------------------------------------
1158 // ---------------------------------------------------------------------
1159 // =====================================================================
1160 /*
1161  \fn GetPathOfFile()
1162  \param a_pathToFile
1163  \brief Simply return the path to the directory of a file path string passed in parameter
1164  \return The path.
1165 */
1166 string GetPathOfFile(const string& a_pathToFile)
1167 {
1168  string path = a_pathToFile;
1169 
1170  int pos = path.find_last_of(OS_SEP);
1171  if (path.find_last_of(OS_SEP) == string::npos)
1172  return "";
1173 
1174  path = path.substr(0,pos+1);
1175 
1176  return path;
1177 }
1178 
1179 
1180 /*
1181  \fn string ConvertAllSlashOcurrencesToBackSlash()
1182  \param const string& a_path
1183  \brief Simply convert all occurrences of "/" to "\"
1184  \return A new converted string
1185 */
1186 string ConvertAllSlashOccurrencesToBackSlash(const string& a_path)
1187 {
1188  string result = a_path;
1189  size_t position;
1190  while ( (position = result.find_first_of("/")) != string::npos )
1191  {
1192  result.replace(position,1,"\\");
1193  }
1194  return result;
1195 }
1196 
1197 
1198 /*
1199  \fn bool FLTNBIsEqual(FLTNB a, FLTNB b, FLTNB a_eps)
1200  \param a : 1st FLTNB nb to compare
1201  \param b : 2nd FLTNB nb to compare
1202  \param a_eps : epsilon for comparison
1203  \brief Comparison of FLTNB numbers
1204  \return true if equal according to the provided epsilon, false otherwise
1205 */
1206 bool FLTNBIsEqual(FLTNB a, FLTNB b, FLTNB a_eps)
1207 {
1208  FLTNB absA = abs(a);
1209  FLTNB absB = abs(b);
1210  FLTNB diff = abs(a - b);
1211 
1212  if (a == b)
1213  {
1214  return true;
1215  }
1216  else if (a == 0 ||
1217  b == 0 ||
1218  diff < std::numeric_limits<FLTNB>::min())
1219  { // a or b is 0, or extremely close to it
1220  return diff < (a_eps * std::numeric_limits<FLTNB>::min() );
1221  }
1222  else
1223  { // relative error
1224  return diff / min((absA + absB), std::numeric_limits<FLTNB>::max()) < a_eps;
1225  }
1226 }
1227 
1228 
1229 // =====================================================================
1230 // ---------------------------------------------------------------------
1231 // ---------------------------------------------------------------------
1232 // =====================================================================
1233 // Explicit template instantiation
1234 // (that way no one would use the templated versions of these functions for not yet implemented type (long double, unsigned, ect..) )
1235 template int ReadStringOption<string>(const string& a_input, string* ap_return, int a_nbElts, const string& sep, const string& a_option);
1236 template int ReadStringOption<int>(const string& a_input, int* ap_return, int a_nbElts, const string& sep, const string& a_option);
1237 template int ReadStringOption<int64_t>(const string& a_input, int64_t* ap_return, int a_nbElts, const string& sep, const string& a_option);
1238 template int ReadStringOption<float>(const string& a_input, float* ap_return, int a_nbElts, const string& sep, const string& a_option);
1239 template int ReadStringOption<double>(const string& a_input, double* ap_return, int a_nbElts, const string& sep, const string& a_option);
1240 template int ReadStringOption<long double>(const string& a_input, long double* ap_return, int a_nbElts, const string& sep, const string& a_option);
1241 template int ReadStringOption<uint8_t>(const string& a_input, uint8_t* ap_return, int a_nbElts, const string& sep, const string& a_option);
1242 template int ReadStringOption<uint16_t>(const string& a_input, uint16_t* ap_return, int a_nbElts, const string& sep, const string& a_option);
1243 template int ReadStringOption<uint32_t>(const string& a_input, uint32_t* ap_return, int a_nbElts, const string& sep, const string& a_option);
1244 template int ReadStringOption<bool>(const string& a_input, bool* ap_return, int a_nbElts, const string& sep, const string& a_option);
1245 
1246 template int ReadDataASCIIFile<string>(const string& a_file, const string& a_keyword, string* ap_return, int a_nbElts, bool a_mandatoryFlag);
1247 template int ReadDataASCIIFile<int>(const string& a_file, const string& a_keyword, int* ap_return, int a_nbElts, bool a_mandatoryFlag);
1248 template int ReadDataASCIIFile<int64_t>(const string& a_file, const string& a_keyword, int64_t* ap_return, int a_nbElts, bool a_mandatoryFlag);
1249 template int ReadDataASCIIFile<float>(const string& a_file, const string& a_keyword, float* ap_return, int a_nbElts, bool a_mandatoryFlag);
1250 template int ReadDataASCIIFile<double>(const string& a_file, const string& a_keyword, double* ap_return, int a_nbElts, bool a_mandatoryFlag);
1251 template int ReadDataASCIIFile<long double>(const string& a_file, const string& a_keyword, long double* ap_return, int a_nbElts, bool a_mandatoryFlag);
1252 template int ReadDataASCIIFile<uint8_t>(const string& a_file, const string& a_keyword, uint8_t* ap_return, int a_nbElts, bool a_mandatoryFlag);
1253 template int ReadDataASCIIFile<uint16_t>(const string& a_file, const string& a_keyword, uint16_t* ap_return, int a_nbElts, bool a_mandatoryFlag);
1254 template int ReadDataASCIIFile<uint32_t>(const string& a_file, const string& a_keyword, uint32_t* ap_return, int a_nbElts, bool a_mandatoryFlag);
1255 template int ReadDataASCIIFile<bool>(const string& a_file, const string& a_keyword, bool* ap_return, int a_nbElts, bool a_mandatoryFlag);
1256 
1257 template int ReadDataASCIIFile<string>(const string& a_file, const string& a_keyword, string* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1258 template int ReadDataASCIIFile<int>(const string& a_file, const string& a_keyword, int* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1259 template int ReadDataASCIIFile<int64_t>(const string& a_file, const string& a_keyword, int64_t* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1260 template int ReadDataASCIIFile<float>(const string& a_file, const string& a_keyword, float* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1261 template int ReadDataASCIIFile<double>(const string& a_file, const string& a_keyword, double* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1262 template int ReadDataASCIIFile<long double>(const string& a_file, const string& a_keyword, long double* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1263 template int ReadDataASCIIFile<uint8_t>(const string& a_file, const string& a_keyword, uint8_t* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1264 template int ReadDataASCIIFile<uint16_t>(const string& a_file, const string& a_keyword, uint16_t* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1265 template int ReadDataASCIIFile<uint32_t>(const string& a_file, const string& a_keyword, uint32_t* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1266 template int ReadDataASCIIFile<bool>(const string& a_file, const string& a_keyword, bool* ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1267 
1268 template int ReadDataASCIIFile<string>(const string& a_file, const string& a_keyword, string** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1269 template int ReadDataASCIIFile<int>(const string& a_file, const string& a_keyword, int** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1270 template int ReadDataASCIIFile<int64_t>(const string& a_file, const string& a_keyword, int64_t** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1271 template int ReadDataASCIIFile<float>(const string& a_file, const string& a_keyword, float** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1272 template int ReadDataASCIIFile<double>(const string& a_file, const string& a_keyword, double** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1273 template int ReadDataASCIIFile<long double>(const string& a_file, const string& a_keyword, long double** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1274 template int ReadDataASCIIFile<uint8_t>(const string& a_file, const string& a_keyword, uint8_t** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1275 template int ReadDataASCIIFile<uint16_t>(const string& a_file, const string& a_keyword, uint16_t** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1276 template int ReadDataASCIIFile<uint32_t>(const string& a_file, const string& a_keyword, uint32_t** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1277 template int ReadDataASCIIFile<bool>(const string& a_file, const string& a_keyword, bool** ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag);
1278 
1279 template int ReadDataASCIIFile<string>(const string& a_file, const string& a_keyword, string* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1280 template int ReadDataASCIIFile<int>(const string& a_file, const string& a_keyword, int* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1281 template int ReadDataASCIIFile<int64_t>(const string& a_file, const string& a_keyword, int64_t* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1282 template int ReadDataASCIIFile<float>(const string& a_file, const string& a_keyword, float* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1283 template int ReadDataASCIIFile<double>(const string& a_file, const string& a_keyword, double* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1284 template int ReadDataASCIIFile<long double>(const string& a_file, const string& a_keyword, long double* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1285 template int ReadDataASCIIFile<uint8_t>(const string& a_file, const string& a_keyword, uint8_t* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1286 template int ReadDataASCIIFile<uint16_t>(const string& a_file, const string& a_keyword, uint16_t* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1287 template int ReadDataASCIIFile<uint32_t>(const string& a_file, const string& a_keyword, uint32_t* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1288 template int ReadDataASCIIFile<bool>(const string& a_file, const string& a_keyword, bool* ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1289 
1290 template int ReadDataASCIIFile<string>(const string& a_file, const string& a_keyword, string** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1291 template int ReadDataASCIIFile<int>(const string& a_file, const string& a_keyword, int** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1292 template int ReadDataASCIIFile<int64_t>(const string& a_file, const string& a_keyword, int64_t** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1293 template int ReadDataASCIIFile<float>(const string& a_file, const string& a_keyword, float** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1294 template int ReadDataASCIIFile<double>(const string& a_file, const string& a_keyword, double** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1295 template int ReadDataASCIIFile<long double>(const string& a_file, const string& a_keyword, long double** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1296 template int ReadDataASCIIFile<uint8_t>(const string& a_file, const string& a_keyword, uint8_t** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1297 template int ReadDataASCIIFile<uint16_t>(const string& a_file, const string& a_keyword, uint16_t** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1298 template int ReadDataASCIIFile<uint32_t>(const string& a_file, const string& a_keyword, uint32_t** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
1299 template int ReadDataASCIIFile<bool>(const string& a_file, const string& a_keyword, bool** a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag);
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
Definition: gOptions.cc:1141
This header file is mainly used to declare some macro definitions and all includes needed from the st...
template int ReadDataASCIIFile< double >(const string &a_file, const string &a_keyword, double *ap_return, int a_nbElts, bool a_mandatoryFlag)
#define FLTNB
Definition: gVariables.hh:81
template int ReadDataASCIIFile< float >(const string &a_file, const string &a_keyword, float *ap_return, int a_nbElts, bool a_mandatoryFlag)
template int ReadDataASCIIFile< int >(const string &a_file, const string &a_keyword, int *ap_return, int a_nbElts, bool a_mandatoryFlag)
template int ReadStringOption< int64_t >(const string &a_input, int64_t *ap_return, int a_nbElts, const string &sep, const string &a_option)
template int ReadStringOption< uint8_t >(const string &a_input, uint8_t *ap_return, int a_nbElts, const string &sep, const string &a_option)
template int ReadStringOption< uint32_t >(const string &a_input, uint32_t *ap_return, int a_nbElts, const string &sep, const string &a_option)
template int ReadDataASCIIFile< int64_t >(const string &a_file, const string &a_keyword, int64_t *ap_return, int a_nbElts, bool a_mandatoryFlag)
#define KEYWORD_MANDATORY_NOT_FOUND
Definition: gOptions.hh:52
template int ReadStringOption< string >(const string &a_input, string *ap_return, int a_nbElts, const string &sep, const string &a_option)
template int ReadDataASCIIFile< long double >(const string &a_file, const string &a_keyword, long double *ap_return, int a_nbElts, bool a_mandatoryFlag)
template int ReadStringOption< uint16_t >(const string &a_input, uint16_t *ap_return, int a_nbElts, const string &sep, const string &a_option)
string ConvertAllSlashOccurrencesToBackSlash(const string &a_path)
Definition: gOptions.cc:1186
#define Cerr(MESSAGE)
bool FLTNBIsEqual(FLTNB a, FLTNB b, FLTNB a_eps)
Comparison of FLTNB numbers.
Definition: gOptions.cc:1206
string GetPathOfFile(const string &a_pathToFile)
Simply return the path to the directory of a file path string passed in parameter.
Definition: gOptions.cc:1166
template int ReadDataASCIIFile< bool >(const string &a_file, const string &a_keyword, bool *ap_return, int a_nbElts, bool a_mandatoryFlag)
template int ReadDataASCIIFile< uint16_t >(const string &a_file, const string &a_keyword, uint16_t *ap_return, int a_nbElts, bool a_mandatoryFlag)
template int ReadDataASCIIFile< uint8_t >(const string &a_file, const string &a_keyword, uint8_t *ap_return, int a_nbElts, bool a_mandatoryFlag)
template int ReadDataASCIIFile< string >(const string &a_file, const string &a_keyword, string *ap_return, int a_nbElts, bool a_mandatoryFlag)
#define OS_SEP
int ReadStringOption(const string &a_input, T *ap_return, int a_nbElts, const string &sep, const string &a_option)
Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator. The results are returned in the templated 'ap_return' dynamic templated array. Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert.
Definition: gOptions.cc:62
template int ReadStringOption< bool >(const string &a_input, bool *ap_return, int a_nbElts, const string &sep, const string &a_option)
#define KEYWORD_OPTIONAL_NOT_FOUND
Definition: gOptions.hh:58
template int ReadStringOption< double >(const string &a_input, double *ap_return, int a_nbElts, const string &sep, const string &a_option)
Declaration of class sOutputManager.
template int ReadDataASCIIFile< uint32_t >(const string &a_file, const string &a_keyword, uint32_t *ap_return, int a_nbElts, bool a_mandatoryFlag)
This file is used for all kind of different functions designed for options parsing and ASCII file rea...
int ReadDataASCIIFile(const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter a...
Definition: gOptions.cc:123
int ConvertFromString(const string &a_str, string *a_result)
Copy the 'a_str' string in the position pointed by 'a_result'.
Definition: gOptions.cc:771
template int ReadStringOption< float >(const string &a_input, float *ap_return, int a_nbElts, const string &sep, const string &a_option)
template int ReadStringOption< int >(const string &a_input, int *ap_return, int a_nbElts, const string &sep, const string &a_option)
template int ReadStringOption< long double >(const string &a_input, long double *ap_return, int a_nbElts, const string &sep, const string &a_option)