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