From 1c552779a030f649de0089aa4609fbe66271a707 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 26 May 2009 11:31:45 +0000 Subject: 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 --- common/serializer.h | 57 +++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'common') 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. @@ -192,6 +164,35 @@ public: _bytesSynced += size; } + /** + * 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 -- cgit v1.2.3