~ubuntu-branches/ubuntu/trusty/openjade1.3/trusty

« back to all changes in this revision

Viewing changes to jade/TmpOutputByteStream.h

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-04-09 00:01:50 UTC
  • Revision ID: james.westby@ubuntu.com-20020409000150-r9rkyalxlhvf9ba3
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef TmpOutputByteStream_INCLUDED
 
2
#define TmpOutputByteStream_INCLUDED 1
 
3
 
 
4
#include "OutputByteStream.h"
 
5
#include "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 */