rippled
Public Member Functions | Private Types | Private Attributes | Friends | List of all members
ripple::Section Class Reference

Holds a collection of configuration values. More...

Collaboration diagram for ripple::Section:
Collaboration graph
[legend]

Public Member Functions

 Section (std::string const &name="")
 Create an empty section. More...
 
std::string const & name () const
 Returns the name of this section. More...
 
std::vector< std::string > const & lines () const
 Returns all the lines in the section. More...
 
std::vector< std::string > const & values () const
 Returns all the values in the section. More...
 
void legacy (std::string value)
 Set the legacy value for this section. More...
 
std::string legacy () const
 Get the legacy value for this section. More...
 
void set (std::string const &key, std::string const &value)
 Set a key/value pair. More...
 
void append (std::vector< std::string > const &lines)
 Append a set of lines to this section. More...
 
void append (std::string const &line)
 Append a line to this section. More...
 
bool exists (std::string const &name) const
 Returns true if a key with the given name exists. More...
 
template<class T = std::string>
std::optional< T > get (std::string const &name) const
 
template<class T >
value_or (std::string const &name, T const &other) const
 Returns a value if present, else another value. More...
 
bool had_trailing_comments () const
 
bool empty () const
 
std::size_t size () const
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator end () const
 
const_iterator cend () const
 

Private Types

using const_iterator = decltype(lookup_)::const_iterator
 

Private Attributes

std::string name_
 
std::map< std::string, std::stringlookup_
 
std::vector< std::stringlines_
 
std::vector< std::stringvalues_
 
bool had_trailing_comments_ = false
 

Friends

std::ostreamoperator<< (std::ostream &, Section const &section)
 

Detailed Description

Holds a collection of configuration values.

A configuration file contains zero or more sections.

Definition at line 42 of file BasicConfig.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 51 of file BasicConfig.h.

Constructor & Destructor Documentation

◆ Section()

ripple::Section::Section ( std::string const &  name = "")
explicit

Create an empty section.

Definition at line 27 of file BasicConfig.cpp.

Member Function Documentation

◆ name()

std::string const& ripple::Section::name ( ) const

Returns the name of this section.

Definition at line 59 of file BasicConfig.h.

◆ lines()

std::vector<std::string> const& ripple::Section::lines ( ) const

Returns all the lines in the section.

This includes everything.

Definition at line 68 of file BasicConfig.h.

◆ values()

std::vector<std::string> const& ripple::Section::values ( ) const

Returns all the values in the section.

Values are non-empty lines which are not key/value pairs.

Definition at line 77 of file BasicConfig.h.

◆ legacy() [1/2]

void ripple::Section::legacy ( std::string  value)

Set the legacy value for this section.

Definition at line 86 of file BasicConfig.h.

◆ legacy() [2/2]

std::string ripple::Section::legacy ( ) const

Get the legacy value for this section.

Returns
The retrieved value. A section with an empty legacy value returns an empty string.

Definition at line 101 of file BasicConfig.h.

◆ set()

void ripple::Section::set ( std::string const &  key,
std::string const &  value 
)

Set a key/value pair.

The previous value is discarded.

Definition at line 32 of file BasicConfig.cpp.

◆ append() [1/2]

void ripple::Section::append ( std::vector< std::string > const &  lines)

Append a set of lines to this section.

Lines containing key/value pairs are added to the map, else they are added to the values list. Everything is added to the lines list.

Definition at line 38 of file BasicConfig.cpp.

◆ append() [2/2]

void ripple::Section::append ( std::string const &  line)

Append a line to this section.

Definition at line 127 of file BasicConfig.h.

◆ exists()

bool ripple::Section::exists ( std::string const &  name) const

Returns true if a key with the given name exists.

Definition at line 105 of file BasicConfig.cpp.

◆ get()

template<class T = std::string>
std::optional<T> ripple::Section::get ( std::string const &  name) const

Definition at line 138 of file BasicConfig.h.

◆ value_or()

template<class T >
T ripple::Section::value_or ( std::string const &  name,
T const &  other 
) const

Returns a value if present, else another value.

Definition at line 149 of file BasicConfig.h.

◆ had_trailing_comments()

bool ripple::Section::had_trailing_comments ( ) const

Definition at line 158 of file BasicConfig.h.

◆ empty()

bool ripple::Section::empty ( ) const

Definition at line 168 of file BasicConfig.h.

◆ size()

std::size_t ripple::Section::size ( ) const

Definition at line 175 of file BasicConfig.h.

◆ begin()

const_iterator ripple::Section::begin ( ) const

Definition at line 182 of file BasicConfig.h.

◆ cbegin()

const_iterator ripple::Section::cbegin ( ) const

Definition at line 189 of file BasicConfig.h.

◆ end()

const_iterator ripple::Section::end ( ) const

Definition at line 196 of file BasicConfig.h.

◆ cend()

const_iterator ripple::Section::cend ( ) const

Definition at line 203 of file BasicConfig.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream os,
Section const &  section 
)
friend

Definition at line 111 of file BasicConfig.cpp.

Member Data Documentation

◆ name_

std::string ripple::Section::name_
private

Definition at line 45 of file BasicConfig.h.

◆ lookup_

std::map<std::string, std::string> ripple::Section::lookup_
private

Definition at line 46 of file BasicConfig.h.

◆ lines_

std::vector<std::string> ripple::Section::lines_
private

Definition at line 47 of file BasicConfig.h.

◆ values_

std::vector<std::string> ripple::Section::values_
private

Definition at line 48 of file BasicConfig.h.

◆ had_trailing_comments_

bool ripple::Section::had_trailing_comments_ = false
private

Definition at line 49 of file BasicConfig.h.