Analysis  version 7.0 - august 2014
StringTools.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file StringTools.hh
3  *
4  * Fichier de déclaration de fonctions diverses travaillant sur les
5  * chaînes de caractères.
6  *
7  * mise à jour: 15 septembre 2007
8  */
9 //======================================================================
10 
11 #ifndef EVENT_STRING_TOOLS_HH
12 #define EVENT_STRING_TOOLS_HH
13 
14 #include "EventCommon.hh"
15 #include "RPointerList.hh"
16 #include "RString.hh"
17 #include "GNamed.hh"
18 
19 //----------------------------------------------------------------------
20 // Lecture d'une chaîne dans un fichier avec prise en compte des commentaires
21 
22 string read_string ( FILE *fptr, Int_t &error, const string &line_com = "//", const bool skip_empty = true, const UInt_t maxlen = 4096 );
23 string read_string ( istream &is, Int_t &error, const string &line_com = "//", const bool skip_empty = true );
24 
25 //----------------------------------------------------------------------
26 
27 // test des nom d'objets
28 bool IsValidName ( const string &name );
29 string ValidName ( const string &name );
30 string ExportName ( const string &name );
31 
32 string FileExt ( const string &name );
33 string FileBaseName ( const string &name );
34 string FileDirName ( const string &name );
35 string SetFileExt ( const string &name, const string &ext );
36 
37 
38 //----------------------------------------------------------------------
39 
40 /*! Patron de fonction qui crée une chaîne de caractère contenant les
41  * noms des éléments d'une liste de pointeurs considérés comme des pointeurs
42  * sur des objets de la classe T (attention, il s'agit d'un forçage de
43  * type direct).
44  * La classe T doit définir une fonction membre GetName(), ce qui est le
45  * cas des classes qui hérite de GNamed.
46  * \param list liste de pointeurs
47  * \param sep chaîne de séparation des noms
48  */
49 template <class T> string PtrListNames ( const RPointerList &list, const string sep = " " )
50 {
51  string result = "";
52  RPointerListIter iter = list.Begin();
53 
54  if (iter != list.Null())
55  {
56  T *ptr = (T *) (iter->GetPointer());
57  result = ptr->GNamed::GetName();
58 
59  ++iter;
60  while (iter != list.Null())
61  {
62  ptr = (T *) (iter->GetPointer());
63 
64  result += sep + ptr->GNamed::GetName();
65  ++iter;
66  }
67  }
68 
69  return (result);
70 }
71 
72 //======================================================================
73 #endif
74 
string FileBaseName(const string &name)
Definition: StringTools.cpp:333
string SetFileExt(const string &name, const string &ext)
Definition: StringTools.cpp:366
string PtrListNames(const RPointerList &list, const string sep=" ")
Definition: StringTools.hh:49
string FileExt(const string &name)
Definition: StringTools.cpp:314
string read_string(FILE *fptr, Int_t &error, const string &line_com, const bool skip_empty, const UInt_t maxlen)
Definition: StringTools.cpp:32
bool IsValidName(const string &name)
Definition: StringTools.cpp:185
string ExportName(const string &name)
Definition: StringTools.cpp:278
string ValidName(const string &name)
Definition: StringTools.cpp:231
string FileDirName(const string &name)
Definition: StringTools.cpp:351