29 m_map.insert(
value ) ;
32G::OptionMap::Range G::OptionMap::findRange( std::string_view key )
const noexcept
36 auto first = std::find_if( m_map.cbegin() , m_map.cend() ,
37 [key](
const Map::value_type & v_){return key == v_.first ;} ) ;
38 auto second = std::find_if( first , m_map.cend() ,
39 [key](
const Map::value_type & v_){return key != v_.first ;} ) ;
40 return {first,second} ;
43G::OptionMap::Map::iterator G::OptionMap::findFirst( std::string_view key )
noexcept
46 auto result = std::find_if( m_map.begin() , m_map.end() ,
47 [key](
const Map::value_type & v_){return key == v_.first ;} ) ;
48 G_ASSERT( result == m_map.find(sv_to_string(key)) ) ;
54 auto pair = findRange( key ) ;
55 return pair.first == pair.second ? m_map.end() : pair.first ;
60 auto pair = findRange( key ) ;
61 if( pair.first != pair.second )
62 m_map.erase( pair.first , pair.second ) ;
63 m_map.insert( Map::value_type(sv_to_string(key),
OptionValue(value)) ) ;
68 auto p = findFirst( key ) ;
69 if( p != m_map.end() )
71 Map::value_type & value = *p ;
72 value.second.increment() ;
78 return m_map.cbegin() ;
107 auto range = findRange( key ) ;
108 for(
auto p = range.first ; p != range.second ; ++p )
110 if( (*p).second.isOff() )
119 return contains( std::string_view(key) ) ;
124 return contains( std::string_view(key) ) ;
130 auto pair = findRange( key ) ;
131 for(
auto p = pair.first ; p != pair.second ; ++p )
132 n += (*p).second.count() ;
138 auto range = findRange( key ) ;
139 if( range.first == range.second )
140 return sv_to_string(default_) ;
142 return join( range.first , range.second , default_ ) ;
145std::string G::OptionMap::join( Map::const_iterator p , Map::const_iterator end , std::string_view off_value )
148 const char * sep =
"" ;
149 for( ; p != end ; ++p )
151 result.append( sep ) ; sep =
"," ;
152 result.append( (*p).second.value() ) ;
153 if( (*p).second.isOn() )
154 return (*p).second.value() ;
155 if( (*p).second.isOff() )
156 return sv_to_string(off_value) ;
164 auto p = find( key ) ;
165 if( p == m_map.end() )
171 static_assert( std::is_same<
decltype(*p),
const Map::value_type&>::value ,
"" ) ;
173 const Map::value_type & value = *p ;
const_iterator find(std::string_view) const noexcept
Finds the map entry with the given key.
const_iterator begin() const noexcept
Returns the begin iterator.
void increment(std::string_view key) noexcept
Increments the repeat count for the given entry.
void replace(std::string_view key, const std::string &value)
Replaces all matching values with a single value.
const_iterator cend() const noexcept
Returns the off-the-end iterator.
const_iterator end() const noexcept
Returns the off-the-end iterator.
bool contains(std::string_view) const noexcept
Returns true if the map contains the given key, but ignoring 'off' option-values.
const_iterator cbegin() const noexcept
Returns the begin iterator.
unsigned int number(std::string_view key, unsigned int default_) const noexcept
Returns the matching value as a number.
void clear()
Clears the map.
std::string value(std::string_view key, std::string_view default_={}) const
Returns the matching value, with concatentation into a comma-separated list if multivalued (with no e...
std::size_t count(std::string_view key) const noexcept
Returns the total repeat count for all matching entries.
void insert(const Map::value_type &)
Inserts the key/value pair into the map.
A simple structure encapsulating the value of a command-line option.
static bool isUInt(std::string_view s) noexcept
Returns true if the string can be converted into an unsigned integer without throwing an exception.
static unsigned int toUInt(std::string_view s)
Converts string 's' to an unsigned int.