KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVNameValueList.h
1
3
4#ifndef __KVNAMEVALUELIST_H
5#define __KVNAMEVALUELIST_H
6
7#include "KVHashList.h"
8#include "TNamed.h"
9#include "TRegexp.h"
10#include "KVNamedParameter.h"
11class KVEnv;
12
116class KVNameValueList : public TNamed {
117protected:
120
121public:
123 KVNameValueList(std::initializer_list<KVNamedParameter>);
124 KVNameValueList(const Char_t* name, const Char_t* title = "");
126 virtual ~KVNameValueList();
128
129 class Iterator {
130 public:
131 typedef std::forward_iterator_tag iterator_category;
133 typedef std::ptrdiff_t difference_type;
136 private:
137 TIter fIter;// iterator over hash list
139 {
141 return reinterpret_cast<KVNamedParameter*>(*fIter);
142 }
143
144 public:
146 : fIter(static_cast<TIterator*>(nullptr))
147 {}
148 Iterator(const Iterator& other)
149 : fIter(other.fIter)
150 {}
152 : fIter(N->GetList())
153 {
154 fIter.Begin();
155 }
157 : fIter(N.GetList())
158 {
159 fIter.Begin();
160 }
162 {
164
165 return *(current());
166 }
167 Bool_t operator!= (const Iterator& it) const
168 {
170 return current() != it.current();
171 }
172 Bool_t operator== (const Iterator& it) const
173 {
175 return current() == it.current();
176 }
178 {
180 ++fIter;
181 return *this;
182 }
184 {
187 Iterator tmp(*this);
188 operator++();
189 return tmp;
190 }
192 {
194 if (this != &rhs) { // check self-assignment based on address of object
195 fIter = rhs.fIter;
196 }
197 return *this;
198 }
199 static Iterator End()
200 {
201 return Iterator();
202 }
203 virtual ~Iterator() {}
204
205 ClassDef(Iterator, 0) //Iterator for KVNameValueList
206 };
208 {
210 return Iterator(this);
211 }
212 Iterator end() const
213 {
215 return Iterator::End();
216 }
217
218 bool Set(const KVString&);
219 KVString Get() const;
220
221 KVHashList* GetList() const;
222
223 virtual void Clear(Option_t* opt = "");
224 virtual void ClearSelection(TRegexp&);
225 virtual void Print(Option_t* opt = "") const;
226 virtual void ls(Option_t* opt = "") const;
227 void SetOwner(Bool_t enable = kTRUE);
228 Bool_t IsOwner() const;
229
230 void Copy(TObject& nvl) const;
231 Int_t Compare(const TObject* nvl) const;
232
233 template<typename value_type>
234 void SetValue(const Char_t* name, value_type value)
235 {
240 par ? par->Set(name, value) : fList.Add(new KVNamedParameter(name, value));
241 }
242 void SetValue(const KVNamedParameter&);
243 void SetValue64bit(const Char_t* name, ULong64_t);
244 ULong64_t GetValue64bit(const Char_t* name) const;
245 Bool_t HasValue64bit(const Char_t* name) const;
246
247 template <typename value_type>
248 void SetValueAt(const Char_t* name, value_type value, Int_t idx)
249 {
256 if (par) {
257 par->Set(value);
258 if (fList.IndexOf(par) != idx) {
259 fList.GetCollection()->Remove(par);
260 fList.AddAt(par, idx);
261 }
262 }
263 else fList.AddAt(new KVNamedParameter(name, value), idx);
264 }
265
266 template <typename value_type>
267 void SetFirstValue(const Char_t* name, value_type value)
268 {
275 if (par) {
276 par->Set(value);
277 if (fList.First() != par) {
278 fList.GetCollection()->Remove(par);
279 fList.AddFirst(par);
280 }
281 }
283 }
284
285 template <typename value_type>
286 void SetLastValue(const Char_t* name, value_type value)
287 {
294 if (par) {
295 par->Set(value);
296 if (fList.Last() != par) {
297 fList.GetCollection()->Remove(par);
298 fList.AddLast(par);
299 }
300 }
302 }
303
304 template <typename value_type>
305 void IncrementValue(const Char_t* name, value_type value)
306 {
312 }
313
314 template <typename value_type>
315 Bool_t IsValue(const Char_t* name, value_type value) const
316 {
319 if (par) {
321 return (*par) == tmp;
322 }
323 return kFALSE;
324 }
325
326 KVNamedParameter* FindParameter(const Char_t* name) const;
328 void RemoveParameter(const Char_t* name);
329 Bool_t HasParameter(const Char_t* name) const;
330 template <typename value_type>
331 Bool_t HasParameter(const Char_t* name) const
332 {
334
336 return (p && p->Is<value_type>());
337 }
338 Bool_t HasIntParameter(const Char_t* name) const
339 {
346 return HasParameter<int>(name);
347 }
348 Bool_t HasBoolParameter(const Char_t* name) const
349 {
350 return HasParameter<bool>(name);
351 }
353 {
360 return HasParameter<double>(name);
361 }
363 {
364 return HasParameter<TString>(name);
365 }
376 Int_t GetNameIndex(const Char_t* name) const;
377 const Char_t* GetNameAt(Int_t idx) const;
378 Int_t GetNpar() const;
380 {
381 return GetNpar();
382 }
384 {
385 return GetNpar() == 0;
386 }
387
388 template <typename value_type>
389 value_type GetValue(const Char_t* name) const
390 {
394
396 return (par ? par->Get<value_type>() : KVNamedParameter::DefaultValue<value_type>());
397 }
398
399 Int_t GetIntValue(const Char_t* name) const
400 {
401 return GetValue<int>(name);
402 }
403 Bool_t GetBoolValue(const Char_t* name) const
404 {
405 return GetValue<bool>(name);
406 }
407 Double_t GetDoubleValue(const Char_t* name) const
408 {
409 return GetValue<double>(name);
410 }
411 const Char_t* GetStringValue(const Char_t* name) const
412 {
413 return GetValue<cstring>(name);
414 }
415 TString GetTStringValue(const Char_t* name) const;
416
417 template <typename value_type>
418 value_type GetValue(Int_t idx) const
419 {
423 KVNamedParameter* par = GetParameter(idx);
424 return (par ? par->Get<value_type>() : KVNamedParameter::DefaultValue<value_type>());
425 }
426
428 {
429 return GetValue<int>(idx);
430 }
432 {
433 return GetValue<bool>(idx);
434 }
436 {
437 return GetValue<double>(idx);
438 }
439 const Char_t* GetStringValue(Int_t idx) const
440 {
441 return GetValue<cstring>(idx);
442 }
443 TString GetTStringValue(Int_t idx) const;
444
445 virtual void ReadEnvFile(const Char_t* filename);
446 virtual KVEnv* ProduceEnvFile();
447 virtual void WriteEnvFile(const Char_t* filename);
448
449 void Sort(Bool_t order = kSortAscending)
450 {
453 fList.Sort(order);
454 }
455
457
458 void WriteClass(const Char_t* classname, const Char_t* classdesc, const Char_t* base_class = "");
459
460 void SetIgnoreBool(Bool_t ignore = kTRUE)
461 {
466 fIgnoreBool = ignore;
467 }
468 void SetFromEnv(TEnv* tenv, const TString& prefix = "");
469 void WriteToEnv(TEnv* tenv, const TString& prefix = "");
470 void Merge(const KVNameValueList&);
471 void AddValue(const KVNamedParameter& p);
472
473 ClassDef(KVNameValueList, 4) //A general-purpose list of parameters
474};
475#endif
int Int_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
const char Option_t
#define ClassDef(name, id)
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Extension of TEnv to allow the writing of comments in the file.
Definition KVEnv.h:17
Extended version of ROOT THashList.
Definition KVHashList.h:29
void Sort(Bool_t order=kSortAscending)
Definition KVHashList.h:44
std::forward_iterator_tag iterator_category
KVNamedParameter * pointer
Iterator(const Iterator &other)
KVNamedParameter & operator*() const
KVNamedParameter & reference
Iterator(const KVNameValueList *N)
Iterator(const KVNameValueList &N)
Bool_t operator==(const Iterator &it) const
Bool_t operator!=(const Iterator &it) const
Iterator & operator=(const Iterator &rhs)
KVNamedParameter * current() const
const Iterator & operator++()
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
virtual void Print(Option_t *opt="") const
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Iterator begin() const
const Char_t * GetStringValue(Int_t idx) const
virtual void ls(Option_t *opt="") const
Int_t GetIntValue(const Char_t *name) const
Double_t GetDoubleValue(const Char_t *name) const
Bool_t HasValue64bit(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
virtual ~KVNameValueList()
Destructor.
Bool_t fIgnoreBool
do not convert "yes", "false", "on", etc. in TEnv file to boolean
Bool_t IsOwner() const
Bool_t HasNumericParameter(const Char_t *name) const
void RemoveParameter(const Char_t *name)
Int_t Compare(const TObject *nvl) const
void SetValue64bit(const Char_t *name, ULong64_t)
void SetFromEnv(TEnv *tenv, const TString &prefix="")
void IncrementValue(const Char_t *name, value_type value)
virtual void Clear(Option_t *opt="")
const Char_t * GetNameAt(Int_t idx) const
Int_t GetNpar() const
return the number of stored parameters
Bool_t HasStringParameter(const Char_t *name) const
Bool_t IsEmpty() const
void SetFirstValue(const Char_t *name, value_type value)
virtual void ReadEnvFile(const Char_t *filename)
Bool_t IsValue(const Char_t *name, value_type value) const
Int_t GetEntries() const
void SetValueAt(const Char_t *name, value_type value, Int_t idx)
virtual void WriteEnvFile(const Char_t *filename)
Write all name-value pairs in this list as a TEnv format file.
Int_t GetNameIndex(const Char_t *name) const
void Merge(const KVNameValueList &)
Iterator end() const
KVNameValueList()
Default constructor.
KVNamedParameter * FindParameter(const Char_t *name) const
return the parameter object with the asking name
KVNameValueList operator+=(const KVNameValueList &nvl)
KVNameValueList & operator=(const KVNameValueList &)
KVHashList fList
list of KVNamedParameter objects
Bool_t HasIntParameter(const Char_t *name) const
void Sort(Bool_t order=kSortAscending)
value_type GetValue(Int_t idx) const
void SetOwner(Bool_t enable=kTRUE)
Bool_t GetBoolValue(Int_t idx) const
Double_t GetDoubleValue(Int_t idx) const
virtual KVEnv * ProduceEnvFile()
void WriteClass(const Char_t *classname, const Char_t *classdesc, const Char_t *base_class="")
Bool_t HasBoolParameter(const Char_t *name) const
Bool_t GetBoolValue(const Char_t *name) const
ULong64_t GetValue64bit(const Char_t *name) const
KVString Get() const
value_type GetValue(const Char_t *name) const
Int_t GetIntValue(Int_t idx) const
const Char_t * GetStringValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
void SetLastValue(const Char_t *name, value_type value)
bool Set(const KVString &)
Bool_t HasDoubleParameter(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
void AddValue(const KVNamedParameter &p)
void SetIgnoreBool(Bool_t ignore=kTRUE)
KVHashList * GetList() const
TString GetTStringValue(const Char_t *name) const
void Copy(TObject &nvl) const
virtual void ClearSelection(TRegexp &)
void WriteToEnv(TEnv *tenv, const TString &prefix="")
A generic named parameter storing values of different types.
void Set(const char *, const char *)
void Add(const KVNamedParameter &p)
virtual void AddLast(TObject *obj)
TSeqCollection * GetCollection() const
virtual TObject * Last() const
virtual TObject * First() const
virtual void Add(TObject *obj)
virtual void AddAt(TObject *obj, Int_t idx)
virtual void AddFirst(TObject *obj)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
virtual TObject * Remove(TObject *obj)=0
TIter & Begin()
virtual Int_t IndexOf(const TObject *obj) const
Bool_t IsFloat() const
unsigned long long ULong64_t