KaliVeda
Toolkit for HIC analysis
KVNamedParameter.h
1 
4 #ifndef __KVNAMEDPARAMETER_H
5 #define __KVNAMEDPARAMETER_H
6 
7 #include "TNamed.h"
8 #include "TEnv.h"
9 #include "KVString.h"
10 
11 typedef const char* cstring;
12 
90 class KVNamedParameter : public TNamed {
91 
92  friend class KVNameValueList;
93 
94  enum {
95  kIsString = BIT(14),
96  kIsDouble = BIT(15),
97  kIsInt = BIT(16),
98  kIsBool = BIT(17)
99  };
100  template <typename T>
101  struct typecode {};
102 
103  enum {
104  kBitMask = 0x0003c000
105  };
106  void ResetBits()
107  {
109  }
110 
111  Int_t GetType() const
112  {
114  return TestBits(kBitMask);
115  }
116 
117  void SetType(UInt_t f)
118  {
119  ResetBits();
120  SetBit(f);
121  }
122 
123 protected:
125 
126 public:
128  KVNamedParameter(const char*);
129  KVNamedParameter(const char*, const char*);
130  KVNamedParameter(const char*, const std::string&);
131  KVNamedParameter(const char*, Double_t);
132  KVNamedParameter(const char*, Int_t);
133  KVNamedParameter(const char*, Bool_t);
134  KVNamedParameter(const char*, const KVNamedParameter&);
135  virtual ~KVNamedParameter();
136 
137  void Set(const char*, const char*);
138  void Set(const char*, const std::string&);
139  void Set(const char*, Double_t);
140  void Set(const char*, Int_t);
141  void Set(const char*, Bool_t);
142  void Set(const char*, const KVNamedParameter&);
143  void Set(const char*);
144  void Set(const std::string&);
145  void Set(Double_t);
146  void Set(Int_t);
147  void Set(Bool_t);
149  void Set(TEnv*, const TString& p = "");
150 
151  const Char_t* GetString() const;
152  TString GetTString() const;
153  Double_t GetDouble() const;
154  Int_t GetInt() const;
155  Bool_t GetBool() const;
156 
157  template <typename T>
158  T Get() const
159  {
161  T a;
162  a.very_unlikely_method_name();
163  }
164  template <typename T>
165  static T DefaultValue();
166  void Clear(Option_t* = "") override;
167 
168  template <typename T>
169  Bool_t Is() const;
170  Bool_t IsString() const
171  {
172  return GetType() == kIsString;
173  }
174  Bool_t IsDouble() const
175  {
176  return GetType() == kIsDouble;
177  }
178  Bool_t IsInt() const
179  {
180  return GetType() == kIsInt;
181  }
182  Bool_t IsBool() const
183  {
184  return GetType() == kIsBool;
185  }
186  Bool_t IsNumber() const
187  {
188  return (IsDouble() || IsInt());
189  }
190 
191  Bool_t IsEqual(const TObject* obj) const override;
192  Bool_t operator== (const KVNamedParameter&) const;
193  Bool_t HasSameValueAs(const KVNamedParameter&) const;
194  void Print(Option_t* opt = "") const override;
195  void ls(Option_t* opt = "") const override;
196  TString List(Option_t* opt = "") const;
197 
198  Int_t Compare(const TObject* obj) const override;
199  void WriteToEnv(TEnv*, const TString& p = "");
200 
201  TString GetSQLType() const;
202  TString AsSQLSelection() const;
203 
204  void Add(const KVNamedParameter& p);
205 
206  ClassDefOverride(KVNamedParameter, 1) //A generic parameter with a name and a value
207 };
208 
209 template<> inline int KVNamedParameter::Get<int>() const
210 {
211  return GetInt();
212 }
213 template<> inline double KVNamedParameter::Get<double>() const
214 {
215  return GetDouble();
216 }
217 template<> inline bool KVNamedParameter::Get<bool>() const
218 {
219  return GetBool();
220 }
221 template<> inline KVString KVNamedParameter::Get<KVString>() const
222 {
223  return GetTString();
224 }
225 template<> inline TString KVNamedParameter::Get<TString>() const
226 {
227  return GetTString();
228 }
229 template<> inline cstring KVNamedParameter::Get<cstring>() const
230 {
231  return GetString();
232 }
233 template<> inline std::string KVNamedParameter::Get<std::string>() const
234 {
235  return std::string(GetString());
236 }
237 template<> inline int KVNamedParameter::DefaultValue<int>()
238 {
239  return -1;
240 }
241 template<> inline double KVNamedParameter::DefaultValue<double>()
242 {
243  return -1.0;
244 }
245 template<> inline bool KVNamedParameter::DefaultValue<bool>()
246 {
247  return false;
248 }
249 template<> inline TString KVNamedParameter::DefaultValue<TString>()
250 {
251  return "-1";
252 }
253 template<> inline KVString KVNamedParameter::DefaultValue<KVString>()
254 {
255  return "-1";
256 }
257 template<> inline cstring KVNamedParameter::DefaultValue<cstring>()
258 {
259  return "-1";
260 }
261 template<> inline std::string KVNamedParameter::DefaultValue<std::string>()
262 {
263  return "-1";
264 }
265 #ifndef __CINT__
266 template<> struct KVNamedParameter::typecode<int> {
267  static const int VALUE = KVNamedParameter::kIsInt;
268 };
269 template<> struct KVNamedParameter::typecode<double> {
270  static const int VALUE = KVNamedParameter::kIsDouble;
271 };
272 template<> struct KVNamedParameter::typecode<bool> {
273  static const int VALUE = KVNamedParameter::kIsBool;
274 };
275 template<> struct KVNamedParameter::typecode<std::string> {
276  static const int VALUE = KVNamedParameter::kIsString;
277 };
278 template<> struct KVNamedParameter::typecode<cstring> {
279  static const int VALUE = KVNamedParameter::kIsString;
280 };
282  static const int VALUE = KVNamedParameter::kIsString;
283 };
285  static const int VALUE = KVNamedParameter::kIsString;
286 };
287 #endif
288 template <typename T>
290 {
291  return GetType() == typecode<T>::VALUE;
292 }
293 #endif
294 
int Int_t
unsigned int UInt_t
#define f(i)
bool Bool_t
char Char_t
double Double_t
const char Option_t
#define BIT(n)
#define ClassDefOverride(name, id)
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
A generic named parameter storing values of different types.
Int_t GetType() const
Bool_t HasSameValueAs(const KVNamedParameter &) const
Bool_t IsDouble() const
const Char_t * GetString() const
void SetType(UInt_t f)
KVNamedParameter()
Default constructor.
void Set(const char *, const char *)
Int_t GetInt() const
Bool_t IsInt() const
Bool_t IsEqual(const TObject *obj) const override
void Print(Option_t *opt="") const override
Bool_t IsBool() const
static T DefaultValue()
void Add(const KVNamedParameter &p)
Bool_t operator==(const KVNamedParameter &) const
Bool_t IsString() const
Double_t GetDouble() const
void WriteToEnv(TEnv *, const TString &p="")
Write parameter in TEnv, using optional prefix p as "p.[name]".
Double_t fNumber
used to store numerical (integer or floating-point) values
TString GetTString() const
TString List(Option_t *opt="") const
Bool_t IsNumber() const
Bool_t Is() const
TString GetSQLType() const
TString AsSQLSelection() const
Int_t Compare(const TObject *obj) const override
Compares numerical parameters for sorting lists (such as KVNameValueList)
virtual ~KVNamedParameter()
Destructor.
Bool_t GetBool() const
void Clear(Option_t *="") override
Removes the name and any assigned value.
void ls(Option_t *opt="") const override
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void SetBit(UInt_t f)
Int_t TestBits(UInt_t f) const
void ResetBit(UInt_t f)
double T(double x)
TArc a