From eb75e394b34de8f78d38c8d49c7a5eadf2894739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Mocquillon?= Date: Sat, 20 Nov 2021 11:11:12 +0100 Subject: [PATCH] Use Files::MemBuf for Bsa::MemoryInputStream base classe instead of making a duplicate (MemoryInputStreamBuf) --- components/CMakeLists.txt | 2 +- components/bsa/memorystream.cpp | 48 --------------------------------- components/bsa/memorystream.hpp | 28 +++++++++---------- 3 files changed, 13 insertions(+), 65 deletions(-) delete mode 100644 components/bsa/memorystream.cpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 012677fc0d..abcec188f4 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -37,7 +37,7 @@ add_component_dir (settings ) add_component_dir (bsa - bsa_file compressedbsafile memorystream + bsa_file compressedbsafile ) add_component_dir (vfs diff --git a/components/bsa/memorystream.cpp b/components/bsa/memorystream.cpp deleted file mode 100644 index 34e98e6b68..0000000000 --- a/components/bsa/memorystream.cpp +++ /dev/null @@ -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(this)) { - -} - -char* MemoryInputStream::getRawData() { - return MemoryInputStreamBuf::getRawData(); -} -} diff --git a/components/bsa/memorystream.hpp b/components/bsa/memorystream.hpp index d168e93d65..5aae448299 100644 --- a/components/bsa/memorystream.hpp +++ b/components/bsa/memorystream.hpp @@ -28,22 +28,10 @@ #include #include +#include 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 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, public virtual Files::MemBuf, public std::istream { public: - explicit MemoryInputStream(size_t bufferSize); - char* getRawData() override; + explicit MemoryInputStream(size_t bufferSize) + : std::vector(bufferSize) + , Files::MemBuf(this->data(), this->size()) + , std::istream(static_cast(this)) + {} + + char* getRawData() + { + return this->data(); + } }; }