KaliVeda
Toolkit for HIC analysis
KVEnv.h
1 
4 #ifndef __KVENV_H
5 #define __KVENV_H
6 
7 #include "TEnv.h"
8 #include "TList.h"
9 #include "KVString.h"
10 
18 class KVEnv : public TEnv {
19 protected:
21 
22 public:
23 
24  KVEnv(const KVString& name = "");
25 
26  void CopyTable(TEnv& env);
27 
28  Int_t WriteFile(const char* fname, EEnvLevel level = kEnvAll) override;
29  void AddCommentLine(const Char_t* line);
30  void AddComments(const Char_t* comments);
31  void ClearComments();
32  void PrintComments();
33 
34  class Value {
35  const KVEnv& fEnv;
37  template<typename T>
39  {
40  return t;
41  }
42  template<typename T, typename... Ts>
43  KVString get_value_name(T t, Ts... args)
44  {
45  KVString vn(t);
46  vn += ".";
47  vn += get_value_name(args...);
48  return vn;
49  }
50  public:
51  template<typename... Ts>
52  Value(const KVEnv& e, Ts... args)
53  : fEnv(e)
54  {
55  value_name = get_value_name(args...);
56  }
57  template<typename ValueType>
58  ValueType Default(ValueType v = ValueType{}) const
59  {
60  return fEnv.GetValue(value_name, v);
61  }
62  Bool_t Defined() const
63  {
64  return fEnv.Defined(value_name);
65  }
66  };
67 
68  template<typename... Ts>
69  Value GetValueOf(Ts... args) const
70  {
94 
95  return Value(*this, args...);
96  }
97  Bool_t HasValue(const KVString& val) const
98  {
99  return Defined(val);
100  }
101  template<typename... Ts>
102  Bool_t HasValue(Ts... args) const
103  {
122  return Value(*this, args...).Defined();
123  }
124 
125 
126  ClassDefOverride(KVEnv, 1) //child class of TEnv to allow the writing of comments in the file
127 };
128 
129 #endif
int Int_t
#define e(i)
bool Bool_t
char Char_t
#define ClassDefOverride(name, id)
EEnvLevel
KVString get_value_name(T t, Ts... args)
Definition: KVEnv.h:43
Value(const KVEnv &e, Ts... args)
Definition: KVEnv.h:52
ValueType Default(ValueType v=ValueType{}) const
Definition: KVEnv.h:58
const KVEnv & fEnv
Definition: KVEnv.h:35
Bool_t Defined() const
Definition: KVEnv.h:62
KVString value_name
Definition: KVEnv.h:36
KVString get_value_name(T t)
Definition: KVEnv.h:38
Extension of TEnv to allow the writing of comments in the file.
Definition: KVEnv.h:18
void AddCommentLine(const Char_t *line)
Definition: KVEnv.cpp:70
Bool_t HasValue(const KVString &val) const
Definition: KVEnv.h:97
void PrintComments()
Definition: KVEnv.cpp:119
Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll) override
Definition: KVEnv.cpp:140
void AddComments(const Char_t *comments)
Definition: KVEnv.cpp:89
Value GetValueOf(Ts... args) const
Definition: KVEnv.h:69
void ClearComments()
Definition: KVEnv.cpp:108
TList fComments
Definition: KVEnv.h:20
KVEnv(const KVString &name="")
Definition: KVEnv.cpp:25
void CopyTable(TEnv &env)
Copy table of env to this.
Definition: KVEnv.cpp:48
Bool_t HasValue(Ts... args) const
Definition: KVEnv.h:102
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
virtual const char * GetValue(const char *name, const char *dflt) const
Bool_t Defined(const char *name) const
double T(double x)