20 #ifndef RIPPLE_BASICS_BASICCONFIG_H_INCLUDED
21 #define RIPPLE_BASICS_BASICCONFIG_H_INCLUDED
23 #include <ripple/basics/contract.h>
24 #include <boost/beast/core/string.hpp>
25 #include <boost/lexical_cast.hpp>
26 #include <boost/optional.hpp>
28 #include <beast/unit_test/detail/const_container.hpp>
43 class Section :
public beast::unit_test::detail::const_container<
44 std::map<std::string, std::string, boost::beast::iless>>
90 lines_[0] = std::move(value);
105 Throw<std::runtime_error>(
106 "A legacy value must have exactly one line. Section: " +
name_);
145 auto const iter = cont().find(
name);
146 if (iter == cont().end())
148 return boost::lexical_cast<T>(iter->second);
156 auto const v = get<T>(
name);
157 return v.is_initialized() ? *v : other;
258 return s.second.had_trailing_comments();
278 bool found_and_valid =
false;
281 auto const val = section.
get<T>(name);
282 if ((found_and_valid = val.is_initialized()))
285 catch (boost::bad_lexical_cast&)
288 return found_and_valid;
299 T
const& defaultValue,
303 bool found_and_valid = set<T>(target, name, section);
304 if (!found_and_valid)
305 target = defaultValue;
306 return found_and_valid;
318 T
const& defaultValue = T{})
322 return section.
value_or<T>(name, defaultValue);
324 catch (boost::bad_lexical_cast&)
336 if (val.is_initialized())
339 catch (boost::bad_lexical_cast&)
349 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.
Section & operator[](std::string const &name)
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.