0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 20:13:05 +02:00

Added class OptionList convenience methods get_default()

and get_num().

Also, get_optional() should return a std::string, not a
const std::string.
This commit is contained in:
James Yonan 2014-12-29 21:54:23 -07:00
parent 464690aa6b
commit 0acb038808

View File

@ -1015,7 +1015,7 @@ namespace openvpn {
// Convenience method that gets a particular argument index within an option,
// while returning the empty string if option doesn't exist, and raising an
// exception if argument index is out-of-bounds.
const std::string get_optional(const std::string& name, size_t index, const size_t max_len) const
std::string get_optional(const std::string& name, size_t index, const size_t max_len) const
{
const Option* o = get_ptr(name);
if (o)
@ -1024,6 +1024,35 @@ namespace openvpn {
return "";
}
// Convenience method that gets a particular argument index within an option,
// while returning a default string if option doesn't exist, and raising an
// exception if argument index is out-of-bounds.
std::string get_default(const std::string& name,
size_t index,
const size_t max_len,
const std::string& default_value) const
{
const Option* o = get_ptr(name);
if (o)
return o->get(index, max_len);
else
return default_value;
}
template <typename T>
T get_num(const std::string& name, const size_t idx, const T default_value) const
{
const Option* o = get_ptr(name);
T n = default_value;
if (o && o->size() > idx)
{
const std::string& numstr = o->get(idx, 64);
if (parse_number<T>(numstr, n))
return n;
}
return n;
}
// Touch an option, if it exists.
void touch(const std::string& name) const
{