start cleaning up unused code

Wed, 27 Jan 2021 13:02:51 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 27 Jan 2021 13:02:51 +0200
changeset 179
7fc34735178e
parent 173
248fba6d1e76
child 180
2e7225dbd9b2

start cleaning up unused code

CMakeLists.txt file | annotate | diff | comparison | revisions
sources/basics.h file | annotate | diff | comparison | revisions
sources/interface.cpp file | annotate | diff | comparison | revisions
sources/interface.h file | annotate | diff | comparison | revisions
sources/list.h file | annotate | diff | comparison | revisions
sources/mystring.cpp file | annotate | diff | comparison | revisions
sources/mystring.h file | annotate | diff | comparison | revisions
sources/network/rconsession.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Wed Jan 27 12:38:00 2021 +0200
+++ b/CMakeLists.txt	Wed Jan 27 13:02:51 2021 +0200
@@ -2,6 +2,9 @@
 cmake_policy (SET CMP0003 NEW)
 project (ZFC9000)
 string (TOLOWER ${CMAKE_PROJECT_NAME} TARGET_NAME)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
 
 add_library (huffman STATIC
 	huffman/bitreader.cpp
--- a/sources/basics.h	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/basics.h	Wed Jan 27 13:02:51 2021 +0200
@@ -29,6 +29,7 @@
 */
 
 #pragma once
+#include <type_traits>
 #include <stdlib.h>
 
 #if !defined(_MSC_VER) && !defined(__cdecl)
@@ -106,8 +107,8 @@
 	return result;
 }
 
-template<typename T>
-T clamp (T a, T b, T c)
+template<typename T, typename TT, typename TTT>
+std::common_type_t<T, TT, TTT> clamp(T a, TT b, TTT c)
 {
 	return (a < b) ? b : (a > c) ? c : a;
 }
--- a/sources/interface.cpp	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/interface.cpp	Wed Jan 27 13:02:51 2021 +0200
@@ -90,7 +90,7 @@
 	}
 
 	int oldcursor = m_inputCursor;
-	m_inputCursor = clamp(m_inputCursor + delta, 0, m_inputHistory.size() - 1);
+	m_inputCursor = clamp(m_inputCursor + delta, 0, static_cast<int>(m_inputHistory.size() - 1));
 
 	if (m_inputCursor != oldcursor)
 	{
@@ -165,7 +165,7 @@
 	::refresh();
 	::timeout(0);
 	m_inputHistory.clear();
-	m_inputHistory << "";
+	m_inputHistory.push_back("");
 	m_outputLines.clear();
 	m_outputLines << ColoredLine();
 	m_session.setInterface(this);
@@ -389,7 +389,7 @@
 	{
 		mvhline(y, x, ' ', width);
 
-		if (i < m_playerNames.size())
+		if (i < static_cast<signed>(m_playerNames.size()))
 			renderColorline(y, x, width, m_playerNames[i], false);
 
 		y++;
@@ -1022,7 +1022,7 @@
 		ColoredLine coloredname;
 		coloredname.addString(name);
 		coloredname.finalize();
-		m_playerNames.append(coloredname);
+		m_playerNames.push_back(coloredname);
 	}
 
 	m_needNicklistRender = true;
@@ -1054,7 +1054,7 @@
 
 	StringList args = input.right(input.length() - 1).split(" ");
 	String command = args[0].toLowerCase();
-	args.remove_at(0);
+	args.erase(args.begin());
 
 	if (command == "connect")
 	{
@@ -1118,7 +1118,7 @@
 //
 void Interface::flushInput()
 {
-	m_inputHistory.insert(0, "");
+	m_inputHistory.insert(m_inputHistory.begin(), "");
 	m_inputCursor = 0;
 	m_needInputRender = true;
 }
--- a/sources/interface.h	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/interface.h	Wed Jan 27 13:02:51 2021 +0200
@@ -85,7 +85,7 @@
 	std::function<void(bool)> m_disconnectCallback;
 	IPAddress m_remoteAddress;
 	String m_statusBarText;
-	List<ColoredLine> m_playerNames;
+	std::vector<ColoredLine> m_playerNames;
 	String m_pasteBuffer;
 	RCONSession m_session;
 
--- a/sources/list.h	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/list.h	Wed Jan 27 13:02:51 2021 +0200
@@ -418,4 +418,24 @@
 ByteArray::ByteArray(Args&& ...args) :
     Vector<unsigned char>(args...) {}
 
+template<typename T>
+T splice(const T& container, int start, int end, int step = 1)
+{
+	start = clamp(start, 0, static_cast<int>(container.size()));
+	end = clamp(end, 0, static_cast<int>(container.size()));
+	T result;
+	result.reserve((end - start) / step);
+	for (int i = start; i < end; i += step)
+	{
+		result.push_back(container[i]);
+	}
+	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/mystring.cpp	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/mystring.cpp	Wed Jan 27 13:02:51 2021 +0200
@@ -48,26 +48,6 @@
 }
 
 /*!
- * \brief Removes all instances of an unwanted character from this string.
- * \param unwanted Character to remove.
- */
-void String::strip (char unwanted)
-{
-	for (int pos = 0; (pos = find (unwanted)) != -1;)
-		removeAt (pos--);
-}
-
-/*!
- * \brief Removes all instances of multiple characters from this string.
- * \param unwanted Characters to remove.
- */
-void String::strip (const List<char>& unwanted)
-{
-	for (char character : unwanted)
-		strip(character);
-}
-
-/*!
  * \returns an upper-case version of this string.
  */
 String String::toUpperCase() const
@@ -128,14 +108,14 @@
 		String sub = mid (a, b);
 
 		if (sub.length() > 0)
-			result << sub;
+			result.push_back(sub);
 
 		a = b + delimeter.length();
 	}
 
 	// Add the string at the right of the last separator
 	if (a < (int) length())
-		result.append (mid (a, length()));
+		result.push_back(mid(a, length()));
 
 	return result;
 }
