20 #ifndef RIPPLE_BASICS_BASICCONFIG_H_INCLUDED
21 #define RIPPLE_BASICS_BASICCONFIG_H_INCLUDED
23 #include <ripple/basics/contract.h>
24 #include <beast/unit_test/detail/const_container.hpp>
25 #include <boost/beast/core/string.hpp>
26 #include <boost/lexical_cast.hpp>
27 #include <boost/optional.hpp>
44 :
public beast::unit_test::detail::const_container <
45 std::map <std::string, std::string, boost::beast::iless>>
92 lines_[0] = std::move (value);
107 Throw<std::runtime_error> (
108 "A legacy value must have exactly one line. Section: " +
name_);
147 auto const iter = cont().find(
name);
148 if (iter == cont().end())
150 return boost::lexical_cast<T>(iter->second);
158 auto const v = get<T>(
name);
159 return v.is_initialized() ? *v : other;
254 [](
auto s){ return s.second.had_trailing_comments(); });
273 bool found_and_valid =
false;
276 auto const val = section.
get<T> (name);
277 if ((found_and_valid = val.is_initialized()))
280 catch (boost::bad_lexical_cast&)
283 return found_and_valid;
293 set (T& target, T
const& defaultValue,
296 bool found_and_valid = set<T>(target, name, section);
297 if (!found_and_valid)
298 target = defaultValue;
299 return found_and_valid;
310 std::string const& name, T
const& defaultValue = T{})
314 return section.
value_or<T> (name, defaultValue);
316 catch (boost::bad_lexical_cast&)
327 bool found_and_valid =
false;
331 if ((found_and_valid = val.is_initialized()))
334 catch (boost::bad_lexical_cast&)
345 return set<T>(v, name, section);
Holds a collection of configuration values.
bool had_trailing_comments() const
std::vector< std::string > values_
void legacy(std::string value)
Set the legacy value for this section.
Section const & operator[](std::string const &name) const
Section(std::string const &name="")
Create an empty section.
T value_or(std::string const &name, T const &other) const
Returns a value if present, else another value.
bool exists(std::string const &name) const
Returns true if a key with the given name exists.
bool had_trailing_comments() const
std::vector< std::string > const & values() const
Returns all the values in the section.
bool get_if_exists(Section const §ion, std::string const &name, T &v)
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
std::string const & name() const
Returns the name of this section.
void deprecatedClearSection(std::string const §ion)
Remove all the key/value pairs from the section.
friend std::ostream & operator<<(std::ostream &ss, BasicConfig const &c)
void build(IniFileSections const &ifs)
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
std::vector< std::string > const & lines() const
Returns all the lines in the section.
bool had_trailing_comments_
void overwrite(std::string const §ion, std::string const &key, std::string const &value)
Overwrite a key/value pair with a command line argument If the section does not exist it is created.
std::pair< std::string, bool > find(std::string const &name) const
Retrieve a key/value pair.
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
boost::optional< T > get(std::string const &name) const
void set(std::string const &key, std::string const &value)
Set a key/value pair.
friend std::ostream & operator<<(std::ostream &, Section const §ion)
std::string legacy() const
Get the legacy value for this section.
std::vector< std::string > lines_
std::map< std::string, Section, boost::beast::iless > map_
bool get_if_exists< bool >(Section const §ion, std::string const &name, bool &v)
Holds unparsed configuration information.
void append(std::string const &line)
Append a line to this section.
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
T & get(EitherAmount &amt)
Section & section(std::string const &name)
Returns the section with the given name.