KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
List of all members | Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Types | Private Member Functions | Friends | List of all members
KVNamedParameter Class Reference

A generic named parameter storing values of different types.

The four different types which are handled are: int, double, bool, TString:

Setting and retrieving parameter values

KVNamedParameter a("a", 12.34);
a.Is<double>(); // => true
a.IsInt(); // => false
a.IsNumber(); // => true
KVNamedParameter b("b", true);
b.Is<bool>(); // => true
b.Is<TString>(); // => false
#define b(i)
A generic named parameter storing values of different types.
auto * a

The same parameter can be reused to store a value with a different type:

b.Set("hello");
b.IsBool(); // => false
b.IsString(); // => true
b.Is<std::string>(); // => true

To retrieve the value of the parameter, its type must be given. This need not be the original type of the parameter, some common sense transformations are allowed:

b.GetString(); => (const char*) "hello"
b.Get<std::string>(); => (std::string) "hello"
b.Get<int>() => (int) 0
a.Get<double>(); => (double) 12.34
a.GetString(); => (const char*) "12.34"
a.GetInt(); => (int) 12
b.Set("12.34");
b.GetDouble(); => (double) 12.34
b.Get<int>() => (int) 12
double

Comparing parameters

Two types of comparison are possible. The == operator or member function IsEqual() test for strict equality between two parameters, i.e. they must have the same type, value, and name:

KVNamedParameter a{"A",12}, b{"A",12};
cout << (a==b) << endl; => (bool) true
b.SetName("B");
cout << b.IsEqual(&a) << endl; => (bool) false

On the other hand, HasTheSameValueAs() returns true as long as both parameters have the same type and value:

cout << b.HasTheSameValueAs(a) << endl; => (bool) true

Miscellaneous

The methods WriteToEnv(TEnv*, const TString &) and Set(TEnv*, const TString &) can be used to read/write parameter lists from/to ROOT resource files (.rootrc-style files).

Add(const KVNamedParameter &) will sum the values of two numerical parameters or concatenate two string parameters with a separating comma.

Definition at line 89 of file KVNamedParameter.h.

Classes

struct  typecode
 
struct  typecode< bool >
 
struct  typecode< cstring >
 
struct  typecode< double >
 
struct  typecode< int >
 
struct  typecode< KVString >
 
struct  typecode< std::string >
 
struct  typecode< TString >
 

Public Member Functions

 KVNamedParameter ()
 Default constructor. More...
 
 KVNamedParameter (const char *)
 
 KVNamedParameter (const char *, Bool_t)
 
 KVNamedParameter (const char *, const char *)
 
 KVNamedParameter (const char *, const KVNamedParameter &)
 Create parameter with given name "nom", and the type & value of "p". More...
 
 KVNamedParameter (const char *, Double_t)
 
 KVNamedParameter (const char *, Int_t)
 
virtual ~KVNamedParameter ()
 Destructor. More...
 
void Add (const KVNamedParameter &p)
 
virtual void Clear (Option_t *="")
 Removes the name and any assigned value. More...
 
Int_t Compare (const TObject *obj) const
 Compares numerical parameters for sorting lists (such as KVNameValueList) More...
 
template<typename T >
T Get () const
 
template<>
int Get () const
 
template<>
double Get () const
 
template<>
bool Get () const
 
template<>
KVString Get () const
 
template<>
TString Get () const
 
template<>
cstring Get () const
 
Bool_t GetBool () const
 
Double_t GetDouble () const
 
Int_t GetInt () const
 
const Char_tGetSQLType () const
 
const Char_tGetString () const
 
TString GetTString () const
 
Bool_t HasSameValueAs (const KVNamedParameter &) const
 
template<typename T >
Bool_t Is () const
 
Bool_t IsBool () const
 
Bool_t IsDouble () const
 
Bool_t IsEqual (const TObject *obj) const
 
Bool_t IsInt () const
 
Bool_t IsNumber () const
 
Bool_t IsString () const
 
virtual void ls (Option_t *opt="") const
 
Bool_t operator== (const KVNamedParameter &) const
 
virtual void Print (Option_t *opt="") const
 
void Set (Bool_t)
 
void Set (const char *)
 
void Set (const char *, Bool_t)
 
void Set (const char *, const char *)
 
void Set (const char *, const KVNamedParameter &)
 Set parameter name "nom" with the type & value of "p". More...
 
void Set (const char *, Double_t)
 
void Set (const char *, Int_t)
 
void Set (Double_t)
 
void Set (Int_t)
 
void Set (TEnv *, const TString &p="")
 void Set(const KVNamedParameter&); More...
 
void WriteToEnv (TEnv *, const TString &p="")
 Write parameter in TEnv, using optional prefix p as "p.[name]". More...
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 
virtual TObjectClone (const char *newname="") const
 
