mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2024-12-29 03:19:44 +00:00
Use Files::MemBuf for Bsa::MemoryInputStream base classe instead of making a duplicate (MemoryInputStreamBuf)
This commit is contained in:
parent
8a7b4649f0
commit
eb75e394b3
@ -37,7 +37,7 @@ add_component_dir (settings
|
||||
)
|
||||
|
||||
add_component_dir (bsa
|
||||
bsa_file compressedbsafile memorystream
|
||||
bsa_file compressedbsafile
|
||||
)
|
||||
|
||||
add_component_dir (vfs
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
OpenMW - The completely unofficial reimplementation of Morrowind
|
||||
Copyright (C) 2008-2010 Nicolay Korslund
|
||||
Email: < korslund@gmail.com >
|
||||
WWW: http://openmw.sourceforge.net/
|
||||
|
||||
This file (memorystream.cpp) is part of the OpenMW package.
|
||||
|
||||
OpenMW is distributed as free software: you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License
|
||||
version 3, as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 3 along with this program. If not, see
|
||||
http://www.gnu.org/licenses/ .
|
||||
|
||||
Compressed BSA upgrade added by Azdul 2019
|
||||
|
||||
*/
|
||||
#include "memorystream.hpp"
|
||||
|
||||
|
||||
namespace Bsa
|
||||
{
|
||||
MemoryInputStreamBuf::MemoryInputStreamBuf(size_t bufferSize) : mBufferPtr(bufferSize)
|
||||
{
|
||||
this->setg(mBufferPtr.data(), mBufferPtr.data(), mBufferPtr.data() + bufferSize);
|
||||
}
|
||||
|
||||
char* MemoryInputStreamBuf::getRawData() {
|
||||
return mBufferPtr.data();
|
||||
}
|
||||
|
||||
MemoryInputStream::MemoryInputStream(size_t bufferSize) :
|
||||
MemoryInputStreamBuf(bufferSize),
|
||||
std::istream(static_cast<std::streambuf*>(this)) {
|
||||
|
||||
}
|
||||
|
||||
char* MemoryInputStream::getRawData() {
|
||||
return MemoryInputStreamBuf::getRawData();
|
||||
}
|
||||
}
|
@ -28,22 +28,10 @@
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <components/files/memorystream.hpp>
|
||||
|
||||
namespace Bsa
|
||||
{
|
||||
/**
|
||||
Class used internally by MemoryInputStream.
|
||||
*/
|
||||
class MemoryInputStreamBuf : public std::streambuf {
|
||||
|
||||
public:
|
||||
explicit MemoryInputStreamBuf(size_t bufferSize);
|
||||
virtual char* getRawData();
|
||||
private:
|
||||
//correct call to delete [] on C++ 11
|
||||
std::vector<char> mBufferPtr;
|
||||
};
|
||||
|
||||
/**
|
||||
Class replaces Ogre memory streams without introducing any new external dependencies
|
||||
beyond standard library.
|
||||
@ -52,10 +40,18 @@ private:
|
||||
|
||||
Memory buffer is freed once the class instance is destroyed.
|
||||
*/
|
||||
class MemoryInputStream : virtual MemoryInputStreamBuf, std::istream {
|
||||
class MemoryInputStream : private std::vector<char>, public virtual Files::MemBuf, public std::istream {
|
||||
public:
|
||||
explicit MemoryInputStream(size_t bufferSize);
|
||||
char* getRawData() override;
|
||||
explicit MemoryInputStream(size_t bufferSize)
|
||||
: std::vector<char>(bufferSize)
|
||||
, Files::MemBuf(this->data(), this->size())
|
||||
, std::istream(static_cast<std::streambuf*>(this))
|
||||
{}
|
||||
|
||||
char* getRawData()
|
||||
{
|
||||
return this->data();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user