aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-05-26 11:31:45 +0000
committerMax Horn2009-05-26 11:31:45 +0000
commit1c552779a030f649de0089aa4609fbe66271a707 (patch)
tree25a11a3b6d80a871a6534e08d49c2091407864a2
parent7d5f3e1714dff2f0beed0f10bcce01be8204f377 (diff)
downloadscummvm-rg350-1c552779a030f649de0089aa4609fbe66271a707.tar.gz
scummvm-rg350-1c552779a030f649de0089aa4609fbe66271a707.tar.bz2
scummvm-rg350-1c552779a030f649de0089aa4609fbe66271a707.zip
Renamed Common::Serializer::syncMagic to matchBytes, and added version paarms to it (we migh want to add corresponding matchUint32LE etc. functions if needed)
svn-id: r40909
-rw-r--r--common/serializer.h57
-rw-r--r--test/common/serializer.h4
2 files changed, 31 insertions, 30 deletions
diff --git a/common/serializer.h b/common/serializer.h
index a44883683b..013a91c0d2 100644
--- a/common/serializer.h
+++ b/common/serializer.h
@@ -127,34 +127,6 @@ public:
*/
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 @@ public:
}
/**
+ * 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
*/
diff --git a/test/common/serializer.h b/test/common/serializer.h
index b3b04e7711..160e5ad667 100644
--- a/test/common/serializer.h
+++ b/test/common/serializer.h
@@ -43,7 +43,7 @@ public:
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 @@ public:
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);