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  const Char_t* GetSQLType() const;
202  void Add(const KVNamedParameter& p);
203 
204  ClassDefOverride(KVNamedParameter, 1) //A generic parameter with a name and a value
205 };
206 
207 template<> inline int KVNamedParameter::Get<int>() const
208 {
209  return GetInt();
210 }
211 template<> inline double KVNamedParameter::Get<double>() const
212 {
213  return GetDouble();
214 }
215 template<> inline bool KVNamedParameter::Get<bool>() const
216 {
217  return GetBool();
218 }
219 template<> inline KVString KVNamedParameter::Get<KVString>() const
220 {
221  return GetTString();
222 }
223 template<> inline TString KVNamedParameter::Get<TString>() const
224 {
225  return GetTString();
226 }
227 template<> inline cstring KVNamedParameter::Get<cstring>() const
228 {
229  return GetString();
230 }
231 template<> inline std::string KVNamedParameter::Get<std::string>() const
232 {
233  return std::string(GetString());
234 }
235 template<> inline int KVNamedParameter::DefaultValue<int>()
236 {
237  return -1;
238 }
239 template<> inline double KVNamedParameter::DefaultValue<double>()
240 {
241  return -1.0;
242 }
243 template<> inline bool KVNamedParameter::DefaultValue<bool>()
244 {
245  return false;
246 }
247 template<> inline TString KVNamedParameter::DefaultValue<TString>()
248 {
249  return "-1";
250 }
251 template<> inline KVString KVNamedParameter::DefaultValue<KVString>()
252 {
253  return "-1";
254 }
255 template<> inline cstring KVNamedParameter::DefaultValue<cstring>()
256 {
257  return "-1";
258 }
259 template<> inline std::string KVNamedParameter::DefaultValue<std::string>()
260 {
261  return "-1";
262 }
263 #ifndef __CINT__
264 template<> struct KVNamedParameter::typecode<int> {
265  static const int VALUE = KVNamedParameter::kIsInt;
266 };
267 template<> struct KVNamedParameter::typecode<double> {
268  static const int VALUE = KVNamedParameter::kIsDouble;
269 };
270 template<> struct KVNamedParameter::typecode<bool> {
271  static const int VALUE = KVNamedParameter::kIsBool;
272 };
273 template<> struct KVNamedParameter::typecode<std::string> {
274  static const int VALUE = KVNamedParameter::kIsString;
275 };
276 template<> struct KVNamedParameter::typecode<cstring> {
277  static const int VALUE = KVNamedParameter::kIsString;
278 };
280  static const int VALUE = KVNamedParameter::kIsString;
281 };
283  static const int VALUE = KVNamedParameter::kIsString;
284 };
285 #endif
286 template <typename T>
288 {
289  return GetType() == typecode<T>::VALUE;
290 }
291 #endif
292 
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
const Char_t * GetSQLType() 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
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