CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsString.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #pragma once
32 
34 
36 namespace ceps
37 {
55  split(const CepsString& s, const CepsString& delimiters = CepsString (" \t"));
56 
59  split(const CepsMap<CepsString, CepsString>& map, const CepsString& delimiters = CepsString (" \t"));
60 
63  split(const CepsVector<CepsString>& vec, const CepsString& delimiters = CepsString (" \t"));
64 
73  join(const CepsVector<CepsString>& vec, const CepsChar& delimeter = ' ');
74 
81  trim(const CepsString& s);
82 
89  removeSpaces(const CepsString& s);
90 
99  substract(const CepsString& s, const CepsString& toErase);
100 
108  CepsString
109  substract(const CepsString& s, const CepsVector<CepsString>& toErase);
110 
116  CepsString
117  toUpper(const CepsString& s);
118 
124  CepsString
125  toLower(const CepsString& s);
126 
133  CepsBool
134  isPathInOneWord(const CepsString& s);
135 
141  CepsString
142  toKey(const CepsString& s);
143 
150  toKey(const CepsVector<CepsString>& vec);
151 
155  void
157 
164  CepsBool
165  toBool(const CepsString& s);
166 
172  CepsReal
173  toReal(const CepsString& s);
174 
181  toReals(const CepsString& s);
182 
191 
199 
211 
217  CepsInt
218  toInt(const CepsString& s);
219 
226  toInts(const CepsString& s);
227 
233  CepsUInt
234  toUInt(const CepsString& s);
235 
242  toUInts(const CepsString& s);
243 
250  CepsBool
251  isNumber(const CepsString& s);
252 
261  CepsBool
262  startsWith(const CepsString& s, const CepsString& comp);
263 
272  CepsBool
273  startsWithOneOf(const CepsString& s, const CepsVector<CepsString>& comps);
274 
278  CepsBool
279  endsWith(const CepsString& s, const CepsString& comp);
280 
284  CepsBool
285  endsWithOneOf(const CepsString& s, const CepsVector<CepsString>& comps);
286 
298  splitByKeyword(const CepsString& s, const CepsSet<CepsString>& tags);
299 
311  const CepsString& s,
312  CepsUInt n,
313  CepsString delimiters = CepsString (" \t")
314  );
315 
326  const CepsString& s,
327  const CepsUInt& n,
328  CepsString delimiters = CepsString (" \t")
329  );
330 
340  CepsString
341  readParams(
342  const CepsVector<CepsString>& scope,
343  const CepsString& tag,
344  const CepsString& def = "",
345  const CepsUInt& pad = 1
346  );
347 
349  CepsString
350  removeDoubleSlashes(const CepsString& path);
351 
359  CepsString
360  getDir(const CepsString& str);
361 
370  CepsString
371  getFilename(const CepsString& str);
372 
381  CepsString
382  getBaseName(const CepsString& str);
383 
390  CepsString
391  getExtension(const CepsString& str);
392 
400  CepsString
401  changeExtension(const CepsString& str, const CepsString& ext);
402 
407  template <typename _Tp>
408  CepsString
409  toString(_Tp value)
410  {
411  return std::to_string(value);
412  }
413 
421  CepsBool
422  fileExists(const CepsString& fileName, const CepsString& directory);
423 
430  CepsBool
431  fileExists(const CepsString& fileName);
432 
440  CepsBool
441  isSameFile(const CepsString& f1, const CepsString& f2);
442 
450  cleanup(const CepsVector<CepsString>& vec);
451 
454  CepsReal
455  readReal(std::istream& file, const CepsString& errorMessage="");
456 
459  CepsInt
460  readInt(std::istream& file, const CepsString& errorMessage="");
461 
464  CepsReal3D
465  readVertex(std::istream& file, const CepsString& errorMessage="");
466 
470  readTensor(std::istream& file, const CepsString& errorMessage="");
471 
473  template<CepsUInt n>
475  readReals(std::istream& file, const CepsString& errorMessage="");
476 
477 } // namespace ceps
478 
479 template<CepsUInt n>
481 ceps::readReals(std::istream& file, const CepsString& errorMessage)
482 {
484  for (CepsUInt i=0;i<n;i++)
485  res[i] = ceps::readReal(file,errorMessage+"("+std::to_string(i)+"/"+std::to_string(n)+")");
486  return res;
487 }
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
std::array< _Type, _N > CepsArray
C++ arrays.
Definition: CepsTypes.hpp:159
CepsScalar CepsMathScalar
Real numbers.
Definition: CepsTypes.hpp:133
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
char CepsChar
Char.
Definition: CepsTypes.hpp:125
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
Eigen::Matrix< CepsScalar, 3, 3 > CepsMathTensor
Tensor, eigen format.
Definition: CepsTypes.hpp:137
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
Eigen::Matrix< CepsScalar, 3, 1 > CepsMathVertex
Vertex, eigen format.
Definition: CepsTypes.hpp:135
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
Definition: CepsTypes.hpp:178
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
A namespace for all utility methods.
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
Definition: CepsString.cpp:521
CepsVector< CepsString > cleanup(const CepsVector< CepsString > &vec)
Clean a vector of string, remove empty and " " string.
Definition: CepsString.cpp:647
CepsMathTensor toMathTensor(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathTensor.
Definition: CepsString.cpp:237
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
Definition: CepsString.hpp:409
CepsString getFilename(const CepsString &str)
Returns a substring corresponding to the string after the last '/' character. Example: "/home/someone...
Definition: CepsString.cpp:556
CepsString toKey(const CepsString &s)
Transform to key type a std::string, upper case and no spaces.
Definition: CepsString.cpp:157
CepsBool endsWith(const CepsString &s, const CepsString &comp)
Check if the string 'str' ends with 'comp'.
Definition: CepsString.cpp:363
CepsString join(const CepsVector< CepsString > &vec, const CepsChar &delimeter=' ')
Join multiple strings into one.
Definition: CepsString.cpp:63
CepsSet< CepsInt > toInts(const CepsString &s)
Cast CepsString to a set of CepsInt.
Definition: CepsString.cpp:284
CepsBool toBool(const CepsString &s)
Cast CepsString to CepsBool.
Definition: CepsString.cpp:186
CepsMap< CepsString, CepsVector< CepsString > > splitByKeyword(const CepsString &s, const CepsSet< CepsString > &tags)
Extract parameters in the CepsString given by tags. Builds a map of keywords and parameter words acco...
Definition: CepsString.cpp:384
CepsMathScalar toMathScalar(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathScalar same effect as ceps::toReal(vec[0])
Definition: CepsString.cpp:219
CepsSet< CepsUInt > toUInts(const CepsString &s)
Cast CepsString to a set of CepsUInt.
Definition: CepsString.cpp:310
CepsString substract(const CepsString &s, const CepsString &toErase)
Substract all occurences of another CepsString.
Definition: CepsString.cpp:95
void toKeyInPlace(CepsVector< CepsString > &vec)
Transform to key type a vector of std::string, upper case and no spaces.
Definition: CepsString.cpp:178
CepsBool startsWith(const CepsString &s, const CepsString &comp)
Check if the string 'str' starts with 'comp'.
Definition: CepsString.cpp:342
CepsArray< CepsMathScalar, n > readReals(std::istream &file, const CepsString &errorMessage="")
Reads n floating point numbers from an istream, aborts if conversion fails.
Definition: CepsString.hpp:481
CepsSet< CepsReal > toReals(const CepsString &s)
Cast CepsString to a set of CepsReal.
Definition: CepsString.cpp:207
CepsString toLower(const CepsString &s)
Switches all characters to lower case.
Definition: CepsString.cpp:134
CepsString readParams(const CepsVector< CepsString > &scope, const CepsString &tag, const CepsString &def="", const CepsUInt &pad=1)
Read parameters into a map.
Definition: CepsString.cpp:496
CepsBool startsWithOneOf(const CepsString &s, const CepsVector< CepsString > &comps)
Check if the string 'str' starts with one of 'comps'.
Definition: CepsString.cpp:353
CepsString removeSpaces(const CepsString &s)
Removes spaces and tabs.
Definition: CepsString.cpp:87
CepsReal3D readVertex(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
Definition: CepsString.cpp:693
CepsInt readInt(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
Definition: CepsString.cpp:677
CepsBool endsWithOneOf(const CepsString &s, const CepsVector< CepsString > &comps)
Check if the string 'str' ends with one of 'comps'.
Definition: CepsString.cpp:374
CepsString getExtension(const CepsString &str)
Returns the extension of a file, if any.
Definition: CepsString.cpp:580
CepsString removeDoubleSlashes(const CepsString &path)
Replaces double slashes in a string with a single slash. Used for clean paths.
Definition: CepsString.cpp:510
CepsVector< CepsString > splitAtNthDelimiter(const CepsString &s, CepsUInt n, CepsString delimiters=CepsString(" \t"))
Split a string a the n-th delimeter. This ignores the doubled delimiter (eg multiple spaces count as ...
Definition: CepsString.cpp:419
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
Definition: CepsString.cpp:38
CepsUInt toUInt(const CepsString &s)
Cast CepsString to CepsUInt.
Definition: CepsString.cpp:296
CepsBool isSameFile(const CepsString &f1, const CepsString &f2)
Tells if given paths refer to the same file.
Definition: CepsString.cpp:637
CepsInt toInt(const CepsString &s)
Cast CepsString to CepsInt.
Definition: CepsString.cpp:270
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
Definition: CepsString.cpp:124
CepsBool isNumber(const CepsString &s)
Check if the string contains only digit numbers.
Definition: CepsString.cpp:322
CepsMathVertex toMathVertex(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathVertex.
Definition: CepsString.cpp:227
CepsVector< CepsString > splitUntilNthDelimiter(const CepsString &s, const CepsUInt &n, CepsString delimiters=CepsString(" \t"))
Split a string for the first n delimeters.
Definition: CepsString.cpp:441
CepsString changeExtension(const CepsString &str, const CepsString &ext)
Change the extension of a file name (does not check if file exists).
Definition: CepsString.cpp:588
CepsString getBaseName(const CepsString &str)
Extracts the base of a file name, without path, nor extension. Ex: getBaseName("/path/to/myfile....
Definition: CepsString.cpp:563
CepsMathTensor readTensor(std::istream &file, const CepsString &errorMessage="")
Reads 9 floating point numbers from an istream, aborts if conversion fails advances the stream by 9 w...
Definition: CepsString.cpp:704
CepsBool isPathInOneWord(const CepsString &s)
Checks if given path is in one word (it may not exist yet)
Definition: CepsString.cpp:144
CepsString trim(const CepsString &s)
Removes trailing and preceeding spaces.
Definition: CepsString.cpp:78
CepsBool fileExists(const CepsString &fileName, const CepsString &directory)
Definition: CepsString.cpp:595
CepsReal toReal(const CepsString &s)
Cast CepsString to CepsReal.
Definition: CepsString.cpp:193
CepsReal readReal(std::istream &file, const CepsString &errorMessage="")
Reads a floating point number from an istream, aborts if conversion fails advances the stream by 1 wo...
Definition: CepsString.cpp:661