aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Sadie Powell2020-10-31 20:03:19 +0000
committerGravatar Sadie Powell2020-10-31 22:33:35 +0000
commit441bd151da733d32e194de6e4a1744ae273b83ee (patch)
tree74eb1ee2aef413185bf3906a17f1b2c27373e03a /include
parentFix reading the <sslprofile> config. (diff)
downloadinspircd++-441bd151da733d32e194de6e4a1744ae273b83ee.tar.gz
inspircd++-441bd151da733d32e194de6e4a1744ae273b83ee.tar.bz2
inspircd++-441bd151da733d32e194de6e4a1744ae273b83ee.zip
Add stdalgo::iterator_range and switch config tag reading to use it.
This allows us to use range-based for loops which were not possible with the previous config tag system.
Diffstat (limited to 'include')
-rw-r--r--include/inspircd.h1
-rw-r--r--include/iterator_range.h69
-rw-r--r--include/typedefs.h3
3 files changed, 72 insertions, 1 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 0fc86fa6e..7dbd6948e 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -61,6 +61,7 @@
#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
new file mode 100644
index 000000000..86aac4e7b
--- /dev/null
+++ b/include/iterator_range.h
@@ -0,0 +1,69 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+namespace stdalgo
+{
+ template <typename Iterator>
+ class iterator_range;
+}
+
+template <typename Iterator>
+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<Iterator, Iterator> 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/typedefs.h b/include/typedefs.h
index a9ea23e30..a779fde3b 100644
--- a/include/typedefs.h
+++ b/include/typedefs.h
@@ -105,8 +105,9 @@ typedef std::multimap<std::string, reference<ConfigTag>, irc::insensitive_swo> C
/** Iterator of ConfigDataHash */
typedef ConfigDataHash::const_iterator ConfigIter;
+
/** Iterator pair, used for tag-name ranges */
-typedef std::pair<ConfigIter,ConfigIter> ConfigTagList;
+typedef stdalgo::iterator_range<ConfigIter> ConfigTagList;
/** Files read by the configuration */
typedef std::map<std::string, file_cache> ConfigFileCache;