virtual void Copy (TObject &named) const
 
virtual void FillBuffer (char *&buffer)
 
virtual const char * GetName () const
 
virtual const char * GetTitle () const
 
virtual ULong_t Hash () const
 
virtual Bool_t IsSortable () const
 
TNamedoperator= (const TNamed &rhs)
 
virtual void SetName (const char *name)
 
virtual void SetNameTitle (const char *name, const char *title)
 
virtual void SetTitle (const char *title="")
 
virtual Int_t Sizeof () const
 
- Public Member Functions inherited from TObject
 TObject ()
 
 TObject (const TObject &object)
 
virtual ~TObject ()
 
void AbstractMethod (const char *method) const
 
virtual void AppendPad (Option_t *option="")
 
virtual void Browse (TBrowser *b)
 
ULong_t CheckedHash ()
 
virtual const char * ClassName () const
 
virtual void Delete (Option_t *option="")
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 
virtual void Draw (Option_t *option="")
 
virtual void DrawClass () const
 
virtual TObjectDrawClone (Option_t *option="") const
 
virtual void Dump () const
 
virtual void Error (const char *method, const char *msgfmt,...) const
 
virtual void Execute (const char *method, const char *params, Int_t *error=0)
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=0)
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 
virtual TObjectFindObject (const char *name) const
 
virtual TObjectFindObject (const TObject *obj) const
 
virtual Option_tGetDrawOption () const
 
virtual const char * GetIconName () const
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 
virtual Bool_t HandleTimer (TTimer *timer)
 
Bool_t HasInconsistentHash () const
 
virtual void Info (const char *method, const char *msgfmt,...) const
 
virtual Bool_t InheritsFrom (const char *classname) const
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 
virtual void Inspect () const
 
void InvertBit (UInt_t f)
 
virtual Bool_t IsFolder () const
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 
virtual Bool_t Notify ()
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 
void operator delete (void *ptr)
 
void operator delete[] (void *ptr)
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 
virtual void Paint (Option_t *option="")
 
virtual void Pop ()
 
virtual Int_t Read (const char *name)
 
virtual void RecursiveRemove (TObject *obj)
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 
virtual void SetDrawOption (Option_t *option="")
 
virtual void SetUniqueID (UInt_t uid)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0)
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const
 

Static Public Member Functions

template<typename T >
static T DefaultValue ()
 
template<>
int DefaultValue ()
 
template<>
double DefaultValue ()
 
template<>
bool DefaultValue ()
 
template<>
TString DefaultValue ()
 
template<>
KVString DefaultValue ()
 
template<>
cstring DefaultValue ()
 
- Static Public Member Functions inherited from TObject
static Longptr_t GetDtorOnly ()
 
static Bool_t GetObjectStat ()
 
static void SetDtorOnly (void *obj)
 
static void SetObjectStat (Bool_t stat)
 

Protected Attributes

Double_t fNumber
 used to store numerical (integer or floating-point) values More...
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 
- Protected Attributes inherited from TObject
 kOnlyPrepStep
 

Private Types

enum  { kIsString = BIT(14) , kIsDouble = BIT(15) , kIsInt = BIT(16) , kIsBool = BIT(17) }
 
enum  { kBitMask = 0x0003c000 }
 

Private Member Functions

Int_t GetType () const
 
void ResetBits ()
 
void SetType (UInt_t f)
 

Friends

class KVNameValueList
 

Additional Inherited Members

- Public Types inherited from TObject
enum  EDeprecatedStatusBits
 
enum  EStatusBits
 
- Public Attributes inherited from TObject
 kBitMask
 
 kCanDelete
 
 kCannotPick
 
 kHasUUID
 
 kInconsistent
 
 kInvalidObject
 
 kIsOnHeap
 
 kIsReferenced
 
 kMustCleanup
 
 kNoContextMenu
 
 kNotDeleted
 
 kObjInCanvas
 
 kOverwrite
 
 kSingleKey
 
 kWriteDelete
 
 kZombie
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 
void MakeZombie ()
 

#include <KVNamedParameter.h>

Inheritance diagram for KVNamedParameter:
Inheritance graph
[legend]

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
kIsString 
kIsDouble 
kIsInt 
kIsBool 

Definition at line 93 of file KVNamedParameter.h.

◆ anonymous enum

anonymous enum
private
Enumerator
kBitMask 

Definition at line 102 of file KVNamedParameter.h.

Constructor & Destructor Documentation

◆ KVNamedParameter() [1/7]

KVNamedParameter::KVNamedParameter ( )

Default constructor.

Definition at line 17 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [2/7]

KVNamedParameter::KVNamedParameter ( const char *  nom)

Definition at line 37 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [3/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
const char *  val 
)

Definition at line 47 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [4/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
Double_t  val 
)

Definition at line 79 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [5/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
Int_t  val 
)

