KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVString.h
Go to the documentation of this file.
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 
72 class KVString : public TString {
73 
74 protected:
75 
76  mutable unique_ptr<TObjArray> kObjArr;
77  mutable Int_t fIterIndex;
78  mutable Bool_t fEndList;
79 
80 public:
81 
83  {
84  }
85  KVString(const Char_t* s): TString(s), kObjArr(nullptr), fIterIndex(-1), fEndList(kTRUE)
86  {
87  }
88  KVString(const TString& s): TString(s), kObjArr(nullptr), fIterIndex(-1), fEndList(kTRUE)
89  {
90  }
91  KVString(const KVString& s): TString((const TString&)s), kObjArr(nullptr), fIterIndex(-1), fEndList(kTRUE)
92  {
93  }
94  KVString(Double_t value, Double_t error);
95 
96  virtual ~ KVString() {}
97 
98 #ifdef __WITHOUT_TSTRING_TOKENIZE
99  TObjArray* Tokenize(const TString& delim) const;
100 #endif
101 #ifdef __WITH_KVSTRING_ISDIGIT
102  Bool_t IsDigit() const;
103 #endif
104 #ifdef __WITH_KVSTRING_ISFLOAT
105  Bool_t IsFloat() const;
106 #endif
107 #ifdef __WITH_KVSTRING_ATOI
108  Int_t Atoi() const;
109 #endif
110 #ifdef __WITH_KVSTRING_ATOF
111  Double_t Atof() const;
112 #endif
113 #ifdef __WITH_KVSTRING_REMOVE
114  KVString& Remove(TString::EStripType s, char c); // Like Strip() but changing string directly
115  KVString& Remove(Ssiz_t pos)
116  {
117  return (KVString&)(TString::Remove(pos));
118  }; // Remove pos to end of string
119  KVString& Remove(Ssiz_t pos, Ssiz_t n)
120  {
121  return (KVString&)(TString::Remove(pos, n));
122  }; // Remove n chars starting at pos
123 #endif
124  inline KVString& operator=(const KVString& s);
125  inline KVString& operator=(const char* s);
126  inline KVString& operator=(const TString& s);
127 
128  virtual KVString& Substitute(const Char_t c1, const Char_t c2);
129  virtual Int_t Sscanf(const Char_t* fmt, ...);
130 
131  virtual Bool_t Match(TString pattern);
132  void Begin(TString delim) const;
133  Bool_t End() const;
134  KVString Next(Bool_t strip_whitespace = kFALSE) const;
135  void RBegin(TString delim) const;
136  KVString RNext(Bool_t strip_whitespace = kFALSE) const;
137  Int_t GetNValues(TString delim) const;
138  std::vector<KVString> Vectorize(TString delim, Bool_t strip_whitespace = kFALSE);
139 
140 #ifdef __WITH_KVSTRING_ISWHITESPACE
141  Bool_t IsWhitespace() const;
142 #endif
143 #ifdef __WITH_KVSTRING_ITOA
144  Bool_t IsBin() const;
145  Bool_t IsOct() const;
146  Bool_t IsDec() const;
147  Bool_t IsInBaseN(Int_t base) const;
148 #endif
149  static KVString Itoa(Int_t value, Int_t base); // Converts int to string with respect to the base specified (2-36)
150  static KVString UItoa(UInt_t value, Int_t base);
151  static KVString LLtoa(Long64_t value, Int_t base);
152  static KVString ULLtoa(ULong64_t value, Int_t base);
153  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)
154 
157 
158  KVString& FindCommonCharacters(const TCollection*, const char bug = '*');
159  KVString& FindCommonTitleCharacters(const TCollection*, const char bug = '*');
160 
161  void RandomLetterSequence(Int_t length);
162 
163  void Capitalize();
164 
165  ClassDef(KVString, 1)//TString wrapper compatible with ROOT versions 3.10/02 onwards
166 };
167 
169 {
170  if (this != &s) {
171  Form("%s", s.Data());
172  }
173  return *this;
174 }
175 
177 {
178  Form("%s", s.Data());
179  return *this;
180 }
181 
182 inline KVString& KVString::operator=(const char* s)
183 {
184  Form("%s", s);
185  return *this;
186 }
187 #endif
int Int_t
unsigned int UInt_t
int Ssiz_t
char Char_t
bool Bool_t
double Double_t
const Bool_t kTRUE
#define ClassDef(name, id)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
virtual ~ KVString()
Definition: KVString.h:96
void Begin(TString delim) const
Definition: KVString.cpp:562
unique_ptr< TObjArray > kObjArr
used by Next() to iterate over list
Definition: KVString.h:76
void RBegin(TString delim) const
Definition: KVString.cpp:741
void RemoveAllExtraWhiteSpace()
Definition: KVString.cpp:1226
Bool_t End() const
Definition: KVString.cpp:625
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:675
virtual Int_t Sscanf(const Char_t *fmt,...)
Definition: KVString.cpp:320
static KVString ULLtoa(ULong64_t value, Int_t base)
Definition: KVString.cpp:1130
static KVString LLtoa(Long64_t value, Int_t base)
Definition: KVString.cpp:1091
Bool_t fEndList
used by Next() & End() to iterate over list
Definition: KVString.h:78
void RandomLetterSequence(Int_t length)
Definition: KVString.cpp:1409
KVString & operator=(const KVString &s)
Definition: KVString.h:168
std::vector< KVString > Vectorize(TString delim, Bool_t strip_whitespace=kFALSE)
Definition: KVString.cpp:882
KVString()
Definition: KVString.h:82
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:1280
static KVString BaseConvert(const KVString &s_in, Int_t base_in, Int_t base_out)
Definition: KVString.cpp:1165
static KVString UItoa(UInt_t value, Int_t base)
Definition: KVString.cpp:1054
virtual Bool_t Match(TString pattern)
Definition: KVString.cpp:494
Int_t GetNValues(TString delim) const
Definition: KVString.cpp:859
static KVString Itoa(Int_t value, Int_t base)
Definition: KVString.cpp:1011
KVString(const KVString &s)
Definition: KVString.h:91
KVString(const Char_t *s)
Definition: KVString.h:85
KVString RNext(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:814
Int_t fIterIndex
used by Next() to iterate over list
Definition: KVString.h:77
KVString & FindCommonTitleCharacters(const TCollection *, const char bug=' *')
Definition: KVString.cpp:1350
KVString StripAllExtraWhiteSpace() const
Definition: KVString.cpp:1248
void Capitalize()
Change first character of string from lower to upper case.
Definition: KVString.cpp:1427
KVString(const TString &s)
Definition: KVString.h:88
Bool_t IsDec() const
Int_t Atoi() const
Double_t Atof() const
Bool_t IsFloat() 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
const long double s
Definition: KVUnits.h:94