Skip to content

Commit

Permalink
Refactor|libdeng2: Split the IIOStream interface to IIStream and IOSt…
Browse files Browse the repository at this point in the history
…ream

Transmitter is now derived from IOStream, which means Socket implements
the output stream interface.
  • Loading branch information
skyjake committed Nov 22, 2012
1 parent e1e1d7c commit d18a9e9
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 126 deletions.
5 changes: 4 additions & 1 deletion doomsday/libdeng2/data.pri
Expand Up @@ -17,6 +17,7 @@ HEADERS += \
include/de/IBlock \
include/de/IByteArray \
include/de/IIOStream \
include/de/IOStream \
include/de/IReadable \
include/de/ISerializable \
include/de/IWritable \
Expand Down Expand Up @@ -56,6 +57,7 @@ HEADERS += \
include/de/data/iblock.h \
include/de/data/ibytearray.h \
include/de/data/iiostream.h \
include/de/data/iostream.h \
include/de/data/info.h \
include/de/data/ireadable.h \
include/de/data/iserializable.h \
Expand All @@ -77,7 +79,8 @@ HEADERS += \
include/de/data/waitable.h \
include/de/data/waitablefifo.h \
include/de/data/writer.h \
include/de/data/zeroed.h
include/de/data/zeroed.h \
include/de/data/iistream.h

SOURCES += \
src/data/accessorvalue.cpp \
Expand Down
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/IIStream
@@ -0,0 +1 @@
#include "data/iistream.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/IOStream
@@ -0,0 +1 @@
#include "data/iostream.h"
16 changes: 8 additions & 8 deletions doomsday/libdeng2/include/de/core/log.h
Expand Up @@ -88,15 +88,15 @@ class DENG2_PUBLIC Log
* to log which methods are entered and exited, and mark certain points within
* methods. Intended only for developers and debug builds.
*/
TRACE,
TRACE = 0,

/**
* Debug messages are intended for normal debugging. They should be enabled
* only in debug builds. An example of a debug message might be a printout of
* a ZIP archive's file count and size once an archive has been successfully
* opened. Intended only for developers and debug builds.
*/
DEBUG,
DEBUG = 1,

/**
* Verbose messages should be used to log technical information that is only
Expand All @@ -106,40 +106,40 @@ class DENG2_PUBLIC Log
* number of log entries, such as an entry about reading the contents of a
* file within a ZIP archive (which would be suitable for the DEBUG level).
*/
VERBOSE,
VERBOSE = 2,

/**
* Normal log entries are intended for regular users. An example: message about
* which map is being loaded.
*/
MESSAGE,
MESSAGE = 3,

/**
* Info messages are intended for situations that are particularly noteworthy.
* An info message should be used for instance when a script has been stopped
* because of an uncaught exception occurred during its execution.
*/
INFO,
INFO = 4,

/**
* Warning messages are reserved for recoverable error situations. A warning
* might be logged for example when the expected resource could not be found,
* and a fallback resource was used instead.
*/
WARNING,
WARNING = 5,

/**
* Error messages are intended for nonrecoverable errors. The error is grave
* enough to cause the shutting down of the current game, but the engine can
* still remain running.
*/
ERROR,
ERROR = 6,

/**
* Critical messages are intended for fatal errors that cause the engine to be
* shut down.
*/
CRITICAL,
CRITICAL = 7,

MAX_LOG_LEVELS
};
Expand Down
10 changes: 5 additions & 5 deletions doomsday/libdeng2/include/de/data/block.h
Expand Up @@ -27,7 +27,7 @@

