removed the Range class too

Wed, 27 Jan 2021 14:16:58 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 27 Jan 2021 14:16:58 +0200
changeset 185
e83ec58cc458
parent 184
afd63357a03d
child 186
9330b93d9946

removed the Range class too

CMakeLists.txt file | annotate | diff | comparison | revisions
sources/interface.cpp file | annotate | diff | comparison | revisions
sources/list.h file | annotate | diff | comparison | revisions
sources/network/bytestream.cpp file | annotate | diff | comparison | revisions
sources/network/ipaddress.cpp file | annotate | diff | comparison | revisions
sources/network/rconsession.cpp file | annotate | diff | comparison | revisions
sources/range.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Wed Jan 27 14:06:45 2021 +0200
+++ b/CMakeLists.txt	Wed Jan 27 14:16:58 2021 +0200
@@ -40,7 +40,6 @@
 	sources/network/ipaddress.h
 	sources/network/rconsession.h
 	sources/network/udpsocket.h
-	sources/range.h
 	sources/version.h
 )
 
--- a/sources/interface.cpp	Wed Jan 27 14:06:45 2021 +0200
+++ b/sources/interface.cpp	Wed Jan 27 14:16:58 2021 +0200
@@ -179,8 +179,8 @@
 		int defaultBg = hasDefaultColors ? -1 : COLOR_BLACK;
 
 		// Initialize color pairs
