| 1 |
#ifndef TmpOutputByteStream_INCLUDED |
| 2 |
#define TmpOutputByteStream_INCLUDED 1 |
| 3 |
|
| 4 |
#include <OpenSP/OutputByteStream.h> |
| 5 |
#include <OpenSP/Boolean.h> |
| 6 |
|
| 7 |
#ifdef DSSSL_NAMESPACE |
| 8 |
namespace DSSSL_NAMESPACE { |
| 9 |
#endif |
| 10 |
|
| 11 |
#ifdef SP_NAMESPACE |
| 12 |
using namespace SP_NAMESPACE; |
| 13 |
#endif |
| 14 |
|
| 15 |
class TmpOutputByteStream : public OutputByteStream { |
| 16 |
public: |
| 17 |
enum { bufSize = 1024 }; |
| 18 |
struct Block { |
| 19 |
Block *next; |
| 20 |
char buf[bufSize]; |
| 21 |
}; |
| 22 |
class Iter { |
| 23 |
public: |
| 24 |
Iter(const TmpOutputByteStream &sb) : block_(sb.head_), lastBlockUsed_(sb.lastBlockUsed()) { } |
| 25 |
bool next(const char *&p, size_t &n) { |
| 26 |
if (block_) { |
| 27 |
p = block_->buf; |
| 28 |
n = block_->next ? TmpOutputByteStream::bufSize : lastBlockUsed_; |
| 29 |
block_ = block_->next; |
| 30 |
return 1; |
| 31 |
} |
| 32 |
else |
| 33 |
return 0; |
| 34 |
} |
| 35 |
private: |
| 36 |
Block *block_; |
| 37 |
size_t lastBlockUsed_; |
| 38 |
}; |
| 39 |
TmpOutputByteStream(); |
| 40 |
~TmpOutputByteStream(); |
| 41 |
bool isEmpty() { return head_ == 0; } |
| 42 |
void flush(); |
| 43 |
void flushBuf(char ch); |
| 44 |
private: |
| 45 |
friend class Iter; |
| 46 |
size_t lastBlockUsed() const { |
| 47 |
return last_ ? (ptr_ - last_->buf) : 0; |
| 48 |
} |
| 49 |
unsigned nFullBlocks_; |
| 50 |
Block *head_; |
| 51 |
Block *last_; |
| 52 |
}; |
| 53 |
|
| 54 |
#ifdef DSSSL_NAMESPACE |
| 55 |
} |
| 56 |
#endif |
| 57 |
|
| 58 |
#endif /* not OutputByteStream_INCLUDED */ |