leo@atcmp.nl (Leo Willems) (08/18/90)
Can someone provide me with a small example of a derived class from streambuf. It should have: 1) a get area of 1 byte (to fetch chars from i.e. wgetch() ) 2) a put area of ~20 bytes. 3) the get and put areas are different arrays. 4) overflow() only outputs the put area to cerr 5) underflow() flushes, then fetches 1 character and returns. I have this working under 2.0 iostream, but the same code fails to work proparly on a different machine with 2.1 iostream. (different suppliers) So I guess my working example is just a case of bad luck :-( If someone can help me with a small example, thanks! For anybody who has some time left, here is the relevant part of the code, I think only the constructor, overflow() and underflow() are interesting: ======================= win.h: #ifndef WINH #define WINH #include <iostream.h> #include "hwin.h" class win : public streambuf { private: delta dy, dx; coord y, x; char s[5+1]; //put area char geta[1]; //get area hwin *hwp int box; // true if boxed int nodel; protected: int underflow(); int overflow(int c=EOF); public: void move(coord, coord); void draw(); void undraw(); void setsize(delta d_dy, delta d_dx){ dy = d_dy; dx = d_dx; } void setcoord(coord c_y, coord c_x){ y = c_y; x = c_x; } void setbox() { box = 1; } void setnodelay(int i) { nodel = (i!=0); } win(); ~win(); }; #endif /* WINH */ win.C: #include "win.h" int win::underflow() { // flush output if (pptr() && pptr() > pbase()) { overflow(EOF);} // reset get area setg(geta, geta, geta+1); if (!hwp) { setg(0,0,0); return EOF;} int c; c = hwp->cwgetch(nodel); if (c == EOF){ setg(0,0,0); return EOF; } geta[0] = c; return zapeof(c); } void win::move(coord y, coord x) { if(!hwp) return; overflow(EOF); hwp->cmove(y,x) ; } win::win() : streambuf(s, sizeof(s)-2) { setp(base(), ebuf()-2); setg(0,0,0); dy = dx = 0; y = x = 0; hwp = 0; box=0; nodel = 0; } win::~win() { if (hwp) undraw(); } void win::draw() { if (!hwp){ hwp = new hwin(dy, dx, y, x, box); } } void win::undraw() { if (hwp) { overflow(EOF); delete hwp; hwp = 0; } } int win::overflow(int c) { if(hwp) { if(c == EOF){ *(pptr()) = 0; } else { *(pptr()) = c; *(pptr()+1) = 0; } hwp->caddstr(s); } setp(base(), ebuf()-2); return zapeof(c); } Thanks Leo Willems Internet: leo@atcmp.nl AT Computing UUCP: mcsun!hp4nl!kunivv1!atcmpe!leo P. O. Box 1428 6501 BK Nijmegen Phone: +31-80-566880 The Netherlands Fax: +31-80-555887