[Scummvm-cvs-logs] SF.net SVN: scummvm:[40909] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue May 26 13:31:45 CEST 2009


Revision: 40909
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40909&view=rev
Author:   fingolfin
Date:     2009-05-26 11:31:45 +0000 (Tue, 26 May 2009)

Log Message:
-----------
Renamed Common::Serializer::syncMagic to matchBytes, and added version paarms to it (we migh want to add corresponding matchUint32LE etc. functions if needed)

Modified Paths:
--------------
    scummvm/trunk/common/serializer.h
    scummvm/trunk/test/common/serializer.h

Modified: scummvm/trunk/common/serializer.h
===================================================================
--- scummvm/trunk/common/serializer.h	2009-05-26 11:30:21 UTC (rev 40908)
+++ scummvm/trunk/common/serializer.h	2009-05-26 11:31:45 UTC (rev 40909)
@@ -127,35 +127,7 @@
 	 */
 	Version getVersion() const { return _version; }
 
-	/**
-	 * Sync a 'magic id' of up to 256 bytes, and return whether it matched.
-	 * When saving, this will simply write out the magic id and return true.
-	 * When loading, this will read the specified number of bytes, compare it
-	 * to the given magic id and return true on a match, false otherwise.
-	 *
-	 * A typical magic id is a FOURCC like 'MAGI'.
-	 *
-	 * @param magic		magic id as a byte sequence
-	 * @param size		length of the magic id in bytes
-	 * @return true if the magic id matched, false otherwise
-	 *
-	 * @todo Should this have minVersion/maxVersion params, too?
-	 */
-	bool syncMagic(const char *magic, byte size) {
-		char buf[256];
-		bool match;
-		if (isSaving()) {
-			_saveStream->write(magic, size);
-			match = true;
-		} else {
-			_loadStream->read(buf, size);
-			match = (0 == memcmp(buf, magic, size));
-		}
-		_bytesSynced += size;
-		return match;
-	}
 
-
 	/**
 	 * Return the total number of bytes synced so far.
 	 */
@@ -193,6 +165,35 @@
 	}
 
 	/**
+	 * Sync a 'magic id' of up to 256 bytes, and return whether it matched.
+	 * When saving, this will simply write out the magic id and return true.
+	 * When loading, this will read the specified number of bytes, compare it
+	 * to the given magic id and return true on a match, false otherwise.
+	 *
+	 * A typical magic id is a FOURCC like 'MAGI'.
+	 *
+	 * @param magic		magic id as a byte sequence
+	 * @param size		length of the magic id in bytes
+	 * @return true if the magic id matched, false otherwise
+	 */
+	bool matchBytes(const char *magic, byte size, Version minVersion = 0, Version maxVersion = kLastVersion) {
+		if (_version < minVersion || _version > maxVersion)
+			return true;	// Ignore anything which is not supposed to be present in this save game version
+
+		bool match;
+		if (isSaving()) {
+			_saveStream->write(magic, size);
+			match = true;
+		} else {
+			char buf[256];
+			_loadStream->read(buf, size);
+			match = (0 == memcmp(buf, magic, size));
+		}
+		_bytesSynced += size;
+		return match;
+	}
+
+	/**
 	 * Sync a C-string, by treating it as a zero-terminated byte sequence.
 	 * @todo Replace this method with a special Syncer class for Common::String
 	 */

Modified: scummvm/trunk/test/common/serializer.h
===================================================================
--- scummvm/trunk/test/common/serializer.h	2009-05-26 11:30:21 UTC (rev 40908)
+++ scummvm/trunk/test/common/serializer.h	2009-05-26 11:31:45 UTC (rev 40909)
@@ -43,7 +43,7 @@
 	void readVersioned_v1(Common::SeekableReadStream *stream, Common::Serializer::Version version) {
 		Common::Serializer  ser(stream, 0);
 
-		TS_ASSERT(ser.syncMagic("MAGI", 4));
+		TS_ASSERT(ser.matchBytes("MAGI", 4));
 
 		TS_ASSERT(ser.syncVersion(1));
 		TS_ASSERT_EQUALS(ser.getVersion(), version);
@@ -64,7 +64,7 @@
 	void readVersioned_v2(Common::SeekableReadStream *stream, Common::Serializer::Version version) {
 		Common::Serializer  ser(stream, 0);
 
-		TS_ASSERT(ser.syncMagic("MAGI", 4));
+		TS_ASSERT(ser.matchBytes("MAGI", 4));
 
 		TS_ASSERT(ser.syncVersion(2));
 		TS_ASSERT_EQUALS(ser.getVersion(), version);


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