[Scummvm-cvs-logs] SF.net SVN: scummvm:[40077] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Apr 22 19:52:57 CEST 2009
Revision: 40077
http://scummvm.svn.sourceforge.net/scummvm/?rev=40077&view=rev
Author: fingolfin
Date: 2009-04-22 17:52:56 +0000 (Wed, 22 Apr 2009)
Log Message:
-----------
COMMON: changed class StringList to a simple typedef; enhanced the Common::Array constructor which converts regular arrays to Array objects to be more flexible in its type (allows e.g. to assign an array of char* to a StringList
Modified Paths:
--------------
scummvm/trunk/common/array.h
scummvm/trunk/common/str.h
scummvm/trunk/test/common/array.h
Modified: scummvm/trunk/common/array.h
===================================================================
--- scummvm/trunk/common/array.h 2009-04-22 12:57:23 UTC (rev 40076)
+++ scummvm/trunk/common/array.h 2009-04-22 17:52:56 UTC (rev 40077)
@@ -54,7 +54,8 @@
/**
* Construct an array by copying data from a regular array.
*/
- Array(const T *data, int n) {
+ template<class T2>
+ Array(const T2 *data, int n) {
_capacity = _size = n;
_storage = new T[_capacity];
copy(data, data + _size, _storage);
Modified: scummvm/trunk/common/str.h
===================================================================
--- scummvm/trunk/common/str.h 2009-04-22 12:57:23 UTC (rev 40076)
+++ scummvm/trunk/common/str.h 2009-04-22 17:52:56 UTC (rev 40077)
@@ -314,17 +314,8 @@
bool matchString(const char *str, const char *pat, bool pathMode = false);
-class StringList : public Array<String> {
-public:
- void push_back(const char *str) {
- Array<String>::push_back(str);
- }
+typedef Array<String> StringList;
- void push_back(const String &str) {
- Array<String>::push_back(str);
- }
-};
-
} // End of namespace Common
#endif
Modified: scummvm/trunk/test/common/array.h
===================================================================
--- scummvm/trunk/test/common/array.h 2009-04-22 12:57:23 UTC (rev 40076)
+++ scummvm/trunk/test/common/array.h 2009-04-22 17:52:56 UTC (rev 40077)
@@ -1,6 +1,7 @@
#include <cxxtest/TestSuite.h>
#include "common/array.h"
+#include "common/str.h"
class ArrayTestSuite : public CxxTest::TestSuite
{
@@ -151,4 +152,16 @@
TS_ASSERT_EQUALS( array2.size(), (unsigned int)3 );
}
+
+ void test_array_constructor_str() {
+ const char *array1[] = { "a", "b", "c" };
+
+ Common::StringList array2(array1, 3);
+
+ TS_ASSERT_EQUALS( array2[0], "a" );
+ TS_ASSERT_EQUALS( array2[1], "b" );
+ TS_ASSERT_EQUALS( array2[2], "c" );
+
+ TS_ASSERT_EQUALS( array2.size(), (unsigned int)3 );
+ }
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list