From 3f113fc04628491cb795d2fc809d89ff2379c61a Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 2 Mar 2021 02:44:41 +0000 Subject: Move iterator_range to the utility directory and renamespace. --- include/configreader.h | 2 +- include/inspircd.h | 3 +- include/iterator_range.h | 80 ---------------------------------------- include/utility/iterator_range.h | 80 ++++++++++++++++++++++++++++++++++++++++ src/configreader.cpp | 4 +- src/mode.cpp | 6 +-- src/modules/m_alias.cpp | 4 +- src/modules/m_chanlog.cpp | 2 +- src/modules/m_customtitle.cpp | 2 +- src/modules/m_vhost.cpp | 2 +- 10 files changed, 93 insertions(+), 92 deletions(-) delete mode 100644 include/iterator_range.h create mode 100644 include/utility/iterator_range.h diff --git a/include/configreader.h b/include/configreader.h index 88a444840..a472144f6 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -300,7 +300,7 @@ class CoreExport ServerConfig typedef std::multimap, irc::insensitive_swo> TagMap; /** Holds iterators to a subsection of the server config map. */ - typedef stdalgo::iterator_range TagList; + typedef insp::iterator_range TagList; /** Get a configuration tag by name. If one or more tags are present then the first is returned. * @param tag The name of the tag to get. diff --git a/include/inspircd.h b/include/inspircd.h index d3ddee776..ffff42be0 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -57,11 +57,12 @@ #include #include +#include "utility/iterator_range.h" + #include "intrusive_list.h" #include "flat_map.h" #include "compat.h" #include "aligned_storage.h" -#include "iterator_range.h" #include "typedefs.h" #include "convto.h" #include "stdalgo.h" diff --git a/include/iterator_range.h b/include/iterator_range.h deleted file mode 100644 index e760646d5..000000000 --- a/include/iterator_range.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2020 Sadie Powell - * - * This file is part of InspIRCd. InspIRCd is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#pragma once - -namespace stdalgo -{ - template - class iterator_range; - - /** Returns a range containing all elements equivalent to \p value. - * @param collection The collection to search within. - * @param value The value to search for. - */ - template - iterator_range equal_range(const Collection& collection, const Value& value) - { - return collection.equal_range(value); - } -} - -/** Represents a range of iterators. */ -template -class stdalgo::iterator_range -{ - private: - /** An iterator which points to the start of the range. */ - const Iterator begini; - - /* An iterator which points to one past the end of the range. */ - const Iterator endi; - - public: - /** Initialises a new iterator range with the specified iterators. - * @param begin An iterator which points to the start of the range. - * @param end An iterator which points to one past the end of the range. - */ - iterator_range(Iterator begin, Iterator end) - : begini(begin) - , endi(end) - { - } - - /** Initialises a new iterator range from a pair of iterators. - * @param range A pair of iterators in the format [first, last). - */ - iterator_range(std::pair range) - : begini(range.first) - , endi(range.second) - { - } - - /** Determines whether the iterator range is empty. */ - bool empty() const { return begini == endi; } - - /** Retrieves an iterator which points to the start of the range. */ - const Iterator& begin() const { return begini; } - - /** Retrieves an iterator which points to one past the end of the range. */ - const Iterator& end() const { return endi; } - - /** Retrieves the number of hops within the iterator range. */ - typename Iterator::difference_type count() const { return std::distance(begini, endi); } -}; diff --git a/include/utility/iterator_range.h b/include/utility/iterator_range.h new file mode 100644 index 000000000..ff8d8d10e --- /dev/null +++ b/include/utility/iterator_range.h @@ -0,0 +1,80 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2020 Sadie Powell + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#pragma once + +namespace insp +{ + template + class iterator_range; + + /** Returns a range containing all elements equivalent to \p value. + * @param collection The collection to search within. + * @param value The value to search for. + */ + template + iterator_range equal_range(const Collection& collection, const Value& value) + { + return collection.equal_range(value); + } +} + +/** Represents a range of iterators. */ +template +class insp::iterator_range final +{ + private: + /** An iterator which points to the start of the range. */ + const Iterator begini; + + /* An iterator which points to one past the end of the range. */ + const Iterator endi; + + public: + /** Initialises a new iterator range with the specified iterators. + * @param begin An iterator which points to the start of the range. + * @param end An iterator which points to one past the end of the range. + */ + iterator_range(Iterator begin, Iterator end) + : begini(begin) + , endi(end) + { + } + + /** Initialises a new iterator range from a pair of iterators. + * @param range A pair of iterators in the format [first, last). + */ + iterator_range(std::pair range) + : begini(range.first) + , endi(range.second) + { + } + + /** Determines whether the iterator range is empty. */ + bool empty() const { return begini == endi; } + + /** Retrieves an iterator which points to the start of the range. */ + const Iterator& begin() const { return begini; } + + /** Retrieves an iterator which points to one past the end of the range. */ + const Iterator& end() const { return endi; } + + /** Retrieves the number of hops within the iterator range. */ + typename Iterator::difference_type count() const { return std::distance(begini, endi); } +}; diff --git a/src/configreader.cpp b/src/configreader.cpp index ac3a2e811..563e1fe08 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -617,7 +617,7 @@ void ServerConfig::ApplyModules(User* user) std::shared_ptr ServerConfig::ConfValue(const std::string& tag, std::shared_ptr def) { - auto tags = stdalgo::equal_range(config_data, tag); + auto tags = insp::equal_range(config_data, tag); if (tags.empty()) return def ? def : EmptyTag; @@ -631,7 +631,7 @@ std::shared_ptr ServerConfig::ConfValue(const std::string& tag, std:: ServerConfig::TagList ServerConfig::ConfTags(const std::string& tag, std::optional def) { - auto range = stdalgo::equal_range(config_data, tag); + auto range = insp::equal_range(config_data, tag); return range.empty() && def ? *def : range; } diff --git a/src/mode.cpp b/src/mode.cpp index ddcddda6a..59f8dd4e0 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -305,7 +305,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode } // Ask mode watchers whether this mode change is OK - for (const auto& [_, mw] : stdalgo::equal_range(modewatchermap, mh->name)) + for (const auto& [_, mw] : insp::equal_range(modewatchermap, mh->name)) { if (mw->GetModeType() == type) { @@ -343,7 +343,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode if (ma != MODEACTION_ALLOW) return ma; - for (const auto& [_, mw] : stdalgo::equal_range(modewatchermap, mh->name)) + for (const auto& [_, mw] : insp::equal_range(modewatchermap, mh->name)) { if (mw->GetModeType() == type) mw->AfterMode(user, targetuser, chan, parameter, adding); @@ -509,7 +509,7 @@ void ModeParser::ShowListModeList(User* user, Channel* chan, ModeHandler* mh) bool display = true; // Ask mode watchers whether it's OK to show the list - for (const auto& [_, mw] : stdalgo::equal_range(modewatchermap, mh->name)) + for (const auto& [_, mw] : insp::equal_range(modewatchermap, mh->name)) { if (mw->GetModeType() == MODETYPE_CHANNEL) { diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 12a6ba833..aa040bf9c 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -166,7 +166,7 @@ class ModuleAlias : public Module return MOD_RES_PASSTHRU; /* We dont have any commands looking like this? Stop processing. */ - auto aliases = stdalgo::equal_range(Aliases, command); + auto aliases = insp::equal_range(Aliases, command); if (aliases.empty()) return MOD_RES_PASSTHRU; @@ -240,7 +240,7 @@ class ModuleAlias : public Module // nor do we give a shit about the prefix scommand.erase(0, fprefix.size()); - auto aliases = stdalgo::equal_range(Aliases, scommand); + auto aliases = insp::equal_range(Aliases, scommand); if (aliases.empty()) return; diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp index 1d6c96282..692b25352 100644 --- a/src/modules/m_chanlog.cpp +++ b/src/modules/m_chanlog.cpp @@ -64,7 +64,7 @@ class ModuleChanLog : public Module ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg) override { - auto channels = stdalgo::equal_range(logstreams, sno); + auto channels = insp::equal_range(logstreams, sno); if (channels.empty()) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index d98ded7b7..05120f930 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -84,7 +84,7 @@ class CommandTitle : public Command CmdResult Handle(User* user, const Params& parameters) override { - for (const auto& [_, config] : stdalgo::equal_range(configs, parameters[0])) + for (const auto& [_, config] : insp::equal_range(configs, parameters[0])) { if (config.MatchUser(user) && config.CheckPass(user, parameters[1])) { diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp index 615272ef0..79915e0ed 100644 --- a/src/modules/m_vhost.cpp +++ b/src/modules/m_vhost.cpp @@ -64,7 +64,7 @@ class CommandVhost : public Command CmdResult Handle(User* user, const Params& parameters) override { - for (const auto& [_, config] : stdalgo::equal_range(vhosts, parameters[0])) + for (const auto& [_, config] : insp::equal_range(vhosts, parameters[0])) { if (config.CheckPass(user, parameters[1])) { -- cgit v1.3.1-10-gc9f91