KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVString.h
1
2
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/*
13The following macro can be used in cases where Tokenize is used
14to split a string into different integer elements and we want to store
15the 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
73class KVString : public TString {
74
75protected:
76
77 mutable std::unique_ptr<TObjArray> kObjArr;
80
81public:
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
117 {
118 return (KVString&)(TString::Remove(pos));
119 }; // Remove pos to end of string
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
129 virtual KVString& Substitute(const Char_t c1, const Char_t c2);
130 virtual Int_t Sscanf(const Char_t* fmt, ...);
131
132 virtual Bool_t Match(TString pattern);
133 void Begin(TString delim) const;
134 Bool_t End() const;
135 KVString Next(Bool_t strip_whitespace = kFALSE) const;
136 void RBegin(TString delim) const;
137 KVString RNext(Bool_t strip_whitespace = kFALSE) const;
138 Int_t GetNValues(TString delim) const;
139 std::vector<KVString> Vectorize(TString delim, Bool_t strip_whitespace = kFALSE);
140
141#ifdef __WITH_KVSTRING_ISWHITESPACE
142 Bool_t IsWhitespace() const;
143#endif
144#ifdef __WITH_KVSTRING_ITOA
145 Bool_t IsBin() const;
146 Bool_t IsOct() const;
147 Bool_t IsDec() const;
148 Bool_t IsInBaseN(Int_t base) const;
149#endif
150 static KVString Itoa(Int_t value, Int_t base); // Converts int to string with respect to the base specified (2-36)
151 static KVString UItoa(UInt_t value, Int_t base);
152 static KVString LLtoa(Long64_t value, Int_t base);
153 static KVString ULLtoa(ULong64_t value, Int_t base);
154 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)
155
158
159 KVString& FindCommonCharacters(const TCollection*, const char bug = '*');
160 KVString& FindCommonTitleCharacters(const TCollection*, const char bug = '*');
161
162 void RandomLetterSequence(Int_t length);
163
164 void Capitalize();
165
166 ClassDef(KVString, 1)//TString wrapper compatible with ROOT versions 3.10/02 onwards
167};
168
170{
171 if (this != &s) {
172 Form("%s", s.Data());
173 }
174 return *this;
175}
176
178{
179 Form("%s", s.Data());
180 return *this;
181}
182
183inline KVString& KVString::operator=(const char* s)
184{
185 Form("%s", s);
186 return *this;
187}
188#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
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()
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)
static KVString LLtoa(Long64_t value, Int_t base)
Bool_t fEndList
used by Next() & End() to iterate over list
Definition KVString.h:79
void RandomLetterSequence(Int_t length)
KVString & operator=(const KVString &s)
Definition KVString.h:169
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=' *')
static KVString BaseConvert(const KVString &s_in, Int_t base_in, Int_t base_out)
static KVString UItoa(UInt_t value, Int_t base)
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)
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=' *')
KVString StripAllExtraWhiteSpace() const
void Capitalize()
Change first character of string from lower to upper case.
KVString(const TString &s)
Definition KVString.h:89
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