mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-24 23:34:37 +01:00
60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
/*****************************************************************************
|
|
* Copyright (c) 2014-2018 OpenRCT2 developers
|
|
*
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
*
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
*****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include "DataSerialiserTraits.h"
|
|
|
|
#include <type_traits>
|
|
|
|
class DataSerialiser
|
|
{
|
|
private:
|
|
MemoryStream _stream;
|
|
MemoryStream* _activeStream;
|
|
bool _isSaving;
|
|
|
|
public:
|
|
DataSerialiser(bool isSaving)
|
|
: _isSaving(isSaving)
|
|
{
|
|
_activeStream = &_stream;
|
|
}
|
|
|
|
DataSerialiser(bool isSaving, MemoryStream& stream)
|
|
: _isSaving(isSaving)
|
|
{
|
|
_activeStream = &stream;
|
|
}
|
|
|
|
bool IsSaving() const
|
|
{
|
|
return _isSaving;
|
|
}
|
|
|
|
bool IsLoading() const
|
|
{
|
|
return !_isSaving;
|
|
}
|
|
|
|
MemoryStream& GetStream()
|
|
{
|
|
return _stream;
|
|
}
|
|
|
|
template<typename T> DataSerialiser& operator<<(T& data)
|
|
{
|
|
if (_isSaving)
|
|
DataSerializerTraits<T>::encode(_activeStream, data);
|
|
else
|
|
DataSerializerTraits<T>::decode(_activeStream, data);
|
|
return *this;
|
|
}
|
|
};
|