E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

goptionmap.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file goptionmap.h
19 ///
20
21 #ifndef G_OPTION_MAP_H
22 #define G_OPTION_MAP_H
23
24 #include "gdef.h"
25 #include "goptionvalue.h"
26 #include <string>
27 #include <map>
28 #include <algorithm>
29
30 namespace G
31 {
32 class OptionMap ;
33 }
34
35 /// \class G::OptionMap
36 /// A multimap-like container for command-line options and their values.
37 /// Normally populated by G::OptionParser.
38 ///
39 class G::OptionMap
40 {
41 public:
42 typedef std::multimap<std::string,OptionValue> Map ;
43 typedef Map::value_type value_type ;
44 typedef Map::iterator iterator ;
45 typedef Map::const_iterator const_iterator ;
46
47 public:
48 OptionMap() ;
49 ///< Default constructor for an empty map.
50
51 void insert( const Map::value_type & ) ;
52 ///< Inserts the key/value pair into the map. The ordering of values in the
53 ///< map with the same key is normally the order of insertion (but this
54 ///< can depend on the underlying multimap implementation).
55
56 const_iterator begin() const ;
57 ///< Returns the begin iterator.
58
59 const_iterator end() const ;
60 ///< Returns the off-the-end iterator.
61
62 const_iterator find( const std::string & ) const ;
63 ///< Finds the map entry with the given key.
64
65 void clear() ;
66 ///< Clears the map.
67
68 bool contains( const std::string & ) const ;
69 ///< Returns true if the map contains the given key, but ignoring un-valued()
70 ///< 'off' options.
71
72 bool contains( const char * ) const ;
73 ///< Overload taking a c-string.
74
75 size_t count( const std::string & key ) const ;
76 ///< Returns the number of times the key appears in the multimap.
77
78 std::string value( const std::string & key , const std::string & default_ = std::string() ) const ;
79 ///< Returns the value of the valued() option identified by the given key.
80 ///< Multiple matching values are concatenated with a comma separator
81 ///< (normally in the order of insertion).
82
83 std::string value( const char * key , const char * default_ = nullptr ) const ;
84 ///< Overload taking c-strings.
85
86 private:
87 std::string join( Map::const_iterator , Map::const_iterator ) const ;
88
89 private:
90 Map m_map ;
91 } ;
92
93 #endif
G::OptionMap::count
size_t count(const std::string &key) const
Returns the number of times the key appears in the multimap.
Definition: goptionmap.cpp:69
G::OptionMap::contains
bool contains(const std::string &) const
Returns true if the map contains the given key, but ignoring un-valued() 'off' options.
Definition: goptionmap.cpp:58
G::OptionMap::begin
const_iterator begin() const
Returns the begin iterator.
Definition: goptionmap.cpp:33
goptionvalue.h
G::OptionMap
A multimap-like container for command-line options and their values.
Definition: goptionmap.h:39
G
Low-level classes.
Definition: garg.h:29
G::OptionMap::end
const_iterator end() const
Returns the off-the-end iterator.
Definition: goptionmap.cpp:38
G::OptionMap::insert
void insert(const Map::value_type &)
Inserts the key/value pair into the map.
Definition: goptionmap.cpp:28
G::OptionMap::OptionMap
OptionMap()
Default constructor for an empty map.
Definition: goptionmap.cpp:24
G::OptionMap::value
std::string value(const std::string &key, const std::string &default_=std::string()) const
Returns the value of the valued() option identified by the given key.
Definition: goptionmap.cpp:83
G::OptionMap::clear
void clear()
Clears the map.
Definition: goptionmap.cpp:48
G::OptionMap::find
const_iterator find(const std::string &) const
Finds the map entry with the given key.
Definition: goptionmap.cpp:43