Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor|libdeng2: Files are I/O streams instead of byte arrays
IIOStream is an interface that provides access to an object through a stream of bytes. Changed the interface of de::File, the base class for all files, from IByteArray to IIOStream. While many files are byte array based, there are also other kinds of files that behave like streams (cf. UNIX sockets, character devices). Added ByteArrayFile: an abstract base class for random-access byte array based files, where the I/O stream has a default implementation that accesses the file's contents (as a byte array). Block, Writer, and Reader constructors accept I/O streams as source/destination objects. Refactored Reader's rewind mechanism to work also with streams. Applied the pimpl idiom in Reader, Writer, and ArchiveFeed. Updated the rest of libdeng2 accordingly.
- Loading branch information
Showing
31 changed files
with
850 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "filesys/bytearrayfile.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "data/iiostream.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* @file iiostream.h | ||
* I/O stream interface. @ingroup data | ||
* | ||
* @authors Copyright © 2012 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. 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 along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBDENG2_IIOSTREAM_H | ||
#define LIBDENG2_IIOSTREAM_H | ||
|
||
#include "../IByteArray" | ||
|
||
namespace de { | ||
|
||
/** | ||
* Interface that allows communication via an input/output stream of bytes. | ||
* | ||
* When reading from a stream, the stream can either be in modifiable | ||
* (non-const) or immutable (const) mode. When reading bytes from a modifiable | ||
* stream, the bytes are then removed from the stream and the next read will | ||
* return a different set of bytes. Immutable streams, on the other hand, can | ||
* be used for peeking ahead into the received data: the bytes are not removed | ||
* from the stream during the read. | ||
*/ | ||
class IIOStream | ||
{ | ||
public: | ||
/// I/O to the stream failed. @ingroup errors | ||
DENG2_ERROR(IOError); | ||
|
||
/// Only reading is allowed from the stream. @ingroup errors | ||
DENG2_SUB_ERROR(IOError, ReadOnlyError); | ||
|
||
public: | ||
virtual ~IIOStream() {} | ||
|
||
/** | ||
* Writes an array of bytes to the stream. | ||
* | ||
* @param bytes Byte array to write. | ||
* | ||
* @return Reference to this IIOStream object. | ||
*/ | ||
virtual IIOStream& operator << (const IByteArray& bytes) = 0; | ||
|
||
/** | ||
* Reads all the available bytes into the array @a bytes. If there is | ||
* nothing available for reading, nothing is written to @a bytes. The | ||
* stream operates as a modifiable object: once read, the bytes are | ||
* considered to be removed from the stream. | ||
* | ||
* @param bytes Read bytes are stored here. | ||
* | ||
* @return Reference to this IIOStream object. | ||
*/ | ||
virtual IIOStream& operator >> (IByteArray& bytes) = 0; | ||
|
||
/** | ||
* Reads all the available bytes into the array @a bytes. If there is | ||
* nothing available for reading, nothing is written to @a bytes. | ||
* | ||
* Immutable streams can be used for peeking ahead into the received data. | ||
* Here the stream operates as a const object: the read bytes are not | ||
* removed from the stream, and a subsequent read will return the same | ||
* bytes, plus any additional bytes that may have been produced in the | ||
* meantime. | ||
* | ||
* @param bytes Read bytes are stored here. | ||
* | ||
* @return Reference to this IIOStream object. | ||
*/ | ||
virtual const IIOStream& operator >> (IByteArray& bytes) const = 0; | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // LIBDENG2_IIOSTREAM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.