3#include <xrpl/basics/contract.h>
5#include <boost/beast/core/string.hpp>
6#include <boost/lexical_cast.hpp>
82 lines_.emplace_back(std::move(value));
86 lines_[0] = std::move(value);
104 "A legacy value must have exactly one line. Section: " +
name_);
140 template <
class T = std::
string>
147 return boost::lexical_cast<T>(iter->second);
158 return v.has_value() ? *v : other;
323 bool foundAndValid =
false;
326 auto const val = section.
get<T>(name);
327 foundAndValid = val.has_value();
331 catch (boost::bad_lexical_cast
const&)
334 return foundAndValid;
347 bool const foundAndValid =
set<T>(target, name, section);
349 target = defaultValue;
350 return foundAndValid;
359template <
class T = std::
string>
365 return section.
valueOr<T>(name, defaultValue);
367 catch (boost::bad_lexical_cast
const&)
378 auto const val = section.
get(name);
382 catch (boost::bad_lexical_cast
const&)
392 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
bool hadTrailingComments() 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)
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.
Section(std::string name="")
Create an empty section.
const_iterator end() const
std::optional< T > get(std::string const &name) const
decltype(lookup_)::const_iterator const_iterator
const_iterator cbegin() const
bool hadTrailingComments_
void append(std::string const &line)
Append a line to this section.
std::unordered_map< std::string, std::string > lookup_
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.
friend std::ostream & operator<<(std::ostream &, Section const §ion)
void set(std::string const &key, std::string const &value)
Set a key/value pair.
const_iterator begin() const
bool hadTrailingComments() const
T valueOr(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.
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.
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,...
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
bool getIfExists< bool >(Section const §ion, std::string const &name, bool &v)
bool getIfExists(Section const §ion, std::string const &name, T &v)
Dir::ConstIterator const_iterator
std::unordered_map< std::string, std::vector< std::string > > IniFileSections
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)