[Scummvm-git-logs] scummvm master -> f63f424309f82e049fce40d29a07d99c613b41f4

whoozle vladimir.menshakov at gmail.com
Mon Aug 31 19:41:32 UTC 2020


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
fb05242d36 COMMON: Add a way to specify default section name for simple sectionless .ini files
e7d7c67c69 COMMON: Allow something else than raw pointer to be used in SortedArray
f63f424309 COMMON: Preserve the order of insertion for equal range of the keys.


Commit: fb05242d36052c2f16185424e8499e8d5b6ad5fa
    https://github.com/scummvm/scummvm/commit/fb05242d36052c2f16185424e8499e8d5b6ad5fa
Author: Vladimir Menshakov (vladimir.menshakov at gmail.com)
Date: 2020-08-31T18:17:28+01:00

Commit Message:
COMMON: Add a way to specify default section name for simple sectionless .ini files

Changed paths:
    common/ini-file.cpp
    common/ini-file.h


diff --git a/common/ini-file.cpp b/common/ini-file.cpp
index 4c4acc9e60..bae7e7d3cd 100644
--- a/common/ini-file.cpp
+++ b/common/ini-file.cpp
@@ -72,6 +72,7 @@ bool INIFile::loadFromStream(SeekableReadStream &stream) {
 	KeyValue kv;
 	String comment;
 	int lineno = 0;
+	section.name = _defaultSectionName;
 
 	// TODO: Detect if a section occurs multiple times (or likewise, if
 	// a key occurs multiple times inside one section).
@@ -297,6 +298,9 @@ void INIFile::renameSection(const String &oldName, const String &newName) {
 	// - merge the two sections "oldName" and "newName"
 }
 
+void INIFile::setDefaultSectionName(const String &name) {
+	_defaultSectionName = name;
+}
 
 bool INIFile::hasKey(const String &key, const String &section) const {
 	if (!isValidName(key)) {
diff --git a/common/ini-file.h b/common/ini-file.h
index 5d72f23bb9..f84ca6009c 100644
--- a/common/ini-file.h
+++ b/common/ini-file.h
@@ -105,6 +105,8 @@ public:
 	void	removeSection(const String &section);
 	void	renameSection(const String &oldName, const String &newName);
 
+	void	setDefaultSectionName(const String &name); ///< sets initial section name for section-less ini files
+
 	bool	hasKey(const String &key, const String &section) const;
 	bool	getKey(const String &key, const String &section, String &value) const;
 	void	setKey(const String &key, const String &section, const String &value);
@@ -118,6 +120,7 @@ public:
 	void allowNonEnglishCharacters();
 
 private:
+	String		_defaultSectionName;
 	SectionList _sections;
 	bool _allowNonEnglishCharacters;
 


Commit: e7d7c67c69a35ebb7db0df8b159831ce13dfc00b
    https://github.com/scummvm/scummvm/commit/e7d7c67c69a35ebb7db0df8b159831ce13dfc00b
Author: Vladimir Menshakov (vladimir.menshakov at gmail.com)
Date: 2020-08-31T18:17:29+01:00

Commit Message:
COMMON: Allow something else than raw pointer to be used in SortedArray

Changed paths:
    common/array.h


diff --git a/common/array.h b/common/array.h
index 5e8ecb57ab..69c53f607e 100644
--- a/common/array.h
+++ b/common/array.h
@@ -392,13 +392,14 @@ protected:
 /**
  * Double linked list with sorted nodes.
  */
-template<class T>
+template<class T, typename CompareArgType = const void *>
 class SortedArray : public Array<T> {
 public:
+	typedef int (*Comparator)(CompareArgType, CompareArgType);
 	typedef T *iterator;
 	typedef uint size_type;
 
-	SortedArray(int (*comparator)(const void *, const void *)) {
+	SortedArray(Comparator comparator) {
 		_comparator = comparator;
 	}
 
@@ -435,7 +436,7 @@ private:
 	// Based on code Copyright (C) 2008-2009 Ksplice, Inc.
 	// Author: Tim Abbott <tabbott at ksplice.com>
 	// Licensed under GPLv2+
-	T *bsearchMin(void *key) {
+	T *bsearchMin(CompareArgType key) {
 		uint start_ = 0, end_ = this->_size;
 		int result;
 
@@ -454,7 +455,7 @@ private:
 		return &this->_storage[start_];
 	}
 
-	int (*_comparator)(const void *, const void *);
+	Comparator _comparator;
 };
 
 } // End of namespace Common


Commit: f63f424309f82e049fce40d29a07d99c613b41f4
    https://github.com/scummvm/scummvm/commit/f63f424309f82e049fce40d29a07d99c613b41f4
Author: Vladimir Menshakov (vladimir.menshakov at gmail.com)
Date: 2020-08-31T18:17:29+01:00

Commit Message:
COMMON: Preserve the order of insertion for equal range of the keys.

Changed paths:
    common/array.h
    test/common/array.h


diff --git a/common/array.h b/common/array.h
index 69c53f607e..c57d0a109d 100644
--- a/common/array.h
+++ b/common/array.h
@@ -446,10 +446,8 @@ private:
 			result = this->_comparator(key, this->_storage[mid]);
 			if (result < 0)
 				end_ = mid;
-			else if (result > 0)
-				start_ = mid + 1;
 			else
-				return &this->_storage[mid];
+				start_ = mid + 1;
 		}
 
 		return &this->_storage[start_];
diff --git a/test/common/array.h b/test/common/array.h
index e0a6438d52..bf0ff55639 100644
--- a/test/common/array.h
+++ b/test/common/array.h
@@ -414,8 +414,9 @@ class ArrayTestSuite : public CxxTest::TestSuite
 
 struct ListElement {
 	int value;
+	int tag;
 
-	ListElement(int v) : value(v) {}
+	ListElement(int v, int t = 0) : value(v), tag(t) {}
 };
 
 static int compareInts(const void *a, const void *b) {
@@ -450,4 +451,30 @@ public:
 		TS_ASSERT_EQUALS(iter, container.end());
 	}
 
+	void test_stability() {
+		Common::SortedArray<ListElement *> container(compareInts);
+		Common::SortedArray<ListElement *>::iterator iter;
+
+		// Check stability, using duplicate keys and sequential tags.
+		container.insert(new ListElement(1, 3));
+		container.insert(new ListElement(0, 1));
+		container.insert(new ListElement(4, 8));
+		container.insert(new ListElement(1, 4));
+		container.insert(new ListElement(0, 2));
+		container.insert(new ListElement(2, 6));
+		container.insert(new ListElement(1, 5));
+		container.insert(new ListElement(3, 7));
+		container.insert(new ListElement(4, 9));
+
+		// Verify contents are correct
+		iter = container.begin();
+
+		for (int i = 1; i < 10; i++) {
+			TS_ASSERT_EQUALS((*iter)->tag, i);
+			++iter;
+		}
+
+		TS_ASSERT_EQUALS(iter, container.end());
+	}
+
 };




More information about the Scummvm-git-logs mailing list