*
* @param val New value
*/
- void Set(const TString& val) { fIsSet = true; fValue = val; }
+ void Set(const TString& val)
+ {
+ if (HasArg()) {
+ fIsSet = true;
+ fValue = val;
+ return;
+ }
+
+ // Allow flags to get =true, =1, =false, =0 values
+ if (!val.IsNull() &&
+ (val.EqualTo("false", TString::kIgnoreCase) ||
+ (val.IsDigit() && !val.Atoi()))) {
+ fIsSet = false;
+ fValue = "false";
+ }
+ else {
+ fIsSet = true;
+ fValue = "true";
+ }
+ }
/**
* Set the value
*/
Error("Option::Set", "Option %s needs an argument", fName.Data());
return;
}
- Set("");
+ Set("true");
}
/**
* Reset the set flag
*
*/
- void Reset() { fIsSet = false; }
+ void Reset()
+ {
+ fIsSet = false;
+ if (!HasArg()) fValue = "false";
+ }
/**
* @return constant reference to value
*/
Option* Add(const TString& name,
const TString& arg,
const TString& desc,
- const TString& val)
+ const TString& val="")
{
Option* o = Find(name);
if (o) {
{
return Add(name, "", desc, "");
}
+ /**
+ * Add an option with argument
+ *
+ * @param name Name of option
+ * @param arg Dummy argument
+ * @param desc Description
+ * @param val Default value
+ *
+ * @return Newly added option
+ */
+ Option* Add(const TString& name,
+ const TString& arg,
+ const TString& desc,
+ Int_t val,
+ Bool_t asHex=false)
+ {
+ if (asHex) {
+ UInt_t uval = val;
+ return Add(name, arg, desc, Form("0x%x", uval));
+ }
+ return Add(name, arg, desc, Form("%d", val));
+ }
+ /**
+ * Add an option with argument
+ *
+ * @param name Name of option
+ * @param arg Dummy argument
+ * @param desc Description
+ * @param val Default value
+ *
+ * @return Newly added option
+ */
+ Option* Add(const TString& name,
+ const TString& arg,
+ const TString& desc,
+ Long64_t val,
+ Bool_t asHex=false)
+ {
+ if (asHex) {
+ ULong64_t uval = val;
+ return Add(name, arg, desc, Form("0x%llx", uval));
+ }
+ return Add(name, arg, desc, Form("%lld", val));
+ }
+ /**
+ * Add an option with argument
+ *
+ * @param name Name of option
+ * @param arg Dummy argument
+ * @param desc Description
+ * @param val Default value
+ *
+ * @return Newly added option
+ */
+ Option* Add(const TString& name,
+ const TString& arg,
+ const TString& desc,
+ Double_t val)
+ {
+ return Add(name, arg, desc, Form("%lg", val));
+ }
+
/**
* Remove an option
*
* @param prefix Prefix for each option
*/
void Store(std::ostream& o, const char* prefix="",
- const char* delim=",", bool quote=true) const
+ const char* delim=",", bool quote=true,
+ bool onlySet=false) const
{
Int_t nWidth, aWidth;
Widest(nWidth, aWidth);
const Link* cur = fList;
while (cur) {
Option* opt = cur->fThis;
- if (!opt->HasArg() && !opt->IsSet()) {
+ if ((!opt->HasArg() || onlySet) && !opt->IsSet()) {
cur = cur->fNext;
continue;
}
// Our linked list
Link* fList;
- static void Test()
+ static void Test(const char* opts="")
{
OptionList l;
l.Add("int", "NUMBER", "Integer", "42");
std::cout << "Find" << std::endl;
Option* b = l.Find("bool");
+ b->Set("true");
b->Show(std::cout);
std::cout << "SetF" << std::endl;
std::cout << "Set" << std::endl;
l.Set("int", "10");
l.Set("hex", 0xbeef, true);
+ l.Set("bool", "false");
l.Show(std::cout, "\t");
std::cout << "Copy" << std::endl;
OptionList c(l);
c.Show(std::cout, "\t");
+ std::cout << "Parse" << std::endl;
+ c.Parse(opts,",");
+ c.Show(std::cout, "\t");
std::cout << "End of test" << std::endl;
}
// TList fList;