diff options
| author | 2020-11-11 02:25:06 +0000 | |
|---|---|---|
| committer | 2020-11-11 02:29:36 +0000 | |
| commit | 2d6d47b489d733ca3c29fc2f963d424029fcb929 (patch) | |
| tree | fa38bdd2dcbebdb126d29482bfb7d5389a10c2d4 /src | |
| parent | Convert FOREACH_MOD_CUSTOM to a variadic function. (diff) | |
Add stdalgo::equal_range and switch more stuff to iterator_range.
Diffstat (limited to 'src')
| -rw-r--r-- | src/configreader.cpp | 18 | ||||
| -rw-r--r-- | src/mode.cpp | 12 | ||||
| -rw-r--r-- | src/modules/m_alias.cpp | 24 | ||||
| -rw-r--r-- | src/modules/m_chanlog.cpp | 9 | ||||
| -rw-r--r-- | src/modules/m_customtitle.cpp | 6 | ||||
| -rw-r--r-- | src/modules/m_vhost.cpp | 6 |
6 files changed, 30 insertions, 45 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp index dd99f5b92..f818d997d 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -616,21 +616,21 @@ void ServerConfig::ApplyModules(User* user) std::shared_ptr<ConfigTag> ServerConfig::ConfValue(const std::string& tag) { - auto found = config_data.equal_range(tag); - if (found.first == found.second) + auto tags = stdalgo::equal_range(config_data, tag); + if (tags.empty()) return EmptyTag; - std::shared_ptr<ConfigTag> rv = found.first->second; - found.first++; - if (found.first != found.second) - ServerInstance->Logs.Log("CONFIG", LOG_DEFAULT, "Multiple <" + tag + "> tags found; only first will be used " - "(first at " + rv->source.str() + "; second at " + found.first->second->source.str() + ")"); - return rv; + if (tags.count() > 1) + { + ServerInstance->Logs.Log("CONFIG", LOG_DEFAULT, "Multiple (%zu) <%s> tags found; only the first will be used (first at %s, last at %s)", + tags.count(), tag.c_str(), tags.begin()->second->source.str().c_str(), std::prev(tags.end())->second->source.str().c_str()); + } + return tags.begin()->second; } ServerConfig::TagList ServerConfig::ConfTags(const std::string& tag) { - return ServerConfig::TagList(config_data.equal_range(tag)); + return stdalgo::equal_range(config_data, tag); } std::string ServerConfig::Escape(const std::string& str) diff --git a/src/mode.cpp b/src/mode.cpp index 46dd502e0..64f844e28 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -297,10 +297,8 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode } // Ask mode watchers whether this mode change is OK - std::pair<ModeWatcherMap::iterator, ModeWatcherMap::iterator> itpair = modewatchermap.equal_range(mh->name); - for (ModeWatcherMap::iterator i = itpair.first; i != itpair.second; ++i) + for (const auto& [_, mw] : stdalgo::equal_range(modewatchermap, mh->name)) { - ModeWatcher* mw = i->second; if (mw->GetModeType() == type) { if (!mw->BeforeMode(user, targetuser, chan, parameter, adding)) @@ -337,10 +335,8 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode if (ma != MODEACTION_ALLOW) return ma; - itpair = modewatchermap.equal_range(mh->name); - for (ModeWatcherMap::iterator i = itpair.first; i != itpair.second; ++i) + for (const auto& [_, mw] : stdalgo::equal_range(modewatchermap, mh->name)) { - ModeWatcher* mw = i->second; if (mw->GetModeType() == type) mw->AfterMode(user, targetuser, chan, parameter, adding); } @@ -502,10 +498,8 @@ void ModeParser::ShowListModeList(User* user, Channel* chan, ModeHandler* mh) bool display = true; // Ask mode watchers whether it's OK to show the list - std::pair<ModeWatcherMap::iterator, ModeWatcherMap::iterator> itpair = modewatchermap.equal_range(mh->name); - for (ModeWatcherMap::iterator i = itpair.first; i != itpair.second; ++i) + for (const auto& [_, mw] : stdalgo::equal_range(modewatchermap, mh->name)) { - ModeWatcher* mw = i->second; if (mw->GetModeType() == MODETYPE_CHANNEL) { std::string dummyparam; diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 21a5c2053..88f00737c 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -166,8 +166,8 @@ class ModuleAlias : public Module return MOD_RES_PASSTHRU; /* We dont have any commands looking like this? Stop processing. */ - std::pair<AliasMap::iterator, AliasMap::iterator> iters = Aliases.equal_range(command); - if (iters.first == iters.second) + auto aliases = stdalgo::equal_range(Aliases, command); + if (aliases.empty()) return MOD_RES_PASSTHRU; /* The parameters for the command in their original form, with the command stripped off */ @@ -176,11 +176,11 @@ class ModuleAlias : public Module while (*(compare.c_str()) == ' ') compare.erase(compare.begin()); - for (AliasMap::iterator i = iters.first; i != iters.second; ++i) + for (const auto& [_, alias] : aliases) { - if (i->second.UserCommand) + if (alias.UserCommand) { - if (DoAlias(user, NULL, &(i->second), compare, original_line)) + if (DoAlias(user, NULL, &alias, compare, original_line)) { return MOD_RES_DENY; } @@ -240,8 +240,8 @@ class ModuleAlias : public Module // nor do we give a shit about the prefix scommand.erase(0, fprefix.size()); - std::pair<AliasMap::iterator, AliasMap::iterator> iters = Aliases.equal_range(scommand); - if (iters.first == iters.second) + auto aliases = stdalgo::equal_range(Aliases, scommand); + if (aliases.empty()) return; /* The parameters for the command in their original form, with the command stripped off */ @@ -249,19 +249,19 @@ class ModuleAlias : public Module while (*(compare.c_str()) == ' ') compare.erase(compare.begin()); - for (AliasMap::iterator i = iters.first; i != iters.second; ++i) + for (const auto& [_, alias] : aliases) { - if (i->second.ChannelCommand) + if (alias.ChannelCommand) { // We use substr here to remove the fantasy prefix - if (DoAlias(user, c, &(i->second), compare, details.text.substr(fprefix.size()))) + if (DoAlias(user, c, &alias, compare, details.text.substr(fprefix.size()))) return; } } } - int DoAlias(User *user, Channel *c, Alias *a, const std::string& compare, const std::string& safe) + int DoAlias(User *user, Channel *c, const Alias *a, const std::string& compare, const std::string& safe) { std::string stripped(compare); if (a->StripColor) @@ -315,7 +315,7 @@ class ModuleAlias : public Module } } - void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line, Alias* a) + void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line, const Alias* a) { std::string result; result.reserve(newline.length()); diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp index 860067e5b..1d6c96282 100644 --- a/src/modules/m_chanlog.cpp +++ b/src/modules/m_chanlog.cpp @@ -64,15 +64,14 @@ class ModuleChanLog : public Module ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg) override { - std::pair<ChanLogTargets::const_iterator, ChanLogTargets::const_iterator> itpair = logstreams.equal_range(sno); - if (itpair.first == itpair.second) + auto channels = stdalgo::equal_range(logstreams, sno); + if (channels.empty()) return MOD_RES_PASSTHRU; const std::string snotice = "\002" + desc + "\002: " + msg; - - for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it) + for (const auto& [_, channel] : channels) { - Channel *c = ServerInstance->FindChan(it->second); + Channel* c = ServerInstance->FindChan(channel); if (c) { ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->Config->ServerName, c, snotice); diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index 6dca396ac..d98ded7b7 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -66,7 +66,6 @@ struct CustomTitle }; typedef std::multimap<std::string, CustomTitle> CustomVhostMap; -typedef std::pair<CustomVhostMap::iterator, CustomVhostMap::iterator> MatchingConfigs; /** Handle /TITLE */ @@ -85,11 +84,8 @@ class CommandTitle : public Command CmdResult Handle(User* user, const Params& parameters) override { - MatchingConfigs matching = configs.equal_range(parameters[0]); - - for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i) + for (const auto& [_, config] : stdalgo::equal_range(configs, parameters[0])) { - CustomTitle config = i->second; if (config.MatchUser(user) && config.CheckPass(user, parameters[1])) { ctitle.set(user, config.title); diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp index b5f47b7cd..615272ef0 100644 --- a/src/modules/m_vhost.cpp +++ b/src/modules/m_vhost.cpp @@ -48,7 +48,6 @@ struct CustomVhost }; typedef std::multimap<std::string, CustomVhost> CustomVhostMap; -typedef std::pair<CustomVhostMap::iterator, CustomVhostMap::iterator> MatchingConfigs; /** Handle /VHOST */ @@ -65,11 +64,8 @@ class CommandVhost : public Command CmdResult Handle(User* user, const Params& parameters) override { - MatchingConfigs matching = vhosts.equal_range(parameters[0]); - - for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i) + for (const auto& [_, config] : stdalgo::equal_range(vhosts, parameters[0])) { - CustomVhost config = i->second; if (config.CheckPass(user, parameters[1])) { user->WriteNotice("Setting your VHost: " + config.vhost); |
