implement confsimple::get/set for integers

This commit is contained in:
Jean-Francois Dockes 2016-04-11 17:21:59 +02:00
parent 95f4807ed9
commit ebb8469253
2 changed files with 34 additions and 3 deletions

View file

@ -274,6 +274,16 @@ int ConfSimple::get(const string& nm, string& value, const string& sk) const
return 1;
}
int ConfSimple::get(const string& nm, int *value, const string& sk) const
{
string sval;
if (!get(nm, sval, sk)) {
return 0;
}
*value = atoi(sval.c_str());
return 1;
}
// Appropriately output a subkey (nm=="") or variable line.
// We can't make any assumption about the data except that it does not
// contain line breaks.
@ -332,6 +342,12 @@ int ConfSimple::set(const std::string& nm, const std::string& value,
}
return write();
}
int ConfSimple::set(const string& nm, long long val,
const string& sk)
{
return this->set(nm, lltodecstr(val), sk);
}
// Internal set variable: no rw checking or file rewriting. If init is
// set, we're doing initial parsing, else we are changing a parsed

View file

@ -165,19 +165,34 @@ public:
}
/**
* Get value for named parameter, from specified subsection (looks in
* global space if sk is empty).
* Get string value for named parameter, from specified subsection (looks
* in global space if sk is empty).
* @return 0 if name not found, 1 else
*/
virtual int get(const string& name, string& value,
const string& sk = string()) const;
/**
* Set value for named parameter in specified subsection (or global)
* Get integer value for named parameter, from specified subsection (looks
* in global space if sk is empty).
* @return 0 if name not found, 1 else
*/
virtual int get(const string& name, int* value,
const string& sk = string()) const;
/**
* Set value for named string parameter in specified subsection (or global)
* @return 0 for error, 1 else
*/
virtual int set(const string& nm, const string& val,
const string& sk = string());
/**
* Set value for named integer parameter in specified subsection (or global)
* @return 0 for error, 1 else
*/
virtual int set(const string& nm, long long val,
const string& sk = string());
/**
* Remove name and value from config