diff options
| author | 2020-11-11 02:25:06 +0000 | |
|---|---|---|
| committer | 2020-11-11 02:29:36 +0000 | |
| commit | 2d6d47b489d733ca3c29fc2f963d424029fcb929 (patch) | |
| tree | fa38bdd2dcbebdb126d29482bfb7d5389a10c2d4 /src/modules | |
| parent | Convert FOREACH_MOD_CUSTOM to a variadic function. (diff) | |
| download | inspircd++-2d6d47b489d733ca3c29fc2f963d424029fcb929.tar.gz inspircd++-2d6d47b489d733ca3c29fc2f963d424029fcb929.tar.bz2 inspircd++-2d6d47b489d733ca3c29fc2f963d424029fcb929.zip | |
Add stdalgo::equal_range and switch more stuff to iterator_range.
Diffstat (limited to 'src/modules')
| -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 |
4 files changed, 18 insertions, 27 deletions
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); |
