1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/filesystem/CMemoryStream.cpp
Andrey Filipenkov ff635edc0b wrap all library code into namespace if VCMI_LIB_NAMESPACE is defined
preparation for having client and server in a single process
2022-09-24 15:55:21 +03:00

54 lines
1.0 KiB
C++

/*
* CMemoryStream.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CMemoryStream.h"
VCMI_LIB_NAMESPACE_BEGIN
CMemoryStream::CMemoryStream(const ui8 * data, si64 size) :
data(data), size(size), position(0)
{
}
si64 CMemoryStream::read(ui8 * data, si64 size)
{
si64 toRead = std::min(this->size - tell(), size);
std::copy(this->data + position, this->data + position + toRead, data);
position += size;
return toRead;
}
si64 CMemoryStream::seek(si64 position)
{
si64 origin = tell();
this->position = std::min(position, size);
return tell() - origin;
}
si64 CMemoryStream::tell()
{
return this->position;
}
si64 CMemoryStream::skip(si64 delta)
{
si64 origin = tell();
this->position += std::min(size - origin, delta);
return tell() - origin;
}
si64 CMemoryStream::getSize()
{
return size;
}
VCMI_LIB_NAMESPACE_END