20#ifndef RIPPLE_BASICS_BASICCONFIG_H_INCLUDED
21#define RIPPLE_BASICS_BASICCONFIG_H_INCLUDED
23#include <xrpl/basics/contract.h>
25#include <boost/beast/core/string.hpp>
26#include <boost/lexical_cast.hpp>
93 lines_[0] = std::move(value);
108 Throw<std::runtime_error>(
109 "A legacy value must have exactly one line. Section: " +
name_);
138 template <
class T = std::
string>
145 return boost::lexical_cast<T>(iter->second);
153 auto const v = get<T>(
name);
154 return v.has_value() ? *v : other;
297 return s.second.had_trailing_comments();
317 bool found_and_valid =
false;
320 auto const val = section.
get<T>(name);
321 if ((found_and_valid = val.has_value()))
324 catch (boost::bad_lexical_cast&)
327 return found_and_valid;
338 T
const& defaultValue,
342 bool found_and_valid = set<T>(target, name, section);
343 if (!found_and_valid)
344 target = defaultValue;
345 return found_and_valid;
353template <
class T = std::
string>
357 T
const& defaultValue = T{})
361 return section.
value_or<T>(name, defaultValue);
363 catch (boost::bad_lexical_cast&)
374 auto const val = section.
get(name);
378 catch (boost::bad_lexical_cast&)
388 return set<T>(v, name, section);
Holds unparsed configuration information.
friend std::ostream & operator<<(std::ostream &ss, BasicConfig const &c)
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
bool had_trailing_comments() const
Section const & operator[](std::string const &name) const
void deprecatedClearSection(std::string const §ion)
Remove all the key/value pairs from the section.
Section & section(std::string const &name)
Returns the section with the given name.
void build(IniFileSections const &ifs)
std::unordered_map< std::string, Section > map_
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.
Section & operator[](std::string const &name)
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
Holds a collection of configuration values.
std::string const & name() const
Returns the name of this section.
std::string legacy() const
Get the legacy value for this section.
std::vector< std::string > lines_
friend std::ostream & operator<<(std::ostream &, Section const §ion)
const_iterator begin() const
decltype(lookup_)::const_iterator const_iterator
const_iterator cend() const
bool had_trailing_comments() const
T value_or(std::string const &name, T const &other) const
Returns a value if present, else another value.
std::vector< std::string > const & lines() const
Returns all the lines in the section.
void legacy(std::string value)
Set the legacy value for this section.
std::optional< T > get(std::string const &name) const
bool exists(std::string const &name) const
Returns true if a key with the given name exists.
void append(std::string const &line)
Append a line to this section.
const_iterator cbegin() const
bool had_trailing_comments_
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
std::vector< std::string > const & values() const
Returns all the values in the section.
std::unordered_map< std::string, std::string > lookup_
std::vector< std::string > values_
const_iterator end() const
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(Section const §ion, std::string const &name, T &v)
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.