Definition at line 111 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [6/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
Bool_t  val 
)

Definition at line 121 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [7/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
const KVNamedParameter p 
)

Create parameter with given name "nom", and the type & value of "p".

Definition at line 132 of file KVNamedParameter.cpp.

◆ ~KVNamedParameter()

KVNamedParameter::~KVNamedParameter ( )
virtual

Destructor.

Definition at line 28 of file KVNamedParameter.cpp.

Member Function Documentation

◆ Add()

void KVNamedParameter::Add ( const KVNamedParameter p)

Numerical values: Add the numerical value of "p" to this parameter Strings: add string to comma-separated list of values If parameters are not same type, print warning and do nothing

Definition at line 181 of file KVNamedParameter.cpp.

◆ Clear()

void KVNamedParameter::Clear ( Option_t = "")
virtual

Removes the name and any assigned value.

Reimplemented from TNamed.

Definition at line 259 of file KVNamedParameter.cpp.

◆ Compare()

Int_t KVNamedParameter::Compare ( const TObject obj) const
virtual

Compares numerical parameters for sorting lists (such as KVNameValueList)

Reimplemented from TNamed.

Definition at line 501 of file KVNamedParameter.cpp.

◆ DefaultValue() [1/7]

template<typename T >
static T KVNamedParameter::DefaultValue ( )
static

◆ DefaultValue() [2/7]

template<>
int KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 230 of file KVNamedParameter.h.

◆ DefaultValue() [3/7]

template<>
double KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 234 of file KVNamedParameter.h.

◆ DefaultValue() [4/7]

template<>
bool KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 238 of file KVNamedParameter.h.

◆ DefaultValue() [5/7]

template<>
TString KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 242 of file KVNamedParameter.h.

◆ DefaultValue() [6/7]

template<>
KVString KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 246 of file KVNamedParameter.h.

◆ DefaultValue() [7/7]

template<>
cstring KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 250 of file KVNamedParameter.h.

◆ Get() [1/7]

template<typename T >
T KVNamedParameter::Get ( ) const
inline

compile-time error if one of allowed specializations not used

Definition at line 154 of file KVNamedParameter.h.

◆ Get() [2/7]

template<>
int KVNamedParameter::Get ( ) const
inline

Definition at line 202 of file KVNamedParameter.h.

◆ Get() [3/7]

template<>
double KVNamedParameter::Get ( ) const
inline

Definition at line 206 of file KVNamedParameter.h.

◆ Get() [4/7]

template<>
bool KVNamedParameter::Get ( ) const
inline

Definition at line 210 of file KVNamedParameter.h.

◆ Get() [5/7]

template<>
KVString KVNamedParameter::Get ( ) const
inline

Definition at line 214 of file KVNamedParameter.h.

◆ Get() [6/7]

template<>
TString KVNamedParameter::Get ( ) const
inline

Definition at line 218 of file KVNamedParameter.h.

◆ Get() [7/7]

template<>
cstring KVNamedParameter::Get ( ) const
inline

Definition at line 222 of file KVNamedParameter.h.

◆ GetBool()

Bool_t KVNamedParameter::GetBool ( ) const

returns boolean if parameter value is of boolean type if string, conversion to integer is attempted

Definition at line 353 of file KVNamedParameter.cpp.

◆ GetDouble()

Double_t KVNamedParameter::GetDouble ( ) const

returns double if parameter value is of numerical type if string, conversion to floating point is attempted

Definition at line 319 of file KVNamedParameter.cpp.

◆ GetInt()

Int_t KVNamedParameter::GetInt ( ) const

returns integer if parameter value is of numerical type if string, conversion to integer is attempted

Definition at line 336 of file KVNamedParameter.cpp.

◆ GetSQLType()

const Char_t * KVNamedParameter::GetSQLType ( ) const

Returns type of parameter for use in SQLite database "INTEGER", "REAL", or "TEXT"

Definition at line 535 of file KVNamedParameter.cpp.

◆ GetString()

const Char_t * KVNamedParameter::GetString ( ) const

Returns value of parameter as a string, whatever the type (integer or floating values are converted to a string, booleans are "true" or "false")

Definition at line 274 of file KVNamedParameter.cpp.

◆ GetTString()

TString KVNamedParameter::GetTString ( ) const

Returns value of parameter as a TString, whatever the type (integer or floating values are converted to a string)

Definition at line 297 of file KVNamedParameter.cpp.

◆ GetType()

Int_t KVNamedParameter::GetType ( ) const
inlineprivate

compare this value with the values kIsString, kIsDouble, etc.

Definition at line 110 of file KVNamedParameter.h.

◆ HasSameValueAs()

Bool_t KVNamedParameter::HasSameValueAs ( const KVNamedParameter other) const

