implement confsimple::get/set for integers
This commit is contained in:
parent
95f4807ed9
commit
ebb8469253
2 changed files with 34 additions and 3 deletions
|
@ -274,6 +274,16 @@ int ConfSimple::get(const string& nm, string& value, const string& sk) const
|
||||||
return 1;
|
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.
|
// Appropriately output a subkey (nm=="") or variable line.
|
||||||
// We can't make any assumption about the data except that it does not
|
// We can't make any assumption about the data except that it does not
|
||||||
// contain line breaks.
|
// contain line breaks.
|
||||||
|
@ -332,6 +342,12 @@ int ConfSimple::set(const std::string& nm, const std::string& value,
|
||||||
}
|
}
|
||||||
return write();
|
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
|
// Internal set variable: no rw checking or file rewriting. If init is
|
||||||
// set, we're doing initial parsing, else we are changing a parsed
|
// set, we're doing initial parsing, else we are changing a parsed
|
||||||
|
|
|
@ -165,19 +165,34 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get value for named parameter, from specified subsection (looks in
|
* Get string value for named parameter, from specified subsection (looks
|
||||||
* global space if sk is empty).
|
* in global space if sk is empty).
|
||||||
* @return 0 if name not found, 1 else
|
* @return 0 if name not found, 1 else
|
||||||
*/
|
*/
|
||||||
virtual int get(const string& name, string& value,
|
virtual int get(const string& name, string& value,
|
||||||
const string& sk = string()) const;
|
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
|
* @return 0 for error, 1 else
|
||||||
*/
|
*/
|
||||||
virtual int set(const string& nm, const string& val,
|
virtual int set(const string& nm, const string& val,
|
||||||
const string& sk = string());
|
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
|
* Remove name and value from config
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue