1#ifndef XRPL_BASICS_BASICCONFIG_H_INCLUDED
2#define XRPL_BASICS_BASICCONFIG_H_INCLUDED
4#include <xrpl/basics/contract.h>
6#include <boost/beast/core/string.hpp>
7#include <boost/lexical_cast.hpp>
73 lines_[0] = std::move(value);
88 Throw<std::runtime_error>(
"A legacy value must have exactly one line. Section: " +
name_);
117 template <
class T = std::
string>
124 return boost::lexical_cast<T>(iter->second);
132 auto const v = get<T>(
name);
133 return v.has_value() ? *v : other;
272 return std::any_of(
map_.cbegin(),
map_.cend(), [](
auto s) { return s.second.had_trailing_comments(); });
291 bool found_and_valid =
false;
294 auto const val = section.
get<T>(name);
295 if ((found_and_valid = val.has_value()))
298 catch (boost::bad_lexical_cast&)
301 return found_and_valid;
313 bool found_and_valid = set<T>(target, name, section);
314 if (!found_and_valid)
315 target = defaultValue;
316 return found_and_valid;
324template <
class T = std::
string>
330 return section.
value_or<T>(name, defaultValue);
332 catch (boost::bad_lexical_cast&)
343 auto const val = section.
get(name);
347 catch (boost::bad_lexical_cast&)
357 return set<T>(v, name, section);
Holds unparsed configuration information.
friend std::ostream & operator<<(std::ostream &ss, BasicConfig const &c)
Section const & operator[](std::string const &name) const
void deprecatedClearSection(std::string const §ion)
Remove all the key/value pairs from the section.
void build(IniFileSections const &ifs)
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::unordered_map< std::string, Section > map_
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & operator[](std::string const &name)
bool had_trailing_comments() const
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
Section & section(std::string const &name)
Returns the section with the given name.
Holds a collection of configuration values.
const_iterator end() const
std::optional< T > get(std::string const &name) const
decltype(lookup_)::const_iterator const_iterator
const_iterator cbegin() const
friend std::ostream & operator<<(std::ostream &, Section const §ion)
void append(std::string const &line)
Append a line to this section.
std::unordered_map< std::string, std::string > lookup_
bool had_trailing_comments() const
std::vector< std::string > const & values() const
Returns all the values in the section.
std::string const & name() const
Returns the name of this section.
std::vector< std::string > values_
std::vector< std::string > const & lines() const
Returns all the lines in the section.
const_iterator begin() const
T value_or(std::string const &name, T const &other) const
Returns a value if present, else another value.
std::string legacy() const
Get the legacy value for this section.
void legacy(std::string value)
Set the legacy value for this section.
bool had_trailing_comments_
std::vector< std::string > lines_
const_iterator cend() const
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
bool exists(std::string const &name) const
Returns true if a key with the given name exists.
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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,...
bool get_if_exists< bool >(Section const §ion, std::string const &name, bool &v)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
bool get_if_exists(Section const §ion, std::string const &name, T &v)