svn-id: r39658
This commit is contained in:
Max Horn 2009-03-24 11:30:52 +00:00
parent 48d73ff6bf
commit 47f9b2eb6d

View File

@ -33,7 +33,7 @@ namespace Common {
#define SYNC_AS(SUFFIX,TYPE,SIZE) \
template <class T> \
template <typename T> \
void syncAs ## SUFFIX(T &val) { \
if (_loadStream) \
val = static_cast<T>(_loadStream->read ## SUFFIX()); \
@ -57,8 +57,29 @@ public:
bool isSaving() { return (_saveStream != 0); }
bool isLoading() { return (_loadStream != 0); }
/**
* Return the total number of bytes synced so far.
*/
uint bytesSynced() const { return _bytesSynced; }
/**
* Skip a number of bytes in the data stream.
* This is useful to skip obsolete fields in old savestates.
*/
void skip(uint32 size) {
_bytesSynced += size;
if (_loadStream)
_loadStream->skip(size);
else {
while (size--)
_saveStream->writeByte(0);
}
}
/**
* Sync a block of arbitrary fixed-length data.
*/
void syncBytes(byte *buf, uint32 size) {
if (_loadStream)
_loadStream->read(buf, size);
@ -93,16 +114,6 @@ public:
syncBytes((byte *)buf, size);
}
void skip(uint32 size) {
_bytesSynced += size;
if (_loadStream)
_loadStream->skip(size);
else {
while (size--)
_saveStream->writeByte(0);
}
}
SYNC_AS(Byte, byte, 1)
SYNC_AS(Uint16LE, uint16, 2)