mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-29 23:33:00 +00:00
- use std::vector for the MemoryArrayReader
This commit is contained in:
parent
2671394961
commit
def6bffdfc
6 changed files with 12 additions and 14 deletions
|
@ -36,10 +36,7 @@
|
|||
#include <time.h>
|
||||
#include <stdexcept>
|
||||
#include "file_zip.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
#include "w_zip.h"
|
||||
|
||||
#include "ancientzip.h"
|
||||
#include "fs_findfile.h"
|
||||
#include "fs_swap.h"
|
||||
|
|
|
@ -329,26 +329,26 @@ char *MemoryReader::Gets(char *strbuf, int len)
|
|||
|
||||
class MemoryArrayReader : public MemoryReader
|
||||
{
|
||||
TArray<uint8_t> buf;
|
||||
std::vector<uint8_t> buf;
|
||||
|
||||
public:
|
||||
MemoryArrayReader(const char *buffer, long length)
|
||||
{
|
||||
if (length > 0)
|
||||
{
|
||||
buf.Resize(length);
|
||||
buf.resize(length);
|
||||
memcpy(&buf[0], buffer, length);
|
||||
}
|
||||
UpdateBuffer();
|
||||
}
|
||||
|
||||
TArray<uint8_t> &GetArray() { return buf; }
|
||||
std::vector<uint8_t> &GetArray() { return buf; }
|
||||
|
||||
void UpdateBuffer()
|
||||
{
|
||||
bufptr = (const char*)&buf[0];
|
||||
bufptr = (const char*)buf.data();
|
||||
FilePos = 0;
|
||||
Length = buf.Size();
|
||||
Length = (long)buf.size();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -397,7 +397,7 @@ bool FileReader::OpenMemoryArray(const void *mem, FileReader::Size length)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileReader::OpenMemoryArray(std::function<bool(TArray<uint8_t>&)> getter)
|
||||
bool FileReader::OpenMemoryArray(std::function<bool(std::vector<uint8_t>&)> getter)
|
||||
{
|
||||
auto reader = new MemoryArrayReader(nullptr, 0);
|
||||
if (getter(reader->GetArray()))
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <functional>
|
||||
#include "basics.h"
|
||||
#include "fs_swap.h"
|
||||
|
||||
#include "tarray.h"
|
||||
|
||||
class FileSystemException : public std::exception
|
||||
|
@ -196,7 +196,7 @@ public:
|
|||
bool OpenFilePart(FileReader &parent, Size start, Size length);
|
||||
bool OpenMemory(const void *mem, Size length); // read directly from the buffer
|
||||
bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer.
|
||||
bool OpenMemoryArray(std::function<bool(TArray<uint8_t>&)> getter); // read contents to a buffer and return a reader to it
|
||||
bool OpenMemoryArray(std::function<bool(std::vector<uint8_t>&)> getter); // read contents to a buffer and return a reader to it
|
||||
bool OpenDecompressor(FileReader &parent, Size length, int method, bool seekable, bool exceptions = false); // creates a decompressor stream. 'seekable' uses a buffered version so that the Seek and Tell methods can be used.
|
||||
|
||||
Size Tell() const
|
||||
|
|
|
@ -320,10 +320,10 @@ unsigned FSavegameManagerBase::ExtractSaveData(int index)
|
|||
{
|
||||
FileReader picreader;
|
||||
|
||||
picreader.OpenMemoryArray([=](TArray<uint8_t> &array)
|
||||
picreader.OpenMemoryArray([=](std::vector<uint8_t> &array)
|
||||
{
|
||||
auto cache = pic->Lock();
|
||||
array.Resize(pic->LumpSize);
|
||||
array.resize(pic->LumpSize);
|
||||
memcpy(&array[0], cache, pic->LumpSize);
|
||||
pic->Unlock();
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "basics.h"
|
||||
|
||||
|
||||
struct FModelVertex
|
||||
|
|
|
@ -983,7 +983,7 @@ void md5Update(FileReader& file, MD5Context& md5, unsigned len)
|
|||
|
||||
while (len > 0)
|
||||
{
|
||||
t = min<unsigned>(len, sizeof(readbuf));
|
||||
t = std::min<unsigned>(len, sizeof(readbuf));
|
||||
len -= t;
|
||||
t = (long)file.Read(readbuf, t);
|
||||
md5.Update(readbuf, t);
|
||||
|
|
Loading…
Reference in a new issue