4 #include "KVClassFactory.h"
5 #include "KVNameValueList.h"
20 : fList(), fIgnoreBool(kFALSE)
49 for (
auto& p : l) SetValue(p);
61 : TNamed(name, title), fList(), fIgnoreBool(kFALSE)
69 if (
Set(name)) SetName(
"");
101 if (&o !=
this) o.
Copy(*
this);
156 if (!list.Contains(
"="))
return false;
160 while (!list.
End()) {
165 if (parval.BeginsWith(
"'") && parval.EndsWith(
"'")) {
167 parval.Remove(parval.Length() - 1);
171 else if (parval.IsDigit()) {
175 else if (parval.IsFloat()) {
209 for (
auto& par : *
this) {
210 if (list.Length()) list +=
",";
211 list += Form(
"%s=", par.GetName());
213 list += par.GetString();
214 else if (par.IsDouble())
215 list += Form(
"%g", par.GetDouble());
216 else if (par.IsInt())
217 list += Form(
"%d", par.GetInt());
282 for (Int_t ii = 0; ii < np1; ii += 1) {
284 if (name.Contains(sel)) toBeRemoved.
Add(
new TNamed(name.Data(),
""));
286 if (toBeRemoved.GetEntries()) {
287 TIter next(&toBeRemoved);
290 toBeRemoved.Delete();
309 TROOT::IndentLevel();
310 cout <<
"KVNameValueList::" << GetName() <<
" : " << GetTitle() <<
" (" <<
this <<
")" << endl;
311 TROOT::IncreaseDirLevel();
312 for (Int_t ii = 0; ii <
GetNpar(); ii += 1) {
315 TROOT::DecreaseDirLevel();
324 if (TString(GetName()) !=
"") cout << GetName();
325 else cout <<
"KVNameValueList";
327 for (
int i = 0; i <
GetNpar(); ++i) {
343 if (i <
GetNpar() - 1) cout <<
",";
371 return fList.IsOwner();
389 for (Int_t ii = 0; ii < np1; ii += 1) {
390 for (Int_t jj = 0; jj < np2; jj += 1) {
424 TString parname = name;
426 SetValue(parname, (Int_t)(x >> 32));
429 SetValue(parname, (Int_t)((x << 32) >> 32));
444 TString parname = name;
450 ULong64_t x = (ULong64_t)((hi << 32) + lo);
465 TString parname_hi = name;
467 TString parname_lo = name;
564 while ((par = next())) {
565 if (!strcmp(par->GetName(), name))
return idx;
568 Error(
"GetNameIndex",
"Parameter \"%s\" not found, -1 returned", name);
588 Error(
"GetNameAt",
"index has to be less than %d, empty string is returned",
GetNpar());
591 return fList.
At(idx)->GetName();
609 Error(
"GetStringValue(const Char_t*)",
"\"%s\" does not correspond to an existing parameter, default value \"-1\" is returned", name);
623 return fList.GetEntries();
638 static TString tmp(
"-1");
640 Error(
"GetStringValue(Int_t)",
"index has to be less than %d, \"-1\" is returned\n",
GetNpar());
685 Int_t status = env_file.ReadFile(filename, kEnvAll);
687 Error(
"ReadEnvFile",
"The file %s does not exist", filename);
690 THashList* name_value_list = env_file.GetTable();
691 TIter next_nv(name_value_list);
693 while ((nv_pair = (TEnvRec*)next_nv())) {
694 TString parname(nv_pair->GetName());
695 if (parname ==
"KVNameValueList.Name") SetName(nv_pair->GetValue());
696 else if (parname ==
"KVNameValueList.Title") SetTitle(nv_pair->GetValue());
697 else if (parname.Contains(
"NumberList"))
SetValue(parname, nv_pair->GetValue());
699 TString parval(nv_pair->GetValue());
700 if (parval.IsDigit())
SetValue(parname, parval.Atoi());
701 else if (parval.IsFloat())
SetValue(parname, parval.Atof());
703 TString PARVAL(parval);
705 if (!
fIgnoreBool && (PARVAL ==
"TRUE" || PARVAL ==
"FALSE" || PARVAL ==
"ON" || PARVAL ==
"OFF"
706 || PARVAL ==
"YES" || PARVAL ==
"NO" || PARVAL ==
"OK" || PARVAL ==
"NOT"))
707 SetValue(parname, (Bool_t)env_file.GetValue(parname, 0));
725 envfile->SetValue(
"KVNameValueList.Name", GetName());
726 envfile->SetValue(
"KVNameValueList.Title", GetTitle());
740 envfile->SetRcName(filename);
822 for (
int i = 0; i < other.
GetNpar(); ++i) {
Factory class for generating skeleton files for new classes.
void GenerateCode()
Generate header and implementation file for currently-defined class.
void AddGetSetMethods(const KVNameValueList &)
For each named parameter in the list, we add protected member variables with the name and type of the...
Extension of TEnv to allow the writing of comments in the file.
Extended version of ROOT THashList.
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
virtual void Print(Option_t *opt="") const
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
virtual void ls(Option_t *opt="") const
Int_t GetIntValue(const Char_t *name) const
Bool_t HasValue64bit(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
virtual ~KVNameValueList()
Destructor.
Bool_t fIgnoreBool
do not convert "yes", "false", "on", etc. in TEnv file to boolean
void RemoveParameter(const Char_t *name)
Int_t Compare(const TObject *nvl) const
void SetValue64bit(const Char_t *name, ULong64_t)
void SetFromEnv(TEnv *tenv, const TString &prefix="")
virtual void Clear(Option_t *opt="")
const Char_t * GetNameAt(Int_t idx) const
Int_t GetNpar() const
return the number of stored parameters
virtual void ReadEnvFile(const Char_t *filename)
virtual void WriteEnvFile(const Char_t *filename)
Write all name-value pairs in this list as a TEnv format file.
Int_t GetNameIndex(const Char_t *name) const
void Merge(const KVNameValueList &)
KVNameValueList()
Default constructor.
KVNamedParameter * FindParameter(const Char_t *name) const
return the parameter object with the asking name
KVNameValueList operator+=(const KVNameValueList &nvl)
KVNameValueList & operator=(const KVNameValueList &)
KVHashList fList
list of KVNamedParameter objects
Bool_t HasIntParameter(const Char_t *name) const
void SetOwner(Bool_t enable=kTRUE)
virtual KVEnv * ProduceEnvFile()
void WriteClass(const Char_t *classname, const Char_t *classdesc, const Char_t *base_class="")
ULong64_t GetValue64bit(const Char_t *name) const
bool Set(const KVString &)
Bool_t HasParameter(const Char_t *name) const
void AddValue(const KVNamedParameter &p)
KVHashList * GetList() const
TString GetTStringValue(const Char_t *name) const
void Copy(TObject &nvl) const
virtual void ClearSelection(TRegexp &)
void WriteToEnv(TEnv *tenv, const TString &prefix="")
A generic named parameter storing values of different types.
const Char_t * GetString() const
void Set(const char *, const char *)
void Add(const KVNamedParameter &p)
Double_t GetDouble() const
virtual void ls(Option_t *opt="") const
void WriteToEnv(TEnv *, const TString &p="")
Write parameter in TEnv, using optional prefix p as "p.[name]".
TString GetTString() const
virtual void Copy(TObject &obj) const
virtual void SetOwner(Bool_t enable=kTRUE)
virtual void Clear(Option_t *option="")
virtual TObject * At(Int_t idx) const
virtual void Add(TObject *obj)
virtual TObject * Remove(TObject *obj)
Remove object from list.
virtual TObject * FindObject(const char *name) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const