namespace de {

class IIOStream;
class IIStream;

/**
* Data buffer that implements the byte array interface.
Expand All @@ -43,22 +43,22 @@ class DENG2_PUBLIC Block : public QByteArray, public IByteArray, public IBlock
Block(const QByteArray& byteArray);

/**
* Constructs a block by reading the contents of an I/O stream. The block
* Constructs a block by reading the contents of an input stream. The block
* will contain all the data that is available immediately; will not wait
* for additional data to become available later.
*
* @param stream Stream to read from.
*/
Block(IIOStream& stream);
Block(IIStream& stream);

/**
* Constructs a block by reading the contents of a I/O stream in const
* Constructs a block by reading the contents of an input stream in const
* mode. The block will contain all the data that is available immediately;
* will not wait for additional data to become available later.
*
* @param stream Stream to read from.
*/
Block(const IIOStream& stream);
Block(const IIStream& stream);

/**
* Construct a new block and copy its contents from the specified
Expand Down
58 changes: 5 additions & 53 deletions doomsday/libdeng2/include/de/data/iiostream.h
Expand Up @@ -21,68 +21,20 @@
#ifndef LIBDENG2_IIOSTREAM_H
#define LIBDENG2_IIOSTREAM_H

#include "../IByteArray"
#include "../IIStream"
#include "../IOStream"

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.
* @see IIStream, IOStream
*/
class IIOStream
class IIOStream : public IIStream, public IOStream
{
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;
DENG2_SUB_ERROR(OutputError, ReadOnlyError);
};

} // namespace de
Expand Down
78 changes: 78 additions & 0 deletions doomsday/libdeng2/include/de/data/iistream.h
@@ -0,0 +1,78 @@
/**
* @file iistream.h
* Input-only 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_IISTREAM_H
#define LIBDENG2_IISTREAM_H

#include "../IByteArray"

namespace de {

/**
* Interface that allows communication via an input stream of bytes.
*
* When reading from the stream, it 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 IIStream
{
public:
/// Input from the stream failed. @ingroup errors
DENG2_ERROR(InputError);

public:
virtual ~IIStream() {}

/**
* 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 IIStream object.
*/
virtual IIStream& 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 IIStream object.
*/
virtual const IIStream& operator >> (IByteArray& bytes) const = 0;
};

} // namespace de

#endif // LIBDENG2_IISTREAM_H
52 changes: 52 additions & 0 deletions doomsday/libdeng2/include/de/data/iostream.h
@@ -0,0 +1,52 @@
/**
* @file iostream.h
* Output-only 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_IOSTREAM_H
#define LIBDENG2_IOSTREAM_H

#include "../IByteArray"

namespace de {

/**
* Interface that allows communication via an output stream of bytes.
*/
class IOStream
{
public:
/// Output to the stream failed. @ingroup errors
DENG2_ERROR(OutputError);

public:
virtual ~IOStream() {}

/**
* Writes an array of bytes to the stream.
*
* @param bytes Byte array to write.
*
* @return Reference to this IOStream object.
*/
virtual IOStream& operator << (const IByteArray& bytes) = 0;
};

} // namespace de

#endif // LIBDENG2_IOSTREAM_H
6 changes: 3 additions & 3 deletions doomsday/libdeng2/include/de/data/reader.h
Expand Up @@ -30,7 +30,7 @@ class Block;
class String;
class IReadable;
class FixedByteArray;
class IIOStream;
class IIStream;

/**
* Provides a protocol for reading data from a byte array object (anything with
Expand Down Expand Up @@ -62,15 +62,15 @@ class DENG2_PUBLIC Reader
* @param stream Stream where input is read.
* @param byteOrder Byte order to use.
*/
Reader(IIOStream& stream, const ByteOrder& byteOrder = littleEndianByteOrder);
Reader(IIStream& stream, const ByteOrder& byteOrder = littleEndianByteOrder);

/**
* Constructs a new reader that reads from a const stream.
*
* @param stream Const stream where input is read.
* @param byteOrder Byte order to use.
*/
Reader(const IIOStream& stream, const ByteOrder& byteOrder = littleEndianByteOrder);
Reader(const IIStream& stream, const ByteOrder& byteOrder = littleEndianByteOrder);

//@{ Read a number from the source buffer, in network byte order.
Reader& operator >> (char& byte);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/include/de/data/writer.h
Expand Up @@ -31,7 +31,7 @@ class String;
class Block;
class ByteArrayFile;
class FixedByteArray;
class IIOStream;
class IOStream;

/**
* Provides a protocol for writing data in a specific byte order into a byte
Expand Down Expand Up @@ -71,7 +71,7 @@ class DENG2_PUBLIC Writer
* @param stream Stream to write to.
* @param byteOrder Byte order to use.
*/
Writer(IIOStream& stream, const ByteOrder& byteOrder = littleEndianByteOrder);
Writer(IOStream& stream, const ByteOrder& byteOrder = littleEndianByteOrder);

/**
* Constructs a new writer for writing into a byte array file.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libdeng2/include/de/filesys/bytearrayfile.h
Expand Up @@ -44,9 +44,9 @@ namespace de

public:
// Implements IIOStream.
IIOStream& operator << (const IByteArray& bytes);
IIOStream& operator >> (IByteArray& bytes);
const IIOStream& operator >> (IByteArray& bytes) const;
IOStream& operator << (const IByteArray& bytes);
IIStream& operator >> (IByteArray& bytes);
const IIStream& operator >> (IByteArray& bytes) const;
};
}

Expand Down

0 comments on commit d18a9e9

Please sign in to comment.