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>
91 lines_[0] = std::move(value);
106 Throw<std::runtime_error>(
107 "A legacy value must have exactly one line. Section: " +
name_);
136 template <
class T = std::
string>
143 return boost::lexical_cast<T>(iter->second);
151 auto const v = get<T>(
name);
152 return v.has_value() ? *v : other;
295 return s.second.had_trailing_comments();
315 bool found_and_valid =
false;
318 auto const val = section.
get<T>(name);
319 if ((found_and_valid = val.has_value()))
322 catch (boost::bad_lexical_cast&)
325 return found_and_valid;
336 T
const& defaultValue,
340 bool found_and_valid = set<T>(target, name, section);
341 if (!found_and_valid)
342 target = defaultValue;
343 return found_and_valid;
351 template <
class T = std::
string>
355 T
const& defaultValue = T{})
359 return section.
value_or<T>(name, defaultValue);
361 catch (boost::bad_lexical_cast&)
372 auto const val = section.
get(name);
376 catch (boost::bad_lexical_cast&)
386 return set<T>(v, name, section);
decltype(lookup_)::const_iterator const_iterator
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.
const_iterator cend() const
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
const_iterator begin() 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.
const_iterator end() const
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.
const_iterator cbegin() const
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::map< std::string, std::string > lookup_
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.
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::optional< T > get(std::string const &name) const
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.