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

Holds a collection of configuration values. More...

Inheritance diagram for ripple::Section:
Inheritance graph
[legend]
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...
 
std::pair< std::string, bool > find (std::string const &name) const
 Retrieve a key/value pair. More...
 
template<class T >
boost::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
 

Private Attributes

std::string name_
 
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 43 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 58 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 67 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 76 of file BasicConfig.h.

◆ legacy() [1/2]

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

Set the legacy value for this section.

Definition at line 85 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 100 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 40 of file BasicConfig.cpp.

◆ append() [2/2]

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

Append a line to this section.

Definition at line 126 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 107 of file BasicConfig.cpp.

◆ find()

std::pair< std::string, bool > ripple::Section::find ( std::string const &  name) const

Retrieve a key/value pair.

Returns
A pair with bool true if the string was found.

Definition at line 113 of file BasicConfig.cpp.

◆ get()

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

Definition at line 143 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 154 of file BasicConfig.h.

◆ had_trailing_comments()

bool ripple::Section::had_trailing_comments ( ) const

Definition at line 163 of file BasicConfig.h.

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 122 of file BasicConfig.cpp.

Member Data Documentation

◆ name_

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

Definition at line 47 of file BasicConfig.h.

◆ lines_

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

Definition at line 48 of file BasicConfig.h.

◆ values_

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

Definition at line 49 of file BasicConfig.h.

◆ had_trailing_comments_

bool ripple::Section::had_trailing_comments_ = false
private

Definition at line 50 of file BasicConfig.h.