/////// FIle Cirbuf.C /////// #include #include "Cirbuf.h" Cirbuf::Cirbuf(int s /* = D_SIZE */) { head = tail = length = 0; size = s; cb = new char[s]; // allocate buffer space } Cirbuf::~Cirbuf() { delete [] cb; // free up space } int Cirbuf::produce(char c) { if ( is_full() ) { cerr << "produce: buffer full\n"; return(-1); } cb[tail++] = c; length++; tail = mod(tail); return(0); } int Cirbuf::consume() { char c; if ( is_empty() ) { cerr << "consume: buffer empty\n"; return(-1); } c = cb[head++]; length--; head = mod(head); return(c); }