2010-09-07 09:08:09 +00:00
|
|
|
#ifndef MANGLE_STREAM_IOSTREAM_H
|
|
|
|
#define MANGLE_STREAM_IOSTREAM_H
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include "../stream.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Mangle {
|
|
|
|
namespace Stream {
|
|
|
|
|
|
|
|
/** This file contains classes for wrapping an std::istream or
|
2010-09-07 11:12:21 +00:00
|
|
|
std::ostream around a Mangle::Stream.
|
2010-09-07 09:08:09 +00:00
|
|
|
|
|
|
|
This allows you to use Mangle streams in places that require std
|
2010-09-07 11:12:21 +00:00
|
|
|
streams.
|
2010-09-07 09:08:09 +00:00
|
|
|
|
2010-09-07 11:12:21 +00:00
|
|
|
This is much easier than trying to make your own custom streams
|
|
|
|
into iostreams. The std::iostream interface is horrible and NOT
|
|
|
|
designed for easy subclassing. Create a Mangle::Stream instead,
|
|
|
|
and use this wrapper.
|
|
|
|
*/
|
2010-09-07 09:08:09 +00:00
|
|
|
|
2010-09-07 11:12:21 +00:00
|
|
|
// An istream wrapping a readable Mangle::Stream. Has extra
|
|
|
|
// optimizations for pointer-based streams.
|
2010-09-07 09:08:09 +00:00
|
|
|
class MangleIStream : public std::istream
|
|
|
|
{
|
2010-09-07 11:12:21 +00:00
|
|
|
std::streambuf *buf;
|
2010-09-07 09:08:09 +00:00
|
|
|
public:
|
2010-09-07 11:12:21 +00:00
|
|
|
MangleIStream(StreamPtr inp);
|
|
|
|
~MangleIStream();
|
2010-09-07 09:08:09 +00:00
|
|
|
};
|
|
|
|
|
2010-09-07 11:12:21 +00:00
|
|
|
// An ostream wrapping a writable Mangle::Stream.
|
2010-09-07 09:08:09 +00:00
|
|
|
class MangleOStream : public std::ostream
|
|
|
|
{
|
2010-09-07 11:12:21 +00:00
|
|
|
std::streambuf *buf;
|
2010-09-07 09:08:09 +00:00
|
|
|
public:
|
2010-09-07 11:12:21 +00:00
|
|
|
MangleOStream(StreamPtr inp);
|
|
|
|
~MangleOStream();
|
2010-09-07 09:08:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}} // namespaces
|
|
|
|
#endif
|