21 #ifndef G_OPTION_MAP_H
22 #define G_OPTION_MAP_H
41 typedef std::multimap<std::string,OptionValue> Map ;
42 typedef Map::value_type value_type ;
43 typedef Map::iterator iterator ;
44 typedef Map::const_iterator const_iterator ;
50 void insert(
const Map::value_type & ) ;
55 const_iterator
begin()
const ;
58 const_iterator
end()
const ;
61 const_iterator
find(
const std::string & )
const ;
67 bool contains(
const std::string & )
const ;
71 size_t count(
const std::string & key )
const ;
74 std::string
value(
const std::string & key )
const ;
80 std::string join( Map::const_iterator , Map::const_iterator )
const ;
94 m_map.insert( value ) ;
100 return m_map.begin() ;
112 return m_map.find( key ) ;
124 const Map::const_iterator end = m_map.end() ;
125 for( Map::const_iterator p = m_map.find(key) ; p != end && (*p).first == key ; ++p )
127 if( (*p).second.valued() || !(*p).second.is_off() )
137 const Map::const_iterator end = m_map.end() ;
138 for( Map::const_iterator p = m_map.find(key) ; p != end && (*p).first == key ; ++p )
146 Map::const_iterator p = m_map.find( key ) ;
147 if( p == m_map.end() || !(*p).second.valued() )
148 return std::string() ;
149 else if( count(key) == 1U )
150 return (*p).second.value() ;
152 return join( p , std::upper_bound(p,m_map.end(),*p,m_map.value_comp()) ) ;
156 std::string G::OptionMap::join( Map::const_iterator p , Map::const_iterator end )
const
159 for(
const char * sep =
"" ; p != end ; ++p )
161 if( (*p).second.valued() )
163 result.append( sep ) ; sep =
"," ;
164 result.append( (*p).second.value() ) ;
size_t count(const std::string &key) const
Returns the number of times the key appears in the multimap.
bool contains(const std::string &) const
Returns true if the map contains the given key, but ignoring un-valued() 'off' options.
const_iterator begin() const
Returns the begin iterator.
std::string value(const std::string &key) const
Returns the value of the valued() option identified by the given key.
A map-like container for command-line options and their values.
const_iterator end() const
Returns the off-the-end iterator.
void insert(const Map::value_type &)
Inserts the key/value pair into the map.
OptionMap()
Default constructor for an empty map.
void clear()
Clears the map.
const_iterator find(const std::string &) const
Finds the map entry with the given key.