E-MailRelay
Public Types | Public Member Functions | List of all members
G::OptionMap Class Reference

A multimap-like container for command-line options and their values. More...

#include <goptionmap.h>

Public Types

using Map = std::multimap< std::string, OptionValue, std::less< std::string > >
 
using value_type = Map::value_type
 
using iterator = Map::iterator
 
using const_iterator = Map::const_iterator
 

Public Member Functions

void insert (const Map::value_type &)
 Inserts the key/value pair into the map. More...
 
void replace (string_view key, const std::string &value)
 Replaces all matching values with a single value. More...
 
void increment (string_view key)
 Increments the repeat count for the given entry. More...
 
const_iterator begin () const
 Returns the begin iterator. More...
 
const_iterator cbegin () const
 Returns the begin iterator. More...
 
const_iterator end () const
 Returns the off-the-end iterator. More...
 
const_iterator cend () const
 Returns the off-the-end iterator. More...
 
const_iterator find (string_view) const
 Finds the map entry with the given key. More...
 
void clear ()
 Clears the map. More...
 
bool contains (string_view) const
 Returns true if the map contains the given key, but ignoring 'off' option-values. More...
 
bool contains (const char *) const
 Overload for c-string. More...
 
bool contains (const std::string &) const
 Overload for std-string. More...
 
std::size_t count (string_view key) const
 Returns the total repeat count for all matching entries. More...
 
std::string value (string_view key, string_view default_={}) const
 Returns the matching value, with concatentation into a comma-separated list if multivalued (with no escaping). More...
 
unsigned int number (string_view key, unsigned int default_) const
 Returns the matching value as a number. More...
 

Detailed Description

A multimap-like container for command-line options and their values.

The values are G::OptionValue objects, so they can be valued with a string value or unvalued with an on/off status, and they can have a repeat-count. Normally populated by G::OptionParser.

Definition at line 42 of file goptionmap.h.

Member Typedef Documentation

◆ const_iterator

using G::OptionMap::const_iterator = Map::const_iterator

Definition at line 48 of file goptionmap.h.

◆ iterator

using G::OptionMap::iterator = Map::iterator

Definition at line 47 of file goptionmap.h.

◆ Map

using G::OptionMap::Map = std::multimap<std::string,OptionValue,std::less<std::string> >

Definition at line 45 of file goptionmap.h.

◆ value_type

using G::OptionMap::value_type = Map::value_type

Definition at line 46 of file goptionmap.h.

Member Function Documentation

◆ begin()

G::OptionMap::const_iterator G::OptionMap::begin ( ) const

Returns the begin iterator.

Definition at line 62 of file goptionmap.cpp.

◆ cbegin()

G::OptionMap::const_iterator G::OptionMap::cbegin ( ) const

Returns the begin iterator.

Definition at line 68 of file goptionmap.cpp.

◆ cend()

G::OptionMap::const_iterator G::OptionMap::cend ( ) const

Returns the off-the-end iterator.

Definition at line 80 of file goptionmap.cpp.

◆ clear()

void G::OptionMap::clear ( )

Clears the map.

Definition at line 86 of file goptionmap.cpp.

◆ contains() [1/3]

bool G::OptionMap::contains ( const char *  key) const

Overload for c-string.

Definition at line 103 of file goptionmap.cpp.

◆ contains() [2/3]

bool G::OptionMap::contains ( const std::string &  key) const

Overload for std-string.

Definition at line 108 of file goptionmap.cpp.

◆ contains() [3/3]

bool G::OptionMap::contains ( string_view  key) const

Returns true if the map contains the given key, but ignoring 'off' option-values.

Definition at line 91 of file goptionmap.cpp.

◆ count()

std::size_t G::OptionMap::count ( string_view  key) const

Returns the total repeat count for all matching entries.

See G::OptionValue::count().

Definition at line 113 of file goptionmap.cpp.

◆ end()

G::OptionMap::const_iterator G::OptionMap::end ( ) const

Returns the off-the-end iterator.

Definition at line 74 of file goptionmap.cpp.

◆ find()

G::OptionMap::const_iterator G::OptionMap::find ( string_view  key) const

Finds the map entry with the given key.

Definition at line 41 of file goptionmap.cpp.

◆ increment()

void G::OptionMap::increment ( string_view  key)

Increments the repeat count for the given entry.

Definition at line 55 of file goptionmap.cpp.

◆ insert()

void G::OptionMap::insert ( const Map::value_type &  value)

Inserts the key/value pair into the map.

The ordering of values in the map with the same key is in the order of insert()ion (as guaranteed by std::multimap since c++ 2011).

Definition at line 26 of file goptionmap.cpp.

◆ number()

unsigned int G::OptionMap::number ( string_view  key,
unsigned int  default_ 
) const

Returns the matching value as a number.

Definition at line 147 of file goptionmap.cpp.

◆ replace()

void G::OptionMap::replace ( string_view  key,
const std::string &  value 
)

Replaces all matching values with a single value.

Definition at line 47 of file goptionmap.cpp.

◆ value()

std::string G::OptionMap::value ( string_view  key,
string_view  default_ = {} 
) const

Returns the matching value, with concatentation into a comma-separated list if multivalued (with no escaping).

If there are any on/off option-values matching the key then a single value is returned corresponding to the first one, being G::Str::positive() if 'on' or the supplied default if 'off'.

Definition at line 122 of file goptionmap.cpp.


The documentation for this class was generated from the following files: