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  KVEnv(TEnv&);
26 
27  void CopyTable(TEnv& env);
28 
29  Int_t WriteFile(const char* fname, EEnvLevel level = kEnvAll) override;
30  void AddCommentLine(const Char_t* line);
31  void AddComments(const Char_t* comments);
32  void ClearComments();
33  void PrintComments();
34 
35  class Value {
36  const KVEnv& fEnv;
38  template<typename T>
40  {
41  return t;
42  }
43  template<typename T, typename... Ts>
44  KVString get_value_name(T t, Ts... args)
45  {
46  KVString vn(t);
47  vn += ".";
48  vn += get_value_name(args...);
49  return vn;
50  }
51  public:
52  template<typename... Ts>
53  Value(const KVEnv& e, Ts... args)
54  : fEnv(e)
55  {
56  value_name = get_value_name(args...);
57  }
58  template<typename ValueType>
59  ValueType Default(ValueType v = ValueType{}) const
60  {
61  return fEnv.GetValue(value_name, v);
62  }
63  Bool_t Defined() const
64  {
65  return fEnv.Defined(value_name);
66  }
67  };
68 
69  template<typename... Ts>
70  Value GetValueOf(Ts... args) const
71  {
95 
96  return Value(*this, args...);
97  }
98  Bool_t HasValue(const KVString& val) const
99  {
100  return Defined(val);
101  }
102  template<typename... Ts>
103  Bool_t HasValue(Ts... args) const
104  {
123  return Value(*this, args...).Defined();
124  }
125 
126 
127  ClassDefOverride(KVEnv, 1) //child class of TEnv to allow the writing of comments in the file
128 };
129 
130 #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:44
Value(const KVEnv &e, Ts... args)
Definition: KVEnv.h:53
ValueType Default(ValueType v=ValueType{}) const
Definition: KVEnv.h:59
const KVEnv & fEnv
Definition: KVEnv.h:36
Bool_t Defined() const
Definition: KVEnv.h:63
KVString value_name
Definition: KVEnv.h:37
KVString get_value_name(T t)
Definition: KVEnv.h:39
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:87
Bool_t HasValue(const KVString &val) const
Definition: KVEnv.h:98
void PrintComments()
Definition: KVEnv.cpp:136
Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll) override
Definition: KVEnv.cpp:157
void AddComments(const Char_t *comments)
Definition: KVEnv.cpp:106
Value GetValueOf(Ts... args) const
Definition: KVEnv.h:70
void ClearComments()
Definition: KVEnv.cpp:125
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:65
Bool_t HasValue(Ts... args) const
Definition: KVEnv.h:103
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)