// Buffer.
// Fixed size buffer of integers, held in FIFO order.

#ifndef BUFFER_H
#define BUFFER_H

class buffer {

public:      ///// Public interface:

  buffer(unsigned capacity=100);// Construct buffer with capacity, default 100.
  void add(int);                // Add new item at end of queue.
  int peek();                   // Get but don't remove next item from buffer.
  int remove();                 // Get and remove next item from buffer.
  unsigned size();              // Count the number of items in the buffer.

private:     ///// Private implementation details.

  int * buf;                    // Storage for the data.
  int last;                     // Index of last location in buffer.
  int head;                     // Index of item at head of queue.
  int tail;                     // Index of 1st free location at end of queue.

  bool isempty();               // Check if there is anything in the buffer.
  bool isfull();                // Check if there is any room left.
  void increment(int);          // Increment an index in the buffer,
                                // taking care to "wrap around" the end.
};

#endif
