2018-12-08 23:44:41 -07:00
|
|
|
#include "CVectorOutStream.h"
|
2026-01-16 23:07:28 -05:00
|
|
|
#include "Common/Math/MathUtil.h"
|
2018-12-08 23:44:41 -07:00
|
|
|
|
|
|
|
|
CVectorOutStream::CVectorOutStream()
|
2025-12-23 14:15:09 -05:00
|
|
|
: mpVector(new std::vector<char>())
|
2018-12-08 23:44:41 -07:00
|
|
|
{
|
2025-12-23 14:15:09 -05:00
|
|
|
mDataEndianness = std::endian::big;
|
2018-12-08 23:44:41 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-23 14:15:09 -05:00
|
|
|
CVectorOutStream::CVectorOutStream(std::endian DataEndianness)
|
|
|
|
|
: mpVector(new std::vector<char>())
|
2018-12-08 23:44:41 -07:00
|
|
|
{
|
|
|
|
|
mDataEndianness = DataEndianness;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 11:00:26 -05:00
|
|
|
CVectorOutStream::CVectorOutStream(uint32_t InitialSize, std::endian DataEndianness)
|
2018-12-08 23:44:41 -07:00
|
|
|
: mpVector(new std::vector<char>(InitialSize))
|
|
|
|
|
{
|
|
|
|
|
mDataEndianness = DataEndianness;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 14:15:09 -05:00
|
|
|
CVectorOutStream::CVectorOutStream(std::vector<char> *pVector, std::endian DataEndianness)
|
2018-12-08 23:44:41 -07:00
|
|
|
: mpVector(pVector)
|
|
|
|
|
, mOwnsVector(false)
|
|
|
|
|
{
|
|
|
|
|
mDataEndianness = DataEndianness;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CVectorOutStream::~CVectorOutStream()
|
|
|
|
|
{
|
2025-12-23 14:15:09 -05:00
|
|
|
if (mOwnsVector)
|
|
|
|
|
delete mpVector;
|
2018-12-08 23:44:41 -07:00
|
|
|
}
|
|
|
|
|
|
2026-01-11 11:00:26 -05:00
|
|
|
void CVectorOutStream::WriteBytes(const void *pkSrc, uint32_t Count)
|
2018-12-08 23:44:41 -07:00
|
|
|
{
|
2025-12-23 14:15:09 -05:00
|
|
|
if (!IsValid())
|
|
|
|
|
return;
|
2018-12-08 23:44:41 -07:00
|
|
|
|
2026-01-11 11:00:26 -05:00
|
|
|
uint32_t NewSize = mPos + Count;
|
2018-12-08 23:44:41 -07:00
|
|
|
|
|
|
|
|
if (NewSize > mpVector->size())
|
|
|
|
|
{
|
|
|
|
|
if (NewSize > mpVector->capacity())
|
2026-01-16 23:07:28 -05:00
|
|
|
mpVector->reserve(Math::Align(mPos + Count, skAllocSize));
|
2018-12-08 23:44:41 -07:00
|
|
|
|
|
|
|
|
mpVector->resize(NewSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(mpVector->data() + mPos, pkSrc, Count);
|
|
|
|
|
mPos += Count;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 11:00:26 -05:00
|
|
|
bool CVectorOutStream::Seek(int32_t Offset, uint32_t Origin)
|
2018-12-08 23:44:41 -07:00
|
|
|
{
|
2025-12-23 14:15:09 -05:00
|
|
|
if (!IsValid())
|
|
|
|
|
return false;
|
2018-12-08 23:44:41 -07:00
|
|
|
|
|
|
|
|
switch (Origin)
|
|
|
|
|
{
|
|
|
|
|
case SEEK_SET:
|
|
|
|
|
mPos = Offset;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEEK_CUR:
|
|
|
|
|
mPos += Offset;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SEEK_END:
|
|
|
|
|
mPos = mpVector->size() - Offset;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mPos < 0)
|
|
|
|
|
{
|
|
|
|
|
mPos = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mPos > mpVector->size())
|
|
|
|
|
mpVector->resize(mPos);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 11:00:26 -05:00
|
|
|
uint32_t CVectorOutStream::Tell() const
|
2018-12-08 23:44:41 -07:00
|
|
|
{
|
|
|
|
|
return mPos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CVectorOutStream::EoF() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CVectorOutStream::IsValid() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 11:00:26 -05:00
|
|
|
uint32_t CVectorOutStream::Size() const
|
2018-12-08 23:44:41 -07:00
|
|
|
{
|
|
|
|
|
return mPos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CVectorOutStream::SetVector(std::vector<char> *pVector)
|
|
|
|
|
{
|
|
|
|
|
if (mOwnsVector)
|
|
|
|
|
{
|
|
|
|
|
delete mpVector;
|
|
|
|
|
mOwnsVector = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpVector = pVector;
|
|
|
|
|
mPos = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* CVectorOutStream::Data()
|
|
|
|
|
{
|
|
|
|
|
return mpVector->data();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-17 13:44:30 -05:00
|
|
|
const void* CVectorOutStream::Data() const
|
|
|
|
|
{
|
|
|
|
|
return mpVector->data();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-08 23:44:41 -07:00
|
|
|
void* CVectorOutStream::DataAtPosition()
|
|
|
|
|
{
|
|
|
|
|
return mpVector->data() + mPos;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-17 13:44:30 -05:00
|
|
|
const void* CVectorOutStream::DataAtPosition() const
|
|
|
|
|
{
|
|
|
|
|
return mpVector->data() + mPos;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-08 23:44:41 -07:00
|
|
|
void CVectorOutStream::Clear()
|
|
|
|
|
{
|
|
|
|
|
mPos = 0;
|
|
|
|
|
mpVector->clear();
|
|
|
|
|
}
|