-		for (int i : range<int>(NUM_COLORS))
-		for (int j : range<int>(NUM_COLORS))
+		for (int i = 0; i < NUM_COLORS; i += 1)
+		for (int j = 0; j < NUM_COLORS; j += 1)
 		{
 			int pairnum = 1 + (i * NUM_COLORS + j);
 			int fg =(i == DEFAULT) ? defaultFg : i;
@@ -360,13 +360,13 @@
 	assert(start <= end and start - end <= height);
 
 	// Clear the display
-	for (int i : range(height))
+	for (int i = 0; i < height; i += 1)
 		mvhline(y + i, 0, ' ', width);
 
 	// Print the lines
 	y += printOffset;
 
-	for (int i : range(start, end))
+	for (int i = start; i < end; i += 1)
 		y = renderColorline(y, 0, width, m_outputLines[i], true);
 
 	m_needOutputRender = false;
@@ -385,7 +385,7 @@
 	if (width > 0)
 		return;
 
-	for (int i : range(height))
+	for (int i = 0; i < height; i += 1)
 	{
 		mvhline(y, x, ' ', width);
 
--- a/sources/list.h	Wed Jan 27 14:06:45 2021 +0200
+++ b/sources/list.h	Wed Jan 27 14:16:58 2021 +0200
@@ -32,7 +32,6 @@
 #include <vector>
 #include <string>
 #include "basics.h"
-#include "range.h"
 BEGIN_ZFC_NAMESPACE
 
 template<typename T>
@@ -61,10 +60,4 @@
 	return result;
 }
 
-template<typename T>
-T splice(const T& container, Range<int>& range)
-{
-	return splice(container, range.min(), range.max(), range.step());
-}
-
 END_ZFC_NAMESPACE
--- a/sources/network/bytestream.cpp	Wed Jan 27 14:06:45 2021 +0200
+++ b/sources/network/bytestream.cpp	Wed Jan 27 14:16:58 2021 +0200
@@ -90,7 +90,7 @@
 	ensureReadSpace (2);
 	int16_t result = 0;
 
-	for (int i : range(2))
+	for (int i : {0, 1})
 		result |= read() << (i * 8);
 
 	return result;
@@ -104,8 +104,8 @@
 {
 	ensureReadSpace (4);
 	int32_t result = 0;
-
-	for (int i : range(4))
+	
+	for (int i = 0; i < 4; i += 1)
 		result |= read() << (i * 8);
 
 	return result;
@@ -170,7 +170,7 @@
 void Bytestream::writeShort(int16_t value)
 {
 	m_data.reserve(m_data.size() + 2);
-	for (int i : range(2))
+	for (int i : {0, 1})
 		m_data.push_back((value >> (i * 8)) & 0xFF);
 }
 
@@ -181,7 +181,7 @@
 void Bytestream::writeLong(int32_t value)
 {
 	m_data.reserve(m_data.size() + 4);
-	for (int i : range(4))
+	for (int i = 0; i < 4; i += 1)
 		m_data.push_back((value >> (i * 8)) & 0xFF);
 }
 
--- a/sources/network/ipaddress.cpp	Wed Jan 27 14:06:45 2021 +0200
+++ b/sources/network/ipaddress.cpp	Wed Jan 27 14:16:58 2021 +0200
@@ -80,7 +80,7 @@
 //
 bool IPAddress::compare (const IPAddress& other) const
 {
-	for (int i : range(4))
+	for (int i = 0; i < 4; i += 1)
 	{
 		if (octet (i) != other.octet (i))
 			return false;
@@ -100,7 +100,7 @@
 //
 bool IPAddress::operator< (const IPAddress& other) const
 {
-	for (int i : range(4))
+	for (int i = 0; i < 4; i += 1)
 	{
 		if (octet (i) != other.octet (i))
 			return octet (i) < other.octet (i);
@@ -133,7 +133,7 @@
 	// Try scanf the IPv4 host first
 	if (sscanf(addressString.data(), "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3]))
 	{
-		for (int i : range(4))
+		for (int i = 0; i < 4; i += 1)
 			value.set_octet (i, parts[i]);
 	}
 	else
--- a/sources/network/rconsession.cpp	Wed Jan 27 14:06:45 2021 +0200
+++ b/sources/network/rconsession.cpp	Wed Jan 27 14:16:58 2021 +0200
@@ -213,9 +213,9 @@
 					{
 						m_interface->print("Completions for '%s':\n", m_lastTabComplete.data());
 
-						for (int i : range(0, static_cast<int>(completes.size()), 8))
+						for (std::size_t i = 0; i < completes.size(); i += 8)
 						{
-							const int end = min(i + 8, static_cast<int>(completes.size()));
+							const int end = min(i + 8, completes.size());
 							std::vector<std::string> splices = splice(completes, i, end);
 							m_interface->print("- %s\n", join_string_list(splices, ", ").data());
 						}
--- a/sources/range.h	Wed Jan 27 14:06:45 2021 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*
-	Copyright 2014 - 2016 Teemu Piippo
-	All rights reserved.
-
-	Redistribution and use in source and binary forms, with or without
-	modification, are permitted provided that the following conditions
-	are met:
-
-	1. Redistributions of source code must retain the above copyright
-	   notice, this list of conditions and the following disclaimer.
-	2. Redistributions in binary form must reproduce the above copyright
-	   notice, this list of conditions and the following disclaimer in the
-	   documentation and/or other materials provided with the distribution.
-	3. Neither the name of the copyright holder nor the names of its
-	   contributors may be used to endorse or promote products derived from
-	   this software without specific prior written permission.
-
-	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-	"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-	TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-	PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
-	OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-	PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-	NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#pragma once
-#include <algorithm>
-#include <memory>
-#include "basics.h"
-BEGIN_ZFC_NAMESPACE
-
-//
-// -------------------------------------------------------------------------------------------------
-//
-
-template<typename T>
-class Range
-{
-	T m_a;
-	T m_b;
-	T m_step;
-
-public:
-	struct Iterator
-	{
-		T value;
-		T step;
-
-		Iterator (T value, T step) :
-			value (value),
-			step (step) {}
-
-		T& operator*()
-		{
-			return value;
-		}
-
-		bool operator== (const Iterator& other) const
-		{
-			return value == other.value;
-		}
-
-		bool operator!= (const Iterator& other) const
-		{
-			return value < other.value;
-		}
-
-		Iterator& operator++()
-		{
-			value += step; return *this;
-		}
-	};
-
-	Range (T a, T b, T step = 1) :
-		m_a (a),
-		m_b (b),
-		m_step (step)
-	{
-		check_bounds();
-	}
-
-	Range() :
-		m_a (T()),
-		m_b (T()) {}
-
-	Iterator begin() const
-	{
-		return Iterator(min(), m_step);
-	}
-
-	Iterator end() const
-	{
-		return Iterator(max(), m_step);
-	}
-
-	T min() const
-	{
-		return m_a;
-	}
-
-	T max() const
-	{
-		return m_b;
-	}
-
-	T step() const
-	{
-		return m_step;
-	}
-
-	void check_bounds()
-	{
-		if (m_b < m_a)
-			std::swap (m_a, m_b);
-	}
-
-	bool contains (T c) const
-	{
-		return c >= m_a
-		   and c <= m_b;
-	}
-
-	bool contains_exclusively (T c) const
-	{
-		return c > m_a
-		   and c < m_b;
-	}
-
-	bool overlaps (Range<T> const& other) const
-	{
-		return contains (other.m_a)
-			or contains (other.m_b);
-	}
-
-	bool operator== (Range<T> const& other) const
-	{
-		return m_a == other.m_a
-		   and m_b == other.m_b;
-	}
-
-	bool operator!= (Range<T> const& other) const
-	{
-		return not operator== (other);
-	}
-};
-
-template<typename T>
-Range<T> range(T a, T b, T step = 1)
-{
-	return Range<T>(a, b, step);
-}
-
-template<typename T>
-Range<T> range(T b)
-{
-	return Range<T>(T(), b);
-}
-
-END_ZFC_NAMESPACE

mercurial