Replaces StringPairArray with Section in Config.

This commit is contained in:
seelabs
2015-03-06 15:32:20 -08:00
committed by Tom Ritchford
parent 8f88d915ba
commit 6b9e842ddd
28 changed files with 165 additions and 281 deletions

View File

@@ -78,7 +78,7 @@ public:
/**
* Set the legacy value for this section.
*/
*/
void
legacy (std::string value)
{
@@ -182,6 +182,11 @@ public:
overwrite (std::string const& section, std::string const& key,
std::string const& value);
/** Remove all the key/value pairs from the section.
*/
void
deprecatedClearSection (std::string const& section);
/**
* Set a value that is not a key/value pair.
*
@@ -232,7 +237,7 @@ set (T& target, std::string const& name, Section const& section)
target = boost::lexical_cast <T> (result.first);
return true;
}
catch(...)
catch (boost::bad_lexical_cast&)
{
}
return false;
@@ -256,7 +261,7 @@ set (T& target, T const& defaultValue,
target = boost::lexical_cast <T> (result.first);
return true;
}
catch(...)
catch (boost::bad_lexical_cast&)
{
target = defaultValue;
}
@@ -280,12 +285,46 @@ get (Section const& section,
{
return boost::lexical_cast <T> (result.first);
}
catch(...)
catch (boost::bad_lexical_cast&)
{
}
return defaultValue;
}
template <class T>
bool
get_if_exists (Section const& section,
std::string const& name, T& v)
{
auto const result = section.find (name);
if (! result.second)
return false;
try
{
v = boost::lexical_cast <T> (result.first);
return true;
}
catch (boost::bad_lexical_cast&)
{
}
return false;
}
template <>
inline
bool
get_if_exists<bool> (Section const& section,
std::string const& name, bool& v)
{
int intVal = 0;
if (get_if_exists (section, name, intVal))
{
v = bool (intVal);
return true;
}
return false;
}
} // ripple
#endif