summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp33
-rw-r--r--src/base.cpp4
-rw-r--r--src/bots.cpp4
-rw-r--r--src/channels.cpp45
-rw-r--r--src/command.cpp9
-rw-r--r--src/config.cpp97
-rw-r--r--src/extensible.cpp5
-rw-r--r--src/init.cpp26
-rw-r--r--src/logger.cpp46
-rw-r--r--src/mail.cpp16
-rw-r--r--src/memos.cpp6
-rw-r--r--src/messages.cpp14
-rw-r--r--src/misc.cpp53
-rw-r--r--src/modes.cpp45
-rw-r--r--src/module.cpp4
-rw-r--r--src/modulemanager.cpp24
-rw-r--r--src/nickcore.cpp26
-rw-r--r--src/opertype.cpp48
-rw-r--r--src/protocol.cpp10
-rw-r--r--src/regchannel.cpp20
-rw-r--r--src/serialize.cpp9
-rw-r--r--src/servers.cpp67
-rw-r--r--src/uplink.cpp4
-rw-r--r--src/users.cpp27
-rw-r--r--src/xline.cpp11
25 files changed, 302 insertions, 351 deletions
diff --git a/src/access.cpp b/src/access.cpp
index baa377a02..063280809 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -62,9 +62,13 @@ static struct
Privilege::Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r)
{
if (this->desc.empty())
- for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j)
- if (descriptions[j].name.equals_ci(name))
- this->desc = descriptions[j].desc;
+ {
+ for (const auto &description : descriptions)
+ {
+ if (description.name.equals_ci(name))
+ this->desc = description.desc;
+ }
+ }
}
bool Privilege::operator==(const Privilege &other) const
@@ -94,10 +98,10 @@ void PrivilegeManager::RemovePrivilege(Privilege &p)
if (it != Privileges.end())
Privileges.erase(it);
- for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit)
+ for (const auto &[_, ci] : *RegisteredChannelList)
{
- cit->second->QueueUpdate();
- cit->second->RemoveLevel(p.name);
+ ci->QueueUpdate();
+ ci->RemoveLevel(p.name);
}
}
@@ -270,9 +274,8 @@ bool ChanAccess::Matches(const User *u, const NickCore *acc, ChannelInfo* &next)
if (acc)
{
- for (unsigned i = 0; i < acc->aliases->size(); ++i)
+ for (auto *na : *acc->aliases)
{
- const NickAlias *na = acc->aliases->at(i);
if (Anope::Match(na->nick, this->mask))
return true;
}
@@ -342,10 +345,8 @@ static bool HasPriv(const ChanAccess::Path &path, const Anope::string &name)
if (path.empty())
return false;
- for (unsigned int i = 0; i < path.size(); ++i)
+ for (auto *access : path)
{
- ChanAccess *access = path[i];
-
EventReturn MOD_RESULT;
FOREACH_RESULT(OnCheckPriv, MOD_RESULT, (access, name));
@@ -392,9 +393,9 @@ static ChanAccess *HighestInPath(const ChanAccess::Path &path)
{
ChanAccess *highest = NULL;
- for (unsigned int i = 0; i < path.size(); ++i)
- if (highest == NULL || *path[i] > *highest)
- highest = path[i];
+ for (auto *ca : path)
+ if (highest == NULL || *ca > *highest)
+ highest = ca;
return highest;
}
@@ -403,9 +404,9 @@ const ChanAccess *AccessGroup::Highest() const
{
ChanAccess *highest = NULL;
- for (unsigned int i = 0; i < paths.size(); ++i)
+ for (const auto &path : paths)
{
- ChanAccess *hip = HighestInPath(paths[i]);
+ ChanAccess *hip = HighestInPath(path);
if (highest == NULL || *hip > *highest)
highest = hip;
diff --git a/src/base.cpp b/src/base.cpp
index ba0d86d51..31b85a41c 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -17,8 +17,8 @@ Base::~Base()
{
if (this->references != NULL)
{
- for (std::set<ReferenceBase *>::iterator it = this->references->begin(), it_end = this->references->end(); it != it_end; ++it)
- (*it)->Invalidate();
+ for (auto *reference : *this->references)
+ reference->Invalidate();
delete this->references;
}
}
diff --git a/src/bots.cpp b/src/bots.cpp
index 6e78cd5d2..3a658ee17 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -131,8 +131,8 @@ void BotInfo::OnKill()
IRCD->SendClientIntroduction(this);
this->introduced = true;
- for (User::ChanUserList::const_iterator cit = this->chans.begin(), cit_end = this->chans.end(); cit != cit_end; ++cit)
- IRCD->SendJoin(this, cit->second->chan, &cit->second->status);
+ for (const auto &[_, chan] : this->chans)
+ IRCD->SendJoin(this, chan->chan, &chan->status);
}
void BotInfo::SetNewNick(const Anope::string &newnick)
diff --git a/src/channels.cpp b/src/channels.cpp
index e2249e528..5c6ba55e7 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -71,25 +71,23 @@ void Channel::Reset()
{
this->modes.clear();
- for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : this->users)
{
- ChanUserContainer *uc = it->second;
-
ChannelStatus f = uc->status;
uc->status.Clear();
/* reset modes for my clients */
if (uc->user->server == Me)
{
- for (size_t i = 0; i < f.Modes().length(); ++i)
- this->SetMode(NULL, ModeManager::FindChannelModeByChar(f.Modes()[i]), uc->user->GetUID(), false);
+ for (auto mode : f.Modes())
+ this->SetMode(NULL, ModeManager::FindChannelModeByChar(mode), uc->user->GetUID(), false);
/* Modes might not exist yet, so be sure the status is really reset */
uc->status = f;
}
}
- for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it)
- this->SetCorrectModes(it->second->user, true);
+ for (auto &[_, cuc] : this->users)
+ this->SetCorrectModes(cuc->user, true);
// If the channel is syncing now, do not force a sync due to Reset(), as we are probably iterating over users in Message::SJoin
// A sync will come soon
@@ -203,10 +201,12 @@ size_t Channel::HasMode(const Anope::string &mname, const Anope::string &param)
{
if (param.empty())
return modes.count(mname);
- std::vector<Anope::string> v = this->GetModeList(mname);
- for (unsigned int i = 0; i < v.size(); ++i)
- if (v[i].equals_ci(param))
+
+ for (const auto &mode : this->GetModeList(mname))
+ {
+ if (mode.equals_ci(param))
return 1;
+ }
return 0;
}
@@ -214,22 +214,22 @@ Anope::string Channel::GetModes(bool complete, bool plus)
{
Anope::string res, params;
- for (std::multimap<Anope::string, Anope::string>::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it)
+ for (const auto &[mode, value] : this->modes)
{
- ChannelMode *cm = ModeManager::FindChannelModeByName(it->first);
+ ChannelMode *cm = ModeManager::FindChannelModeByName(mode);
if (!cm || cm->type == MODE_LIST)
continue;
res += cm->mchar;
- if (complete && !it->second.empty())
+ if (complete && !value.empty())
{
ChannelModeParam *cmp = NULL;
if (cm->type == MODE_PARAM)
cmp = anope_dynamic_static_cast<ChannelModeParam *>(cm);
if (plus || !cmp || !cmp->minus_no_arg)
- params += " " + it->second;
+ params += " " + value;
}
}
@@ -728,10 +728,9 @@ bool Channel::MatchesList(User *u, const Anope::string &mode)
if (!this->HasMode(mode))
return false;
- std::vector<Anope::string> v = this->GetModeList(mode);
- for (unsigned i = 0; i < v.size(); ++i)
+ for (const auto &entry : this->GetModeList(mode))
{
- Entry e(mode, v[i]);
+ Entry e(mode, entry);
if (e.Matches(u))
return true;
}
@@ -845,9 +844,8 @@ void Channel::SetCorrectModes(User *user, bool give_modes)
bool giving = give_modes;
/* whether or not we have given a mode */
bool given = false;
- for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i)
+ for (auto *cm : ModeManager::GetStatusChannelModesByRank())
{
- ChannelModeStatus *cm = ModeManager::GetStatusChannelModesByRank()[i];
bool has_priv = u_access.HasPriv("AUTO" + cm->name);
if (give_modes && has_priv)
@@ -880,10 +878,9 @@ bool Channel::Unban(User *u, const Anope::string &mode, bool full)
bool ret = false;
- std::vector<Anope::string> v = this->GetModeList(mode);
- for (unsigned int i = 0; i < v.size(); ++i)
+ for (const auto &entry : this->GetModeList(mode))
{
- Entry ban(mode, v[i]);
+ Entry ban(mode, entry);
if (ban.Matches(u, full))
{
this->RemoveMode(NULL, mode, ban.GetMask());
@@ -967,10 +964,8 @@ void Channel::QueueForDeletion()
void Channel::DeleteChannels()
{
- for (unsigned int i = 0; i < deleting.size(); ++i)
+ for (auto *c : deleting)
{
- Channel *c = deleting[i];
-
if (c->CheckDelete())
delete c;
}
diff --git a/src/command.cpp b/src/command.cpp
index 94255ef4b..4205fc4a6 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -288,15 +288,10 @@ bool Command::FindCommandFromService(const Anope::string &command_service, BotIn
{
bot = NULL;
- for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
+ for (const auto &[_, bi] : *BotListByNick)
{
- BotInfo *bi = it->second;
-
- for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit)
+ for (const auto &[c_name, info] : bi->commands)
{
- const Anope::string &c_name = cit->first;
- const CommandInfo &info = cit->second;
-
if (info.name != command_service)
continue;
diff --git a/src/config.cpp b/src/config.cpp
index 1f0951183..08b82bbc2 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -154,9 +154,11 @@ Conf::Conf() : Block("")
{"networkinfo", "chanlen"},
};
- for (unsigned i = 0; i < sizeof(noreload) / sizeof(noreload[0]); ++i)
- if (this->GetBlock(noreload[i].block)->Get<const Anope::string>(noreload[i].name) != Config->GetBlock(noreload[i].block)->Get<const Anope::string>(noreload[i].name))
- throw ConfigException("<" + noreload[i].block + ":" + noreload[i].name + "> can not be modified once set");
+ for (const auto &tag : noreload)
+ {
+ if (this->GetBlock(tag.block)->Get<const Anope::string>(tag.name) != Config->GetBlock(tag.block)->Get<const Anope::string>(tag.name))
+ throw ConfigException("<" + tag.block + ":" + tag.name + "> can not be modified once set");
+ }
}
const Block *serverinfo = this->GetBlock("serverinfo"), *options = this->GetBlock("options"),
@@ -186,8 +188,8 @@ Conf::Conf() : Block("")
if (mail->Get<bool>("usemail"))
{
Anope::string check[] = { "sendmailpath", "sendfrom", "registration_subject", "registration_message", "emailchange_subject", "emailchange_message", "memo_subject", "memo_message" };
- for (unsigned i = 0; i < sizeof(check) / sizeof(Anope::string); ++i)
- ValidateNotEmpty("mail", check[i], mail->Get<const Anope::string>(check[i]));
+ for (const auto &field : check)
+ ValidateNotEmpty("mail", field, mail->Get<const Anope::string>(field));
}
this->ReadTimeout = options->Get<time_t>("readtimeout");
@@ -276,10 +278,8 @@ Conf::Conf() : Block("")
/* Strip leading ' ' after , */
if (str.length() > 1 && str[0] == ' ')
str.erase(str.begin());
- for (unsigned j = 0; j < this->MyOperTypes.size(); ++j)
+ for (auto *ot2 : this->MyOperTypes)
{
- OperType *ot2 = this->MyOperTypes[j];
-
if (ot2->GetName().equals_ci(str))
{
Log() << "Inheriting commands and privs from " << ot2->GetName() << " to " << ot->GetName();
@@ -308,9 +308,11 @@ Conf::Conf() : Block("")
ValidateNotEmpty("oper", "type", type);
OperType *ot = NULL;
- for (unsigned j = 0; j < this->MyOperTypes.size(); ++j)
- if (this->MyOperTypes[j]->GetName() == type)
- ot = this->MyOperTypes[j];
+ for (auto *opertype : this->MyOperTypes)
+ {
+ if (opertype->GetName() == type)
+ ot = opertype;
+ }
if (ot == NULL)
throw ConfigException("Oper block for " + nname + " has invalid oper type " + type);
@@ -324,8 +326,8 @@ Conf::Conf() : Block("")
this->Opers.push_back(o);
}
- for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
- it->second->conf = false;
+ for (const auto &[_, bi] : *BotListByNick)
+ bi->conf = false;
for (int i = 0; i < this->CountBlock("service"); ++i)
{
const Block *service = this->GetBlock("service", i);
@@ -373,28 +375,30 @@ Conf::Conf() : Block("")
/* Remove all existing modes */
ChanUserContainer *cu = c->FindUser(bi);
if (cu != NULL)
- for (size_t j = 0; j < cu->status.Modes().length(); ++j)
- c->RemoveMode(bi, ModeManager::FindChannelModeByChar(cu->status.Modes()[j]), bi->GetUID());
+ {
+ for (auto mode : cu->status.Modes())
+ c->RemoveMode(bi, ModeManager::FindChannelModeByChar(mode), bi->GetUID());
+ }
/* Set the new modes */
- for (unsigned j = 0; j < want_modes.length(); ++j)
+ for (char want_mode : want_modes)
{
- ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(want_mode);
if (cm == NULL)
- cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j]));
+ cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_mode));
if (cm && cm->type == MODE_STATUS)
c->SetMode(bi, cm, bi->GetUID());
}
}
- for (unsigned k = 0; k < oldchannels.size(); ++k)
+ for (const auto &oldchannel : oldchannels)
{
- size_t ch = oldchannels[k].find('#');
- Anope::string chname = oldchannels[k].substr(ch != Anope::string::npos ? ch : 0);
+ size_t ch = oldchannel.find('#');
+ Anope::string chname = oldchannel.substr(ch != Anope::string::npos ? ch : 0);
bool found = false;
- for (unsigned j = 0; j < bi->botchannels.size(); ++j)
+ for (const auto &botchannel : bi->botchannels)
{
- ch = bi->botchannels[j].find('#');
- Anope::string ochname = bi->botchannels[j].substr(ch != Anope::string::npos ? ch : 0);
+ ch = botchannel.find('#');
+ Anope::string ochname = botchannel.substr(ch != Anope::string::npos ? ch : 0);
if (chname.equals_ci(ochname))
found = true;
@@ -436,8 +440,8 @@ Conf::Conf() : Block("")
this->LogInfos.push_back(l);
}
- for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
- it->second->commands.clear();
+ for (const auto &[_, bi] : *BotListByNick)
+ bi->commands.clear();
for (int i = 0; i < this->CountBlock("command"); ++i)
{
const Block *command = this->GetBlock("command", i);
@@ -514,17 +518,14 @@ Conf::Conf() : Block("")
if (Config)
/* Clear existing conf opers */
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- NickCore *nc = it->second;
if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end())
nc->o = NULL;
}
/* Apply new opers */
- for (unsigned i = 0; i < this->Opers.size(); ++i)
+ for (auto *o : this->Opers)
{
- Oper *o = this->Opers[i];
-
NickAlias *na = NickAlias::Find(o->name);
if (!na)
continue;
@@ -564,21 +565,27 @@ Conf::Conf() : Block("")
Conf::~Conf()
{
- for (unsigned i = 0; i < MyOperTypes.size(); ++i)
- delete MyOperTypes[i];
- for (unsigned i = 0; i < Opers.size(); ++i)
- delete Opers[i];
+ for (const auto *opertype : MyOperTypes)
+ delete opertype;
+
+ for (const auto *oper : Opers)
+ delete oper;
}
void Conf::Post(Conf *old)
{
/* Apply module changes */
- for (unsigned i = 0; i < old->ModulesAutoLoad.size(); ++i)
- if (std::find(this->ModulesAutoLoad.begin(), this->ModulesAutoLoad.end(), old->ModulesAutoLoad[i]) == this->ModulesAutoLoad.end())
- ModuleManager::UnloadModule(ModuleManager::FindModule(old->ModulesAutoLoad[i]), NULL);
- for (unsigned i = 0; i < this->ModulesAutoLoad.size(); ++i)
- if (std::find(old->ModulesAutoLoad.begin(), old->ModulesAutoLoad.end(), this->ModulesAutoLoad[i]) == old->ModulesAutoLoad.end())
- ModuleManager::LoadModule(this->ModulesAutoLoad[i], NULL);
+ for (const auto &mod : old->ModulesAutoLoad)
+ {
+ if (std::find(this->ModulesAutoLoad.begin(), this->ModulesAutoLoad.end(), mod) == this->ModulesAutoLoad.end())
+ ModuleManager::UnloadModule(ModuleManager::FindModule(mod), NULL);
+ }
+
+ for (const auto &mod : this->ModulesAutoLoad)
+ {
+ if (std::find(old->ModulesAutoLoad.begin(), old->ModulesAutoLoad.end(), mod) == old->ModulesAutoLoad.end())
+ ModuleManager::LoadModule(mod, NULL);
+ }
/* Apply opertype changes, as non-conf opers still point to the old oper types */
for (unsigned i = Oper::opers.size(); i > 0; --i)
@@ -591,9 +598,11 @@ void Conf::Post(Conf *old)
OperType *ot = o->ot;
o->ot = NULL;
- for (unsigned j = 0; j < MyOperTypes.size(); ++j)
- if (ot->GetName() == MyOperTypes[j]->GetName())
- o->ot = MyOperTypes[j];
+ for (auto *opertype : MyOperTypes)
+ {
+ if (ot->GetName() == opertype->GetName())
+ o->ot = opertype;
+ }
if (o->ot == NULL)
{
diff --git a/src/extensible.cpp b/src/extensible.cpp
index 05ab7c5ac..06ffeeb3f 100644
--- a/src/extensible.cpp
+++ b/src/extensible.cpp
@@ -52,10 +52,9 @@ void Extensible::ExtensibleSerialize(const Extensible *e, const Serializable *s,
void Extensible::ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data)
{
- for (std::set<ExtensibleBase *>::iterator it = extensible_items.begin(); it != extensible_items.end(); ++it)
+ for (auto *extensible_item : extensible_items)
{
- ExtensibleBase *eb = *it;
- eb->ExtensibleUnserialize(e, s, data);
+ extensible_item->ExtensibleUnserialize(e, s, data);
}
}
diff --git a/src/init.cpp b/src/init.cpp
index cb94d77f6..a0c46cb2f 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -71,11 +71,11 @@ static bool GetCommandLineArgument(const Anope::string &name, char shortname, An
{
param.clear();
- for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = CommandLineArguments.begin(), it_end = CommandLineArguments.end(); it != it_end; ++it)
+ for (const auto &[argument, value] : CommandLineArguments)
{
- if (it->first.equals_ci(name) || (it->first.length() == 1 && it->first[0] == shortname))
+ if (argument.equals_ci(name) || (argument.length() == 1 && argument[0] == shortname))
{
- param = it->second;
+ param = argument;
return true;
}
}
@@ -258,14 +258,10 @@ static void setuidgid()
gid = g->gr_gid;
}
- for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
+ for (const auto &li : Config->LogInfos)
{
- LogInfo& li = Config->LogInfos[i];
-
- for (unsigned j = 0; j < li.logfiles.size(); ++j)
+ for (const auto *lf : li.logfiles)
{
- LogFile* lf = li.logfiles[j];
-
errno = 0;
if (chown(lf->filename.c_str(), uid, gid) != 0)
Log() << "Unable to change the ownership of " << lf->filename << " to " << uid << "/" << gid << ": " << Anope::LastError();
@@ -489,9 +485,9 @@ void Anope::Init(int ac, char **av)
/* Create me */
Configuration::Block *block = Config->GetBlock("serverinfo");
Me = new Server(NULL, block->Get<const Anope::string>("name"), 0, block->Get<const Anope::string>("description"), block->Get<const Anope::string>("id"));
- for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
+ for (const auto &[_, bi] : *BotListByNick)
{
- it->second->server = Me;
+ bi->server = Me;
++Me->users;
}
@@ -547,8 +543,8 @@ void Anope::Init(int ac, char **av)
Anope::string sid = IRCD->SID_Retrieve();
if (Me->GetSID() == Me->GetName())
Me->SetSID(sid);
- for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
- it->second->GenerateUID();
+ for (const auto &[_, bi] : *BotListByNick)
+ bi->GenerateUID();
}
/* Load up databases */
@@ -560,8 +556,8 @@ void Anope::Init(int ac, char **av)
FOREACH_MOD(OnPostInit, ());
- for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
- it->second->Sync();
+ for (const auto &[_, ci] : ChannelList)
+ ci->Sync();
Serialize::CheckTypes();
}
diff --git a/src/logger.cpp b/src/logger.cpp
index 532369c3b..fb4b4bea8 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -130,9 +130,13 @@ Log::~Log()
FOREACH_MOD(OnLog, (this));
if (Config)
- for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
- if (Config->LogInfos[i].HasType(this->type, this->category))
- Config->LogInfos[i].ProcessMessage(this);
+ {
+ for (auto &li : Config->LogInfos)
+ {
+ if (li.HasType(this->type, this->category))
+ li.ProcessMessage(this);
+ }
+ }
}
Anope::string Log::FormatSource() const
@@ -232,8 +236,8 @@ LogInfo::LogInfo(int la, bool rio, bool ldebug) : log_age(la), raw_io(rio), debu
LogInfo::~LogInfo()
{
- for (unsigned i = 0; i < this->logfiles.size(); ++i)
- delete this->logfiles[i];
+ for (const auto *logfile : this->logfiles)
+ delete logfile;
this->logfiles.clear();
}
@@ -280,16 +284,15 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const
if (list == NULL)
return false;
- for (unsigned i = 0; i < list->size(); ++i)
+ for (auto value : *list)
{
- Anope::string cat = list->at(i);
bool inverse = false;
- if (cat[0] == '~')
+ if (value[0] == '~')
{
- cat.erase(cat.begin());
+ value.erase(value.begin());
inverse = true;
}
- if (Anope::Match(type, cat))
+ if (Anope::Match(type, value))
{
return !inverse;
}
@@ -300,14 +303,12 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const
void LogInfo::OpenLogFiles()
{
- for (unsigned i = 0; i < this->logfiles.size(); ++i)
- delete this->logfiles[i];
+ for (const auto *logfile : this->logfiles)
+ delete logfile;
this->logfiles.clear();
- for (unsigned i = 0; i < this->targets.size(); ++i)
+ for (const auto &target : this->targets)
{
- const Anope::string &target = this->targets[i];
-
if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos)
continue;
@@ -352,10 +353,8 @@ void LogInfo::ProcessMessage(const Log *l)
FOREACH_MOD(OnLogMessage, (this, l, buffer));
- for (unsigned i = 0; i < this->targets.size(); ++i)
+ for (const auto &target : this->targets)
{
- const Anope::string &target = this->targets[i];
-
if (!target.empty() && target[0] == '#')
{
if (UplinkSock && l->type <= LOG_NORMAL && Me && Me->IsSynced())
@@ -393,11 +392,10 @@ void LogInfo::ProcessMessage(const Log *l)
this->OpenLogFiles();
if (this->log_age)
- for (unsigned i = 0; i < this->targets.size(); ++i)
+ {
+ for (const auto &target : this->targets)
{
- const Anope::string &target = this->targets[i];
-
- if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos)
+ if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos)
continue;
Anope::string oldlog = CreateLogName(target, Anope::CurTime - 86400 * this->log_age);
@@ -407,11 +405,11 @@ void LogInfo::ProcessMessage(const Log *l)
Log(LOG_DEBUG) << "Deleted old logfile " << oldlog;
}
}
+ }
}
- for (unsigned i = 0; i < this->logfiles.size(); ++i)
+ for (auto *lf : this->logfiles)
{
- LogFile *lf = this->logfiles[i];
lf->stream << GetTimeStamp() << " " << buffer << std::endl;
}
}
diff --git a/src/mail.cpp b/src/mail.cpp
index 7ad9c75f2..3f24e3a54 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -144,13 +144,15 @@ bool Mail::Validate(const Anope::string &email)
return false;
/* Check for forbidden characters in the name */
- for (unsigned i = 0, end = copy.length(); i < end; ++i)
+ for (auto chr : copy)
{
- if (copy[i] <= 31 || copy[i] >= 127)
+ if (chr <= 31 || chr >= 127)
return false;
- for (unsigned int j = 0; j < 13; ++j)
- if (copy[i] == specials[j])
+ for (auto special : specials)
+ {
+ if (chr == special)
return false;
+ }
}
/* Check for forbidden characters in the domain */
@@ -158,9 +160,11 @@ bool Mail::Validate(const Anope::string &email)
{
if (domain[i] <= 31 || domain[i] >= 127)
return false;
- for (unsigned int j = 0; j < 13; ++j)
- if (domain[i] == specials[j])
+ for (auto special : specials)
+ {
+ if (domain[i] == special)
return false;
+ }
if (domain[i] == '.')
{
if (!i || i == end - 1)
diff --git a/src/memos.cpp b/src/memos.cpp
index 3393e958b..03cd7f77d 100644
--- a/src/memos.cpp
+++ b/src/memos.cpp
@@ -113,9 +113,11 @@ void MemoInfo::Del(unsigned index)
bool MemoInfo::HasIgnore(User *u)
{
- for (unsigned i = 0; i < this->ignores.size(); ++i)
- if (u->nick.equals_ci(this->ignores[i]) || (u->Account() && u->Account()->display.equals_ci(this->ignores[i])) || Anope::Match(u->GetMask(), Anope::string(this->ignores[i])))
+ for (const auto &ignore : this->ignores)
+ {
+ if (u->nick.equals_ci(ignore) || (u->Account() && u->Account()->display.equals_ci(ignore)) || Anope::Match(u->GetMask(), Anope::string(ignore)))
return true;
+ }
return false;
}
diff --git a/src/messages.cpp b/src/messages.cpp
index 701df60a1..2aaae177f 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -43,8 +43,10 @@ void Capab::Run(MessageSource &source, const std::vector<Anope::string> &params,
Servers::Capab.insert(token);
}
else
- for (unsigned i = 0; i < params.size(); ++i)
- Servers::Capab.insert(params[i]);
+ {
+ for (const auto &param : params)
+ Servers::Capab.insert(param);
+ }
}
void Error::Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags)
@@ -127,10 +129,8 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
*/
c->SetModesInternal(source, modes, ts, !c->syncing);
- for (std::list<SJoinUser>::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it)
+ for (const auto &[status, u] : users)
{
- const ChannelStatus &status = it->first;
- User *u = it->second;
keep_their_modes = ts <= c->creation_time; // OnJoinChannel can call modules which can modify this channel's ts
if (c->FindUser(u))
@@ -426,10 +426,8 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params,
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
else
{
- for (unsigned i = 0; i < Oper::opers.size(); ++i)
+ for (auto *o : Oper::opers)
{
- Oper *o = Oper::opers[i];
-
const NickAlias *na = NickAlias::Find(o->name);
if (na)
IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().replace_all_cs(" ", "_").c_str());
diff --git a/src/misc.cpp b/src/misc.cpp
index 0728daab1..39c688ea6 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -102,8 +102,8 @@ void NumberList::Process()
}
else
{
- for (std::set<unsigned>::iterator it = numbers.begin(), it_end = numbers.end(); it != it_end; ++it)
- this->HandleNumber(*it);
+ for (unsigned int number : numbers)
+ this->HandleNumber(number);
}
}
@@ -141,29 +141,30 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer)
std::vector<Anope::string> tcolumns;
std::map<Anope::string, size_t> lengths;
std::set<Anope::string> breaks;
- for (unsigned i = 0; i < this->columns.size(); ++i)
+ for (const auto &column : this->columns)
{
- tcolumns.emplace_back(Language::Translate(this->nc, this->columns[i].c_str()));
- lengths[this->columns[i]] = tcolumns[i].length();
+ tcolumns.emplace_back(Language::Translate(this->nc, column.c_str()));
+ lengths[column] = column.length();
}
- for (unsigned i = 0; i < this->entries.size(); ++i)
+ for (auto &entry : this->entries)
{
- ListEntry &e = this->entries[i];
- for (unsigned j = 0; j < this->columns.size(); ++j)
- if (e[this->columns[j]].length() > lengths[this->columns[j]])
- lengths[this->columns[j]] = e[this->columns[j]].length();
+ for (const auto &column : this->columns)
+ {
+ if (entry[column].length() > lengths[column])
+ lengths[column] = entry[column].length();
+ }
}
- unsigned length = 0;
- for (std::map<Anope::string, size_t>::iterator it = lengths.begin(), it_end = lengths.end(); it != it_end; ++it)
+ unsigned total_length = 0;
+ for (const auto &[column, length] : lengths)
{
/* Break lines at 80 chars */
- if (length > 80)
+ if (total_length > 80)
{
- breaks.insert(it->first);
- length = 0;
+ breaks.insert(column);
+ total_length = 0;
}
else
- length += it->second;
+ total_length += length;
}
/* Only put a list header if more than 1 column */
@@ -187,10 +188,8 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer)
buffer.push_back(s);
}
- for (unsigned i = 0; i < this->entries.size(); ++i)
+ for (auto &entry : this->entries)
{
- ListEntry &e = this->entries[i];
-
Anope::string s;
for (unsigned j = 0; j < this->columns.size(); ++j)
{
@@ -201,9 +200,9 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer)
}
else if (!s.empty())
s += " ";
- s += e[this->columns[j]];
+ s += entry[this->columns[j]];
if (j + 1 != this->columns.size())
- for (unsigned k = e[this->columns[j]].length(); k < lengths[this->columns[j]]; ++k)
+ for (unsigned k = entry[this->columns[j]].length(); k < lengths[this->columns[j]]; ++k)
s += " ";
}
buffer.push_back(s);
@@ -218,12 +217,12 @@ void InfoFormatter::Process(std::vector<Anope::string> &buffer)
{
buffer.clear();
- for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = this->replies.begin(), it_end = this->replies.end(); it != it_end; ++it)
+ for (const auto &[key, value] : this->replies)
{
Anope::string s;
- for (unsigned i = it->first.length(); i < this->longest; ++i)
+ for (unsigned i = key.length(); i < this->longest; ++i)
s += " ";
- s += it->first + ": " + Language::Translate(this->nc, it->second.c_str());
+ s += key + ": " + Language::Translate(this->nc, value.c_str());
buffer.push_back(s);
}
@@ -242,11 +241,11 @@ void InfoFormatter::AddOption(const Anope::string &opt)
{
Anope::string options = Language::Translate(this->nc, "Options");
Anope::string *optstr = NULL;
- for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = this->replies.begin(), it_end = this->replies.end(); it != it_end; ++it)
+ for (auto &[option, value] : this->replies)
{
- if (it->first == options)
+ if (option == options)
{
- optstr = &it->second;
+ optstr = &value;
break;
}
}
diff --git a/src/modes.cpp b/src/modes.cpp
index be2a5fab1..6c46302de 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -95,9 +95,9 @@ Anope::string ChannelStatus::BuildModePrefixList() const
{
Anope::string ret;
- for (size_t i = 0; i < modes.length(); ++i)
+ for (auto mode : modes)
{
- ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(mode);
if (cm != NULL && cm->type == MODE_STATUS)
{
ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm);
@@ -144,9 +144,9 @@ ChannelMode *ChannelMode::Wrap(Anope::string &param)
ChannelMode *ChannelMode::Unwrap(Anope::string &param)
{
- for (unsigned i = 0; i < listeners.size(); ++i)
+ for (auto *listener : listeners)
{
- ChannelMode *cm = listeners[i]->Unwrap(this, param);
+ ChannelMode *cm = listener->Unwrap(this, param);
if (cm != this)
return cm;
}
@@ -446,8 +446,8 @@ bool ModeManager::AddChannelMode(ChannelMode *cm)
FOREACH_MOD(OnChannelModeAdd, (cm));
- for (unsigned int i = 0; i < ChannelModes.size(); ++i)
- ChannelModes[i]->Check();
+ for (auto *cmode : ChannelModes)
+ cmode->Check();
return true;
}
@@ -590,10 +590,8 @@ static struct StatusSort
void ModeManager::RebuildStatusModes()
{
ChannelModesByStatus.clear();
- for (unsigned j = 0; j < ChannelModesIdx.size(); ++j)
+ for (auto *cm : ChannelModesIdx)
{
- ChannelMode *cm = ChannelModesIdx[j];
-
if (cm && cm->type == MODE_STATUS && std::find(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), cm) == ChannelModesByStatus.end())
ChannelModesByStatus.push_back(anope_dynamic_static_cast<ChannelModeStatus *>(cm));
}
@@ -630,30 +628,22 @@ void ModeManager::ProcessModes()
{
if (!UserStackerObjects.empty())
{
- for (std::map<User *, StackerInfo *>::const_iterator it = UserStackerObjects.begin(), it_end = UserStackerObjects.end(); it != it_end; ++it)
+ for (const auto &[u, s] : UserStackerObjects)
{
- User *u = it->first;
- StackerInfo *s = it->second;
-
- std::list<Anope::string> ModeStrings = BuildModeStrings(s);
- for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit)
- IRCD->SendMode(s->bi, u, "%s", lit->c_str());
- delete it->second;
+ for (const auto &modestr : BuildModeStrings(s))
+ IRCD->SendMode(s->bi, u, "%s", modestr.c_str());
+ delete s;
}
UserStackerObjects.clear();
}
if (!ChannelStackerObjects.empty())
{
- for (std::map<Channel *, StackerInfo *>::const_iterator it = ChannelStackerObjects.begin(), it_end = ChannelStackerObjects.end(); it != it_end; ++it)
+ for (const auto &[c, s] : ChannelStackerObjects)
{
- Channel *c = it->first;
- StackerInfo *s = it->second;
-
- std::list<Anope::string> ModeStrings = BuildModeStrings(s);
- for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit)
- IRCD->SendMode(s->bi, c, "%s", lit->c_str());
- delete it->second;
+ for (const auto &modestr : BuildModeStrings(s))
+ IRCD->SendMode(s->bi, c, "%s", modestr.c_str());
+ delete s;
}
ChannelStackerObjects.clear();
}
@@ -666,9 +656,8 @@ static void StackerDel(std::map<T *, StackerInfo *> &map, T *obj)
if (it != map.end())
{
StackerInfo *si = it->second;
- std::list<Anope::string> ModeStrings = BuildModeStrings(si);
- for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit)
- IRCD->SendMode(si->bi, obj, "%s", lit->c_str());
+ for (const auto &modestr : BuildModeStrings(si))
+ IRCD->SendMode(si->bi, obj, "%s", modestr.c_str());
delete si;
map.erase(it);
diff --git a/src/module.cpp b/src/module.cpp
index 3aab9f46f..7722c7748 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -40,11 +40,11 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt
ModuleManager::Modules.push_back(this);
#if HAVE_LOCALIZATION
- for (unsigned i = 0; i < Language::Languages.size(); ++i)
+ for (const auto &language : Language::Languages)
{
/* Remove .UTF-8 or any other suffix */
Anope::string lang;
- sepstream(Language::Languages[i], '.').GetToken(lang);
+ sepstream(language, '.').GetToken(lang);
if (Anope::IsFile(Anope::LocaleDir + "/" + lang + "/LC_MESSAGES/" + modname + ".mo"))
{
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 600e7910e..38ed130f7 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -267,8 +267,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
Log(LOG_DEBUG) << "Module " << modname << " loaded.";
/* Attach module to all events */
- for (unsigned i = 0; i < I_SIZE; ++i)
- EventHandlers[i].push_back(m);
+ for (auto &mods : EventHandlers)
+ mods.push_back(m);
m->Prioritize();
@@ -307,10 +307,8 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u)
Module *ModuleManager::FindModule(const Anope::string &name)
{
- for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ for (auto *m : Modules)
{
- Module *m = *it;
-
if (m->name.equals_ci(name))
return m;
}
@@ -320,10 +318,8 @@ Module *ModuleManager::FindModule(const Anope::string &name)
Module *ModuleManager::FindFirstOf(ModType type)
{
- for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ for (auto *m : Modules)
{
- Module *m = *it;
-
if (m->type & type)
return m;
}
@@ -389,9 +385,8 @@ ModuleReturn ModuleManager::DeleteModule(Module *m)
void ModuleManager::DetachAll(Module *mod)
{
- for (unsigned i = 0; i < I_SIZE; ++i)
+ for (auto &mods : EventHandlers)
{
- std::vector<Module *> &mods = EventHandlers[i];
std::vector<Module *>::iterator it2 = std::find(mods.begin(), mods.end(), mod);
if (it2 != mods.end())
mods.erase(it2);
@@ -504,16 +499,17 @@ void ModuleManager::UnloadAll()
{
std::vector<Anope::string> modules;
for (size_t i = 1, j = 0; i != MT_END; j |= i, i <<= 1)
- for (std::list<Module *>::iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ {
+ for (auto *m : Modules)
{
- Module *m = *it;
if ((m->type & j) == m->type)
modules.push_back(m->name);
}
+ }
- for (unsigned i = 0; i < modules.size(); ++i)
+ for (auto &module : modules)
{
- Module *m = FindModule(modules[i]);
+ Module *m = FindModule(module);
if (m != NULL)
UnloadModule(m, NULL);
}
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index 4c14d8591..9d292bbf3 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -78,11 +78,11 @@ void NickCore::Serialize(Serialize::Data &data) const
data["pass"] << this->pass;
data["email"] << this->email;
data["language"] << this->language;
- for (unsigned i = 0; i < this->access.size(); ++i)
- data["access"] << this->access[i] << " ";
+ for (const auto &mask : this->access)
+ data["access"] << mask << " ";
data["memomax"] << this->memos.memomax;
- for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
- data["memoignores"] << this->memos.ignores[i] << " ";
+ for (const auto &ignore : this->memos.ignores)
+ data["memoignores"] << ignore << " ";
Extensible::ExtensibleSerialize(this, this, data);
}
@@ -171,8 +171,8 @@ void NickCore::SetDisplay(const NickAlias *na)
FOREACH_MOD(OnChangeCoreDisplay, (this, na->nick));
/* this affects the serialized aliases */
- for (unsigned i = 0; i < aliases->size(); ++i)
- aliases->at(i)->QueueUpdate();
+ for (auto *alias : *aliases)
+ alias->QueueUpdate();
/* Remove the core from the list */
NickCoreList->erase(this->display);
@@ -207,9 +207,11 @@ unsigned NickCore::GetAccessCount() const
bool NickCore::FindAccess(const Anope::string &entry)
{
- for (unsigned i = 0, end = this->access.size(); i < end; ++i)
- if (this->access[i] == entry)
+ for (const auto &mask : this->access)
+ {
+ if (mask == entry)
return true;
+ }
return false;
}
@@ -263,8 +265,8 @@ void NickCore::RemoveChannelReference(ChannelInfo *ci)
void NickCore::GetChannelReferences(std::deque<ChannelInfo *> &queue)
{
queue.clear();
- for (std::map<ChannelInfo *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it)
- queue.push_back(it->first);
+ for (const auto &[ci, _] : *this->chanaccess)
+ queue.push_back(ci);
}
NickCore* NickCore::Find(const Anope::string &nick)
@@ -300,8 +302,8 @@ uint64_t NickCore::GetId()
{
// Generate a random key for SipHash.
char key[16];
- for (size_t i = 0; i < sizeof(key); ++i)
- key[i] = rand() % CHAR_MAX;
+ for (auto &chr : key)
+ chr = rand() % CHAR_MAX;
uint64_t newid = Anope::SipHash24(secretid.c_str(), secretid.length(), key);
nickcoreid_map::const_iterator it = NickCoreIdList.find(newid);
diff --git a/src/opertype.cpp b/src/opertype.cpp
index 6a144fd3c..e7708f99f 100644
--- a/src/opertype.cpp
+++ b/src/opertype.cpp
@@ -27,10 +27,8 @@ Oper::~Oper()
Oper *Oper::Find(const Anope::string &name)
{
- for (unsigned i = 0; i < opers.size(); ++i)
+ for (auto *o : opers)
{
- Oper *o = opers[i];
-
if (o->name.equals_ci(name))
return o;
}
@@ -40,10 +38,8 @@ Oper *Oper::Find(const Anope::string &name)
OperType *OperType::Find(const Anope::string &name)
{
- for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i)
+ for (auto *ot : Config->MyOperTypes)
{
- OperType *ot = Config->MyOperTypes[i];
-
if (ot->GetName() == name)
return ot;
}
@@ -57,19 +53,15 @@ OperType::OperType(const Anope::string &nname) : name(nname)
bool OperType::HasCommand(const Anope::string &cmdstr) const
{
- for (std::list<Anope::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it)
+ for (const auto &command : this->commands)
{
- const Anope::string &s = *it;
-
- if (!s.find('~') && Anope::Match(cmdstr, s.substr(1)))
+ if (!command.find('~') && Anope::Match(cmdstr, command.substr(1)))
return false;
- else if (Anope::Match(cmdstr, s))
+ else if (Anope::Match(cmdstr, command))
return true;
}
- for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit)
+ for (auto *ot : this->inheritances)
{
- OperType *ot = *iit;
-
if (ot->HasCommand(cmdstr))
return true;
}
@@ -79,19 +71,15 @@ bool OperType::HasCommand(const Anope::string &cmdstr) const
bool OperType::HasPriv(const Anope::string &privstr) const
{
- for (std::list<Anope::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it)
+ for (const auto &priv : this->privs)
{
- const Anope::string &s = *it;
-
- if (!s.find('~') && Anope::Match(privstr, s.substr(1)))
+ if (!priv.find('~') && Anope::Match(privstr, priv.substr(1)))
return false;
- else if (Anope::Match(privstr, s))
+ else if (Anope::Match(privstr, priv))
return true;
}
- for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit)
+ for (auto *ot : this->inheritances)
{
- OperType *ot = *iit;
-
if (ot->HasPriv(privstr))
return true;
}
@@ -123,12 +111,10 @@ void OperType::Inherits(OperType *ot)
const std::list<Anope::string> OperType::GetCommands() const
{
std::list<Anope::string> cmd_list = this->commands;
- for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it)
+ for (auto *ot : this->inheritances)
{
- OperType *ot = *it;
- std::list<Anope::string> cmds = ot->GetCommands();
- for (std::list<Anope::string>::const_iterator it2 = cmds.begin(), it2_end = cmds.end(); it2 != it2_end; ++it2)
- cmd_list.push_back(*it2);
+ for (const auto &cmd : ot->GetCommands())
+ cmd_list.push_back(cmd);
}
return cmd_list;
}
@@ -136,12 +122,10 @@ const std::list<Anope::string> OperType::GetCommands() const
const std::list<Anope::string> OperType::GetPrivs() const
{
std::list<Anope::string> priv_list = this->privs;
- for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it)
+ for (auto *ot : this->inheritances)
{
- OperType *ot = *it;
- std::list<Anope::string> priv = ot->GetPrivs();
- for (std::list<Anope::string>::const_iterator it2 = priv.begin(), it2_end = priv.end(); it2 != it2_end; ++it2)
- priv_list.push_back(*it2);
+ for (const auto &priv : ot->GetPrivs())
+ priv_list.push_back(priv);
}
return priv_list;
}
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 6cba86a9b..090187819 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -389,10 +389,8 @@ bool IRCDProto::IsIdentValid(const Anope::string &ident)
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
return false;
- for (unsigned i = 0; i < ident.length(); ++i)
+ for (auto c : ident)
{
- const char &c = ident[i];
-
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
continue;
@@ -416,11 +414,11 @@ bool IRCDProto::IsHostValid(const Anope::string &host)
return false;
int dots = 0;
- for (unsigned i = 0; i < host.length(); ++i)
+ for (auto chr : host)
{
- if (host[i] == '.')
+ if (chr == '.')
++dots;
- if (vhostchars.find_first_of(host[i]) == Anope::string::npos)
+ if (vhostchars.find_first_of(chr) == Anope::string::npos)
return false;
}
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 984da55ab..966f3e1b4 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -194,16 +194,16 @@ void ChannelInfo::Serialize(Serialize::Data &data) const
data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype;
{
Anope::string levels_buffer;
- for (Anope::map<int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
- levels_buffer += it->first + " " + stringify(it->second) + " ";
+ for (const auto &[name, level] : this->levels)
+ levels_buffer += name + " " + stringify(level) + " ";
data["levels"] << levels_buffer;
}
if (this->bi)
data["bi"] << this->bi->nick;
data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire;
data["memomax"] << this->memos.memomax;
- for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
- data["memoignores"] << this->memos.ignores[i] << " ";
+ for (const auto &ignore : this->memos.ignores)
+ data["memoignores"] << ignore << " ";
Extensible::ExtensibleSerialize(this, this, data);
}
@@ -443,12 +443,10 @@ AccessGroup ChannelInfo::AccessFor(const User *u, bool updateLastUsed)
if (updateLastUsed)
this->last_used = Anope::CurTime;
- for (unsigned i = 0; i < group.paths.size(); ++i)
+ for (auto &p : group.paths)
{
- ChanAccess::Path &p = group.paths[i];
-
- for (unsigned int j = 0; j < p.size(); ++j)
- p[j]->last_seen = Anope::CurTime;
+ for (auto *ca : p)
+ ca->last_seen = Anope::CurTime;
}
}
@@ -688,6 +686,6 @@ void ChannelInfo::RemoveChannelReference(const Anope::string &what)
void ChannelInfo::GetChannelReferences(std::deque<Anope::string> &chans)
{
chans.clear();
- for (Anope::map<int>::iterator it = references.begin(); it != references.end(); ++it)
- chans.push_back(it->first);
+ for (auto &[chan, _] : references)
+ chans.push_back(chan);
}
diff --git a/src/serialize.cpp b/src/serialize.cpp
index b43be2dcf..03d9ed626 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -34,9 +34,8 @@ void Serialize::RegisterTypes()
void Serialize::CheckTypes()
{
- for (std::map<Anope::string, Serialize::Type *>::const_iterator it = Serialize::Type::GetTypes().begin(), it_end = Serialize::Type::GetTypes().end(); it != it_end; ++it)
+ for (const auto &[_, t] : Serialize::Type::GetTypes())
{
- Serialize::Type *t = it->second;
t->Check();
}
}
@@ -124,13 +123,13 @@ Type::~Type()
{
/* null the type of existing serializable objects of this type */
if (Serializable::SerializableItems != NULL)
- for (std::list<Serializable *>::iterator it = Serializable::SerializableItems->begin(); it != Serializable::SerializableItems->end(); ++it)
+ {
+ for (auto *s : *Serializable::SerializableItems)
{
- Serializable *s = *it;
-
if (s->s_type == this)
s->s_type = NULL;
}
+ }
std::vector<Anope::string>::iterator it = std::find(TypeOrder.begin(), TypeOrder.end(), this->name);
if (it != TypeOrder.end())
diff --git a/src/servers.cpp b/src/servers.cpp
index 397ed8fe1..e8547015a 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -48,27 +48,26 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
if (Me == this->uplink && !juped)
{
/* Now do mode related stuff as we know what modes exist .. */
- for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
+ for (auto &[_, bi] : *BotListByNick)
{
- BotInfo *bi = it->second;
Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : IRCD->DefaultPseudoclientModes;
bi->SetModesInternal(bi, modes.c_str());
- for (unsigned i = 0; i < bi->botchannels.size(); ++i)
+ for (const auto &botchannel : bi->botchannels)
{
- size_t h = bi->botchannels[i].find('#');
+ size_t h = botchannel.find('#');
if (h == Anope::string::npos)
continue;
- Anope::string chname = bi->botchannels[i].substr(h);
+ Anope::string chname = botchannel.substr(h);
Channel *c = Channel::Find(chname);
if (c && c->FindUser(bi))
{
- Anope::string want_modes = bi->botchannels[i].substr(0, h);
- for (unsigned j = 0; j < want_modes.length(); ++j)
+ Anope::string want_modes = botchannel.substr(0, h);
+ for (char want_mode : want_modes)
{
- ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(want_mode);
if (cm == NULL)
- cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j]));
+ cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_mode));
if (cm && cm->type == MODE_STATUS)
{
MessageSource ms = bi;
@@ -81,19 +80,15 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
IRCD->SendBOB();
- for (unsigned i = 0; i < Me->GetLinks().size(); ++i)
+ for (auto *link : Me->GetLinks())
{
- Server *s = Me->GetLinks()[i];
-
- if (s->juped)
- IRCD->SendServer(s);
+ if (link->juped)
+ IRCD->SendServer(link);
}
/* We make the bots go online */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, u] : UserListByNick)
{
- User *u = it->second;
-
BotInfo *bi = BotInfo::Find(u->GetUID());
if (bi)
{
@@ -106,22 +101,22 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
bi->introduced = true;
}
- for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
+ for (const auto &[_, c] : ChannelList)
{
- Channel *c = it->second;
-
if (c->users.empty())
IRCD->SendChannel(c);
else
- for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit)
- IRCD->SendJoin(cit->second->user, c, &cit->second->status);
+ {
+ for (const auto &[_, uc] : c->users)
+ IRCD->SendJoin(uc->user, c, &uc->status);
+ }
- for (Channel::ModeList::const_iterator it2 = c->GetModes().begin(); it2 != c->GetModes().end(); ++it2)
+ for (const auto &[mode, value] : c->GetModes())
{
- ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first);
+ ChannelMode *cm = ModeManager::FindChannelModeByName(mode);
if (!cm || cm->type != MODE_LIST)
continue;
- ModeManager::StackerAdd(c->WhoSends(), c, cm, true, it2->second);
+ ModeManager::StackerAdd(c->WhoSends(), c, cm, true, value);
}
if (!c->topic.empty() && !c->topic_setter.empty())
@@ -139,10 +134,8 @@ Server::~Server()
{
Log(this, "quit") << "quit from " << (this->uplink ? this->uplink->GetName() : "no uplink") << " for " << this->quit_reason;
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, u] : UserListByNick)
{
- User *u = it->second;
-
if (u->server == this)
{
u->Quit(this->quit_reason);
@@ -259,8 +252,8 @@ void Server::Sync(bool sync_links)
if (sync_links && !this->links.empty())
{
- for (unsigned i = 0, j = this->links.size(); i < j; ++i)
- this->links[i]->Sync(true);
+ for (auto *link : this->links)
+ link->Sync(true);
}
bool me = this->GetUplink() && this->GetUplink() == Me;
@@ -309,9 +302,11 @@ bool Server::IsULined() const
if (this == Me)
return true;
- for (unsigned i = 0; i < Config->Ulines.size(); ++i)
- if (Config->Ulines[i].equals_ci(this->GetName()))
+ for (const auto &uline : Config->Ulines)
+ {
+ if (uline.equals_ci(this->GetName()))
return true;
+ }
return false;
}
@@ -353,8 +348,10 @@ Server *Server::Find(const Anope::string &name, bool name_only)
Server* Servers::GetUplink()
{
- for (unsigned i = 0; Me && i < Me->GetLinks().size(); ++i)
- if (!Me->GetLinks()[i]->IsJuped())
- return Me->GetLinks()[i];
+ for (auto *link : Me->GetLinks())
+ {
+ if (!link->IsJuped())
+ return link;
+ }
return NULL;
}
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 019ca8454..67599c2d6 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -79,10 +79,8 @@ UplinkSocket::~UplinkSocket()
{
FOREACH_MOD(OnServerDisconnect, ());
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, u] : UserListByNick)
{
- User *u = it->second;
-
if (u->server == Me)
{
/* Don't use quitmsg here, it may contain information you don't want people to see */
diff --git a/src/users.cpp b/src/users.cpp
index 2b7aacd9b..ce22828a9 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -468,9 +468,8 @@ bool User::IsServicesOper()
bool match = false;
Anope::string match_host = this->GetIdent() + "@" + this->host;
Anope::string match_ip = this->GetIdent() + "@" + this->ip.addr();
- for (unsigned i = 0; i < this->nc->o->hosts.size(); ++i)
+ for (const auto &userhost : this->nc->o->hosts)
{
- const Anope::string &userhost = this->nc->o->hosts[i];
if (Anope::Match(match_host, userhost) || Anope::Match(match_ip, userhost))
{
match = true;
@@ -629,11 +628,11 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...)
spacesepstream sep(buf);
sep.GetToken(modebuf);
- for (unsigned i = 0, end = modebuf.length(); i < end; ++i)
+ for (auto mode : modebuf)
{
UserMode *um;
- switch (modebuf[i])
+ switch (mode)
{
case '+':
add = 1;
@@ -644,7 +643,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...)
default:
if (add == -1)
continue;
- um = ModeManager::FindUserModeByChar(modebuf[i]);
+ um = ModeManager::FindUserModeByChar(mode);
if (!um)
continue;
}
@@ -676,11 +675,11 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ...
spacesepstream sep(buf);
sep.GetToken(modebuf);
- for (unsigned i = 0, end = modebuf.length(); i < end; ++i)
+ for (auto mode : modebuf)
{
UserMode *um;
- switch (modebuf[i])
+ switch (mode)
{
case '+':
add = 1;
@@ -691,7 +690,7 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ...
default:
if (add == -1)
continue;
- um = ModeManager::FindUserModeByChar(modebuf[i]);
+ um = ModeManager::FindUserModeByChar(mode);
if (!um)
continue;
}
@@ -712,16 +711,16 @@ Anope::string User::GetModes() const
{
Anope::string m, params;
- for (ModeList::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it)
+ for (const auto &[mode, value] : this->modes)
{
- UserMode *um = ModeManager::FindUserModeByName(it->first);
+ UserMode *um = ModeManager::FindUserModeByName(mode);
if (um == NULL)
continue;
m += um->mchar;
- if (!it->second.empty())
- params += " " + it->second;
+ if (!value.empty())
+ params += " " + value;
}
return m + params;
@@ -852,7 +851,7 @@ User* User::Find(const Anope::string &name, bool nick_only)
void User::QuitUsers()
{
- for (std::list<User *>::iterator it = quitting_users.begin(), it_end = quitting_users.end(); it != it_end; ++it)
- delete *it;
+ for (const auto *quitting_user : quitting_users)
+ delete quitting_user;
quitting_users.clear();
}
diff --git a/src/xline.cpp b/src/xline.cpp
index 26e39fa5d..1e39e9840 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -224,10 +224,8 @@ void XLineManager::UnregisterXLineManager(XLineManager *xlm)
void XLineManager::CheckAll(User *u)
{
- for (std::list<XLineManager *>::iterator it = XLineManagers.begin(), it_end = XLineManagers.end(); it != it_end; ++it)
+ for (auto *xlm : XLineManagers)
{
- XLineManager *xlm = *it;
-
if (xlm->CheckAllXLines(u))
break;
}
@@ -361,9 +359,8 @@ void XLineManager::Clear()
std::vector<XLine *> xl;
this->xlines->swap(xl);
- for (unsigned i = 0; i < xl.size(); ++i)
+ for (auto *x : xl)
{
- XLine *x = xl[i];
if (!x->id.empty())
XLinesByUID->erase(x->id);
delete x;
@@ -427,10 +424,8 @@ XLine* XLineManager::HasEntry(const Anope::string &mask)
it->second->QueueUpdate();
return it->second;
}
- for (unsigned i = 0, end = this->xlines->size(); i < end; ++i)
+ for (auto *x : *this->xlines)
{
- XLine *x = this->xlines->at(i);
-
if (x->mask.equals_ci(mask))
{
x->QueueUpdate();