Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move remaining classes into own header file, remove archivelib.h
  • Loading branch information
codereader committed Aug 31, 2017
1 parent 829872a commit 7ca9968
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 95 deletions.
2 changes: 1 addition & 1 deletion libs/DirectoryArchiveFile.h
@@ -1,7 +1,7 @@
#pragma once

#include "iarchive.h"
#include "archivelib.h"
#include "stream/filestream.h"

namespace archive
{
Expand Down
2 changes: 1 addition & 1 deletion libs/DirectoryArchiveTextFile.h
@@ -1,7 +1,7 @@
#pragma once

#include "iarchive.h"
#include "archivelib.h"
#include "stream/textfilestream.h"

namespace archive
{
Expand Down
77 changes: 0 additions & 77 deletions libs/archivelib.h

This file was deleted.

91 changes: 91 additions & 0 deletions libs/stream/BinaryToTextInputStream.h
@@ -0,0 +1,91 @@
#pragma once

#include "itextstream.h"

namespace stream
{

/// \brief A single-byte-reader wrapper around an InputStream.
/// Optimised for reading one byte at a time.
/// Uses a buffer to reduce the number of times the wrapped stream must be read.
template<typename InputStreamType>
class SingleByteInputStream
{
private:
typedef typename InputStreamType::byte_type byte_type;

static const std::size_t SIZE = 1024;

InputStreamType& _inputStream;
byte_type _buffer[SIZE];
byte_type* _cur;
byte_type* _end;

public:
SingleByteInputStream(InputStreamType& inputStream) :
_inputStream(inputStream),
_cur(_buffer + SIZE),
_end(_cur)
{}

bool readByte(byte_type& b)
{
if (_cur == _end)
{
if (_end != _buffer + SIZE)
{
return false;
}

_end = _buffer + _inputStream.read(_buffer, SIZE);
_cur = _buffer;

if (_end == _buffer)
{
return false;
}
}

b = *_cur++;

return true;
}
};

/// \brief A binary-to-text wrapper around an InputStream.
/// Converts CRLF or LFCR line-endings to LF line-endings.
template<typename BinaryInputStreamType>
class BinaryToTextInputStream :
public TextInputStream
{
private:
SingleByteInputStream<BinaryInputStreamType> _inputStream;

public:
BinaryToTextInputStream(BinaryInputStreamType& inputStream) :
_inputStream(inputStream)
{}

std::size_t read(char* buffer, std::size_t length) override
{
char* p = buffer;
for (;;)
{
if (length != 0 && _inputStream.readByte(*reinterpret_cast<typename BinaryInputStreamType::byte_type*>(p)))
{
if (*p != '\r')
{
++p;
--length;
}
}
else
{
return p - buffer;
}
}
}
};

}

4 changes: 2 additions & 2 deletions plugins/archivezip/DeflatedArchiveTextFile.h
Expand Up @@ -2,7 +2,7 @@

#include "iarchive.h"
#include "iregistry.h"
#include "archivelib.h"
#include "stream/BinaryToTextInputStream.h"

namespace archive
{
Expand All @@ -18,7 +18,7 @@ class DeflatedArchiveTextFile :
FileInputStream _istream;
SubFileInputStream _substream; // reads subset of _istream
DeflatedInputStream _zipstream; // inflates data from _substream
BinaryToTextInputStream<DeflatedInputStream> _textStream; // converts data from _zipstream
stream::BinaryToTextInputStream<DeflatedInputStream> _textStream; // converts data from _zipstream

// Mod directory containing this file
const std::string _modName;
Expand Down
1 change: 0 additions & 1 deletion plugins/archivezip/StoreArchiveFile.h
@@ -1,7 +1,6 @@
#pragma once

#include "iarchive.h"
#include "archivelib.h"

namespace archive
{
Expand Down
4 changes: 2 additions & 2 deletions plugins/archivezip/StoredArchiveTextFile.h
@@ -1,7 +1,7 @@
#pragma once

#include "iarchive.h"
#include "archivelib.h"
#include "stream/BinaryToTextInputStream.h"

namespace archive
{
Expand All @@ -14,7 +14,7 @@ class StoredArchiveTextFile :
std::string _name;
FileInputStream _filestream;
SubFileInputStream _substream; // provides a subset of _filestream
BinaryToTextInputStream<SubFileInputStream> _textStream; // converts data from _substream
stream::BinaryToTextInputStream<SubFileInputStream> _textStream; // converts data from _substream

// Mod directory
std::string _modName;
Expand Down
1 change: 0 additions & 1 deletion plugins/archivezip/ZipArchive.cpp
Expand Up @@ -3,7 +3,6 @@
#include <stdexcept>
#include "itextstream.h"
#include "iarchive.h"
#include "archivelib.h"
#include "gamelib.h"
#include <zlib.h>

Expand Down
1 change: 0 additions & 1 deletion plugins/eclassmgr/EClassManager.cpp
Expand Up @@ -10,7 +10,6 @@
#include "iradiant.h"
#include "iuimanager.h"
#include "ifilesystem.h"
#include "archivelib.h"
#include "parser/DefTokeniser.h"

#include "Doom3EntityClass.h"
Expand Down
1 change: 0 additions & 1 deletion plugins/image/Doom3ImageLoader.cpp
Expand Up @@ -5,7 +5,6 @@

#include "ifilesystem.h"
#include "iarchive.h"
#include "archivelib.h"
#include "iregistry.h"
#include "igame.h"

Expand Down
5 changes: 3 additions & 2 deletions plugins/md5model/MD5ModelLoader.cpp
@@ -1,11 +1,12 @@
#include "MD5ModelLoader.h"

#include "idatastream.h"
#include "iarchive.h"
#include "imodule.h"
#include "ishaders.h"
#include "imodelcache.h"
#include "ifilesystem.h"
#include "archivelib.h"
#include "stream/BinaryToTextInputStream.h"
#include "os/path.h"

#include "MD5ModelNode.h"
Expand Down Expand Up @@ -79,7 +80,7 @@ model::IModelPtr MD5ModelLoader::loadModelFromPath(const std::string& name)
model->setFilename(os::getFilename(file->getName()));

// greebo: Get the Inputstream from the given file
BinaryToTextInputStream<InputStream> inputStream(file->getInputStream());
stream::BinaryToTextInputStream<InputStream> inputStream(file->getInputStream());

// Construct a Tokeniser object and start reading the file
try
Expand Down
1 change: 0 additions & 1 deletion plugins/sound/SoundManager.cpp
Expand Up @@ -2,7 +2,6 @@
#include "SoundFileLoader.h"

#include "ifilesystem.h"
#include "archivelib.h"

#include "debugging/ScopedDebugTimer.h"

Expand Down
1 change: 0 additions & 1 deletion plugins/sound/SoundPlayer.cpp
Expand Up @@ -6,7 +6,6 @@
#include <boost/algorithm/string/case_conv.hpp>

#include "stream/textfilestream.h"
#include "archivelib.h"
#include "os/path.h"
#include <memory>

Expand Down
1 change: 0 additions & 1 deletion plugins/vfspk3/DirectoryArchive.cpp
@@ -1,6 +1,5 @@
#include "DirectoryArchive.h"

#include "archivelib.h"
#include "gamelib.h"
#include "UnixPath.h"
#include "os/file.h"
Expand Down
1 change: 0 additions & 1 deletion plugins/vfspk3/Doom3FileSystem.cpp
Expand Up @@ -26,7 +26,6 @@
#include "string/string.h"
#include "os/path.h"
#include "os/dir.h"
#include "archivelib.h"
#include "moduleobservers.h"

#include <boost/algorithm/string/case_conv.hpp>
Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/libs.vcxproj
Expand Up @@ -138,7 +138,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\libs\archivelib.h" />
<ClInclude Include="..\..\libs\BasicTexture2D.h" />
<ClInclude Include="..\..\libs\BasicUndoMemento.h" />
<ClInclude Include="..\..\libs\bytestreamutils.h" />
Expand Down Expand Up @@ -194,6 +193,7 @@
<ClInclude Include="..\..\libs\scenelib.h" />
<ClInclude Include="..\..\libs\selectionlib.h" />
<ClInclude Include="..\..\libs\shaderlib.h" />
<ClInclude Include="..\..\libs\stream\BinaryToTextInputStream.h" />
<ClInclude Include="..\..\libs\stream\BufferInputStream.h" />
<ClInclude Include="..\..\libs\stream\filestream.h" />
<ClInclude Include="..\..\libs\stream\PointerInputStream.h" />
Expand Down
4 changes: 3 additions & 1 deletion tools/msvc/libs.vcxproj.filters
Expand Up @@ -12,7 +12,6 @@
<ClInclude Include="..\..\libs\shaderlib.h" />
<ClInclude Include="..\..\libs\texturelib.h" />
<ClInclude Include="..\..\libs\transformlib.h" />
<ClInclude Include="..\..\libs\archivelib.h" />
<ClInclude Include="..\..\libs\BasicTexture2D.h" />
<ClInclude Include="..\..\libs\bytestreamutils.h" />
<ClInclude Include="..\..\libs\character.h" />
Expand Down Expand Up @@ -153,6 +152,9 @@
</ClInclude>
<ClInclude Include="..\..\libs\DirectoryArchiveFile.h" />
<ClInclude Include="..\..\libs\DirectoryArchiveTextFile.h" />
<ClInclude Include="..\..\libs\stream\BinaryToTextInputStream.h">
<Filter>stream</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="util">
Expand Down

0 comments on commit 7ca9968

Please sign in to comment.