KaliVeda
Toolkit for HIC analysis
KVString.h
1 
3 #ifndef __KVSTRING_H
4 #define __KVSTRING_H
5 
6 #include "TString.h"
7 #include "KVConfig.h"
8 #include "RVersion.h"
9 
10 #include <TObjArray.h>
11 
12 /*
13 The following macro can be used in cases where Tokenize is used
14 to split a string into different integer elements and we want to store
15 the integers in Int_t variables. This macro is backwards compatible.
16 */
17 #define KV__TOBJSTRING_TO_INT(arr,index,var) \
18  Int_t var; \
19  { \
20  KVString _temp_string_ = ((TObjString *) arr->At(index))->String(); \
21  if(_temp_string_.IsDigit()) var = _temp_string_.Atoi(); else var = 0; \
22  }
23 
73 class KVString : public TString {
74 
75 protected:
76 
77  mutable std::unique_ptr<TObjArray> kObjArr;
78  mutable Int_t fIterIndex;
79  mutable Bool_t fEndList;
80 
81 public:
82 
84  {
85  }
86  KVString(const Char_t* s): TString(s), kObjArr(nullptr), fIterIndex(-1), fEndList(kTRUE)
87  {
88  }
89  KVString(const TString& s): TString(s), kObjArr(nullptr), fIterIndex(-1), fEndList(kTRUE)
90  {
91  }
92  KVString(const KVString& s): TString((const TString&)s), kObjArr(nullptr), fIterIndex(-1), fEndList(kTRUE)
93  {
94  }
95  KVString(Double_t value, Double_t error);
96 
97  virtual ~ KVString() {}
98 
99 #ifdef __WITHOUT_TSTRING_TOKENIZE
100  TObjArray* Tokenize(const TString& delim) const;
101 #endif
102 #ifdef __WITH_KVSTRING_ISDIGIT
103  Bool_t IsDigit() const;
104 #endif
105 #ifdef __WITH_KVSTRING_ISFLOAT
106  Bool_t IsFloat() const;
107 #endif
108 #ifdef __WITH_KVSTRING_ATOI
109  Int_t Atoi() const;
110 #endif
111 #ifdef __WITH_KVSTRING_ATOF
112  Double_t Atof() const;
113 #endif
114 #ifdef __WITH_KVSTRING_REMOVE
115  KVString& Remove(TString::EStripType s, char c); // Like Strip() but changing string directly
116  KVString& Remove(Ssiz_t pos)
117  {
118  return (KVString&)(TString::Remove(pos));
119  }; // Remove pos to end of string
120  KVString& Remove(Ssiz_t pos, Ssiz_t n)
121  {
122  return (KVString&)(TString::Remove(pos, n));
123  }; // Remove n chars starting at pos
124 #endif
125  inline KVString& operator=(const KVString& s);
126  inline KVString& operator=(const char* s);
127  inline KVString& operator=(const TString& s);
128 
130  operator const char* () const
131  {
132  return Data();
133  }
134 
135  virtual KVString& Substitute(const Char_t c1, const Char_t c2);
136  virtual Int_t Sscanf(const Char_t* fmt, ...);
137 
138  virtual Bool_t Match(TString pattern);
139  void Begin(TString delim) const;
140  Bool_t End() const;
141  KVString Next(Bool_t strip_whitespace = kFALSE) const;
142  void RBegin(TString delim) const;
143  KVString RNext(Bool_t strip_whitespace = kFALSE) const;
144  Int_t GetNValues(TString delim) const;
145  std::vector<KVString> Vectorize(TString delim, Bool_t strip_whitespace = kFALSE);
146 
147 #ifdef __WITH_KVSTRING_ISWHITESPACE
148  Bool_t IsWhitespace() const;
149 #endif
150 #ifdef __WITH_KVSTRING_ITOA
151  Bool_t IsBin() const;
152  Bool_t IsOct() const;
153  Bool_t IsDec() const;
154  Bool_t IsInBaseN(Int_t base) const;
155 #endif
156  static KVString Itoa(Int_t value, Int_t base); // Converts int to string with respect to the base specified (2-36)
157  static KVString UItoa(UInt_t value, Int_t base);
158  static KVString LLtoa(Long64_t value, Int_t base);
159  static KVString ULLtoa(ULong64_t value, Int_t base);
160  static KVString BaseConvert(const KVString& s_in, Int_t base_in, Int_t base_out); // Converts string from base base_in to base base_out (supported bases 2-36)
161 
164 
165  KVString& FindCommonCharacters(const TCollection*, const char bug = '*');
166  KVString& FindCommonTitleCharacters(const TCollection*, const char bug = '*');
167 
168  void RandomLetterSequence(Int_t length);
169 
170  void Capitalize();
171 
172  ClassDef(KVString, 1)//TString wrapper compatible with ROOT versions 3.10/02 onwards
173 };
174 
176 {
177  if (this != &s) {
178  Form("%s", s.Data());
179  }
180  return *this;
181 }
182 
184 {
185  Form("%s", s.Data());
186  return *this;
187 }
188 
189 inline KVString& KVString::operator=(const char* s)
190 {
191  Form("%s", s);
192  return *this;
193 }
194 #endif
int Int_t
unsigned int UInt_t
bool Bool_t
int Ssiz_t
char Char_t
double Double_t
constexpr Bool_t kTRUE
#define ClassDef(name, id)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
virtual ~ KVString()
Definition: KVString.h:97
void Begin(TString delim) const
Definition: KVString.cpp:565
std::unique_ptr< TObjArray > kObjArr
used by Next() to iterate over list
Definition: KVString.h:77
void RBegin(TString delim) const
Definition: KVString.cpp:768
void RemoveAllExtraWhiteSpace()
Definition: KVString.cpp:1253
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
virtual Int_t Sscanf(const Char_t *fmt,...)
Definition: KVString.cpp:320
static KVString ULLtoa(ULong64_t value, Int_t base)
Definition: KVString.cpp:1157
static KVString LLtoa(Long64_t value, Int_t base)
Definition: KVString.cpp:1118
Bool_t fEndList
used by Next() & End() to iterate over list
Definition: KVString.h:79
void RandomLetterSequence(Int_t length)
Definition: KVString.cpp:1436
KVString & operator=(const KVString &s)
Definition: KVString.h:175
std::vector< KVString > Vectorize(TString delim, Bool_t strip_whitespace=kFALSE)
Definition: KVString.cpp:909
KVString()
Definition: KVString.h:83
virtual KVString & Substitute(const Char_t c1, const Char_t c2)
Replace every occurence of 'c1' with 'c2'.
Definition: KVString.cpp:275
KVString & FindCommonCharacters(const TCollection *, const char bug=' *')
Definition: KVString.cpp:1307
static KVString BaseConvert(const KVString &s_in, Int_t base_in, Int_t base_out)
Definition: KVString.cpp:1192
static KVString UItoa(UInt_t value, Int_t base)
Definition: KVString.cpp:1081
virtual Bool_t Match(TString pattern)
Definition: KVString.cpp:494
Int_t GetNValues(TString delim) const
Definition: KVString.cpp:886
static KVString Itoa(Int_t value, Int_t base)
Definition: KVString.cpp:1038
KVString(const KVString &s)
Definition: KVString.h:92
KVString(const Char_t *s)
Definition: KVString.h:86
KVString RNext(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:841
Int_t fIterIndex
used by Next() to iterate over list
Definition: KVString.h:78
KVString & FindCommonTitleCharacters(const TCollection *, const char bug=' *')
Definition: KVString.cpp:1377
KVString StripAllExtraWhiteSpace() const
Definition: KVString.cpp:1275
void Capitalize()
Change first character of string from lower to upper case.
Definition: KVString.cpp:1454
KVString(const TString &s)
Definition: KVString.h:89
Bool_t IsDec() const
Int_t Atoi() const
Double_t Atof() const
Bool_t IsFloat() const
const char * Data() const
Bool_t IsDigit() const
Bool_t IsOct() const
TObjArray * Tokenize(const TString &delim) const
Bool_t IsBin() const
Bool_t IsInBaseN(Int_t base) const
Bool_t IsWhitespace() const
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
long long Long64_t
unsigned long long ULong64_t