28 m_map.insert(
value ) ;
31G::OptionMap::Range G::OptionMap::findRange(
string_view key )
const
33 return m_map.equal_range( sv_to_string(key) ) ;
36G::OptionMap::Map::iterator G::OptionMap::findFirst( string_view key )
38 return m_map.find( sv_to_string(key) ) ;
43 auto pair = findRange( key ) ;
44 return pair.first == pair.second ? m_map.end() : pair.first ;
49 auto pair = findRange( key ) ;
50 if( pair.first != pair.second )
51 m_map.erase( pair.first , pair.second ) ;
52 m_map.insert( Map::value_type(sv_to_string(key),
OptionValue(value)) ) ;
57 auto p = findFirst( key ) ;
58 if( p != m_map.end() )
59 (*p).second.increment() ;
64 return m_map.begin() ;
93 auto range = findRange( key ) ;
94 for(
auto p = range.first ; p != range.second ; ++p )
96 if( (*p).second.isOff() )
116 auto pair = findRange( key ) ;
117 for(
auto p = pair.first ; p != pair.second ; ++p )
118 n += (*p).second.count() ;
124 auto range = findRange( key ) ;
125 if( range.first == range.second )
126 return sv_to_string(default_) ;
128 return join( range.first , range.second , default_ ) ;
131std::string G::OptionMap::join( Map::const_iterator p , Map::const_iterator end ,
string_view off_value )
const
134 const char * sep =
"" ;
135 for( ; p != end ; ++p )
137 result.append( sep ) ; sep =
"," ;
138 result.append( (*p).second.value() ) ;
139 if( (*p).second.isOn() )
140 return (*p).second.value() ;
141 if( (*p).second.isOff() )
142 return sv_to_string(off_value) ;
const_iterator cend() const
Returns the off-the-end iterator.
void replace(string_view key, const std::string &value)
Replaces all matching values with a single value.
void clear()
Clears the map.
std::size_t count(string_view key) const
Returns the total repeat count for all matching entries.
bool contains(string_view) const
Returns true if the map contains the given key, but ignoring 'off' option-values.
unsigned int number(string_view key, unsigned int default_) const
Returns the matching value as a number.
const_iterator cbegin() const
Returns the begin iterator.
const_iterator end() const
Returns the off-the-end iterator.
void insert(const Map::value_type &)
Inserts the key/value pair into the map.
void increment(string_view key)
Increments the repeat count for the given entry.
const_iterator find(string_view) const
Finds the map entry with the given key.
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 e...
const_iterator begin() const
Returns the begin iterator.
A simple structure encapsulating the value of a command-line option.
static unsigned int toUInt(string_view s)
Converts string 's' to an unsigned int.
static bool isUInt(string_view s) noexcept
Returns true if the string can be converted into an unsigned integer without throwing an exception.
A class like c++17's std::string_view.