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