Returns kTRUF if the two parameters have the same type and the same value (don't care about parameter names)

Definition at line 401 of file KVNamedParameter.cpp.

◆ Is()

template<typename T >
Bool_t KVNamedParameter::Is
inline

Definition at line 282 of file KVNamedParameter.h.

◆ IsBool()

Bool_t KVNamedParameter::IsBool ( ) const
inline

Definition at line 178 of file KVNamedParameter.h.

◆ IsDouble()

Bool_t KVNamedParameter::IsDouble ( ) const
inline

Definition at line 170 of file KVNamedParameter.h.

◆ IsEqual()

Bool_t KVNamedParameter::IsEqual ( const TObject obj) const
virtual

Test for equality between two parameters Returns kTRUE if both the name, the type, and the value of the parameters are identical

Reimplemented from TObject.

Definition at line 370 of file KVNamedParameter.cpp.

◆ IsInt()

Bool_t KVNamedParameter::IsInt ( ) const
inline

Definition at line 174 of file KVNamedParameter.h.

◆ IsNumber()

Bool_t KVNamedParameter::IsNumber ( ) const
inline

Definition at line 182 of file KVNamedParameter.h.

◆ IsString()

Bool_t KVNamedParameter::IsString ( ) const
inline

Definition at line 166 of file KVNamedParameter.h.

◆ ls()

void KVNamedParameter::ls ( Option_t option = "") const
virtual

compact listing of parameter name & value, used by KVNameValueList::Print option controls what is printed: "" (default) : all parameters "int" : only integer parameters "bool" : only boolean parameters "double" : only double parameters "string" : only string parameters

Reimplemented from TNamed.

Definition at line 453 of file KVNamedParameter.cpp.

◆ operator==()

Bool_t KVNamedParameter::operator== ( const KVNamedParameter other) const

Test for equality between two parameters Returns kTRUE if both the name, the type, and the value of the parameters are identical

Definition at line 386 of file KVNamedParameter.cpp.

◆ Print()

void KVNamedParameter::Print ( Option_t opt = "") const
virtual

Reimplemented from TNamed.

Definition at line 433 of file KVNamedParameter.cpp.

◆ ResetBits()

void KVNamedParameter::ResetBits ( )
inlineprivate

Definition at line 105 of file KVNamedParameter.h.

◆ Set() [1/10]

void KVNamedParameter::Set ( Bool_t  val)

Definition at line 216 of file KVNamedParameter.cpp.

◆ Set() [2/10]

void KVNamedParameter::Set ( const char *  val)

Definition at line 68 of file KVNamedParameter.cpp.

◆ Set() [3/10]

void KVNamedParameter::Set ( const char *  name,
Bool_t  val 
)

Definition at line 154 of file KVNamedParameter.cpp.

◆ Set() [4/10]

void KVNamedParameter::Set ( const char *  name,
const char *  val 
)

Definition at line 57 of file KVNamedParameter.cpp.

◆ Set() [5/10]

void KVNamedParameter::Set ( const char *  nom,
const KVNamedParameter p 
)

Set parameter name "nom" with the type & value of "p".

Definition at line 166 of file KVNamedParameter.cpp.

◆ Set() [6/10]

void KVNamedParameter::Set ( const char *  name,
Double_t  val 
)

Definition at line 89 of file KVNamedParameter.cpp.

◆ Set() [7/10]

void KVNamedParameter::Set ( const char *  name,
Int_t  val 
)

Definition at line 143 of file KVNamedParameter.cpp.

◆ Set() [8/10]

void KVNamedParameter::Set ( Double_t  val)

Definition at line 100 of file KVNamedParameter.cpp.

◆ Set() [9/10]

void KVNamedParameter::Set ( Int_t  val)

Definition at line 205 of file KVNamedParameter.cpp.

◆ Set() [10/10]

void KVNamedParameter::Set ( TEnv e,
const TString p = "" 
)

void Set(const KVNamedParameter&);

Look for value in TEnv with same name as this parameter, or prefixed with "p." If found, set value according to TEnv

Definition at line 240 of file KVNamedParameter.cpp.

◆ SetType()

void KVNamedParameter::SetType ( UInt_t  f)
inlineprivate

Definition at line 116 of file KVNamedParameter.h.

◆ WriteToEnv()

void KVNamedParameter::WriteToEnv ( TEnv e,
const TString p = "" 
)

Write parameter in TEnv, using optional prefix p as "p.[name]".

Definition at line 517 of file KVNamedParameter.cpp.

Friends And Related Function Documentation

◆ KVNameValueList

friend class KVNameValueList
friend

Definition at line 91 of file KVNamedParameter.h.

Member Data Documentation

◆ fNumber

Double_t KVNamedParameter::fNumber
protected

used to store numerical (integer or floating-point) values

Definition at line 123 of file KVNamedParameter.h.


The documentation for this class was generated from the following files: