5 * $XConsortium: Buffer.hh /main/4 1996/04/21 19:44:23 drk $
7 * RESTRICTED CONFIDENTIAL INFORMATION:
9 * The information in this document is subject to special
10 * restrictions in a confidential disclosure agreement bertween
11 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
13 * Sun's specific written approval. This documment and all copies
14 * and derivative works thereof must be returned or destroyed at
17 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
22 #ifndef _DTMAILBUFFER_HH
23 #define _DTMAILBUFFER_HH
27 // these classes are provided in order to have a logical array whose
28 // size is not known at creation time. The DtMailBuffer class
29 // holds the data, and for the moment holds the only "write" operation
30 // (which is append). In addition, to be thread safe, there is
31 // a separate class for reading, so that you can have separate
32 // "seek points" in the read buffer in different procedures.
40 static const int defaultchunksize;
46 // actually add data. result is # of bytes written. Can
47 // fail if underlying write fails, or if out of memory.
48 virtual int appendData(const char *user_buffer, int length) = 0;
50 // an interator function that gets called so that eventually
51 // the entire buffer has been passed through
52 typedef unsigned long (*CallBack)(const char *buffer, int len, va_list);
53 virtual unsigned long iterate(CallBack, ...) = 0;
55 // get a new reader object
56 virtual BufReader *getReader(void) = 0;
58 virtual int getSize(void) = 0; // get total size of the buffer
62 virtual ~Buffer(void);
64 Buffer(const Buffer&); // try and avoid copies
72 // actually read data into a user specified buffer
73 virtual int getData(char *user_buffer, int length) = 0;
74 virtual ~BufReader(void);
79 BufReader(const BufReader &);
83 class BufReaderMemory;
84 class BufferMemory : public Buffer {
88 friend class BufReaderMemory;
90 BufferMemory(int chunksize);
92 virtual ~BufferMemory(void);
94 // actually add data. result is # of bytes written. Can
95 // fail if underlying write fails, or if out of memory.
96 virtual int appendData(const char *user_buffer, int length);
98 virtual unsigned long iterate(Buffer::CallBack, ...);
100 // get a new reader object
101 virtual BufReader *getReader(void);
103 virtual int getSize(void); // get total size of the buffer
106 #if !defined(linux) && !defined(CSRG_BASED) && !defined(sun)
110 BufferMemory(const Buffer&); // try and avoid copies
111 void initBuffer(int size); // common constructor
112 int newChunk(int size); // get a new data chunk
114 Chunk *_firstchunk; // first chunk
115 Chunk *_lastchunk; // last chunk
116 int _totalsize; // total size in all buffers
117 int _chunksize; // size to allocate new buffers
121 BufReaderMemory *_firstreader; // linked list of readers
125 // aux structure to hold data; no active functions
127 struct Chunk *_nextchunk; // next element in linked list
128 char *_buffer; // data buffer
129 int _chunksize; // allocated size of buffer
130 int _currentend; // current used space
133 // subsidiary classes
136 class BufReaderMemory : protected BufReader {
137 friend class BufferMemory;
140 // actually read data into a user specified buffer
141 virtual int getData(char *user_buffer, int length);
142 virtual ~BufReaderMemory(void);
145 BufReaderMemory(const BufReaderMemory &);
146 BufReaderMemory(BufferMemory *);
148 BufferMemory::Chunk *_currentchunk;
151 BufferMemory *_buffer;
152 BufReaderMemory *_nextreader; // maintain linked list of readers
153 BufReaderMemory *_prevreader; // maintain linked list of readers
156 #endif // _DTMAILBUFFER_HH