@@ -409,11 +389,11 @@
  * \param delimeter The delimeter to place between the element strings.
  * \returns the catenated string.
  */
-String StringList::join (const String& delimeter)
+String join_string_list(const StringList& strings, const String& delimeter)
 {
 	String result;
 
-	for (const String &item : container())
+	for (const String &item : strings)
 	{
 		if (result.isEmpty() == false)
 			result += delimeter;
--- a/sources/mystring.h	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/mystring.h	Wed Jan 27 13:02:51 2021 +0200
@@ -37,6 +37,7 @@
 
 BEGIN_ZFC_NAMESPACE
 
+using StringList = std::vector<class String>;
 
 class String
 {
@@ -86,13 +87,11 @@
 	void                        replace(int position, int amount, const String &text);
 	String                      right(int length) const;
 	void                        shrinkToFit();
-	class StringList            split(const String &delimeter) const;
-	class StringList            split(char delimeter) const;
+	StringList            split(const String &delimeter) const;
+	StringList            split(char delimeter) const;
 	void __cdecl                sprintf(const char* fmtstr, ...);
 	bool                        startsWith(const String &other) const;
 	const std::string&          stdString() const;
-	void                        strip(char unwanted);
-	void                        strip(const List<char> &unwanted);
 	const unsigned char*        toBytes() const;
 	double                      toDouble(bool* ok = nullptr) const;
 	float                       toFloat(bool* ok = nullptr) const;
@@ -134,16 +133,7 @@
 	std::string m_string;
 };
 
-
-class StringList : public List<String>
-{
-public:
-	StringList();
-	StringList(int numvalues);
-	StringList(const List<String>& other);
-	String join(const String& delim);
-};
-
+String join_string_list(const StringList& strings, const String& delim);
 
 inline bool operator==(const char* a, const String& b);
 inline String operator+(const char* a, const String& b);
@@ -563,25 +553,6 @@
 }
 
 /*!
- * \brief Constructs an empty string list.
- */
-inline StringList::StringList() {}
-
-/*!
- * \brief Constructs a string list containing \c numvalues empty strings.
- * \param numvalues Amount of empty strings to fill.
- */
-inline StringList::StringList(int numvalues) :
-	List<String>(numvalues) {}
-
-/*!
- * \brief Constructs a string list from another list of strings.
- * \param other The list of strings to use for construction.
- */
-inline StringList::StringList(const List<String>& other) :
-	List<String>(other) {}
-
-/*!
  * \brief An \c operator== implementation that allows a char-array to be at the left side of a string comparison
  *        with a \c String.
  * \param one A char-array representation of a string to compare.
--- a/sources/network/rconsession.cpp	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/network/rconsession.cpp	Wed Jan 27 13:02:51 2021 +0200
@@ -208,15 +208,15 @@
 					{
 						m_interface->tabComplete(m_lastTabComplete, completes[0]);
 					}
-					else if (not completes.is_empty())
+					else if (completes.size() > 0)
 					{
 						m_interface->print("Completions for '%s':\n", m_lastTabComplete.chars());
 
-						for (int i : range(0, completes.size(), 8))
+						for (int i : range(0, static_cast<int>(completes.size()), 8))
 						{
-							Range<int> spliceRange(i, min(i + 8, completes.size()));
-							StringList splice(completes.splice(spliceRange));
-							m_interface->print("- %s\n", splice.join(", ").chars());
+							const int end = min(i + 8, static_cast<int>(completes.size()));
+							StringList splices = splice(completes, i, end);
+							m_interface->print("- %s\n", join_string_list(splices, ", ").chars());
 						}
 					}
 				}
@@ -243,7 +243,7 @@
 			StringList players;
 
 			for (int i = packet.readByte(); i > 0; --i)
-				players.append(packet.readString());
+				players.push_back(packet.readString());
 
 			m_interface->setPlayerNames(players);
 		}

mercurial