// file: cb.h
//
// this file defines a circular buffer class
//

// make sure definitions are only made once
//
#ifndef __CB
#define __CB

// isip include files
//
#ifndef __ISIP_INTEGRAL
#include <integral.h>
#endif

class Circular_buffer {

  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // data information
  //
  int* idx_d;
  int* num_d;
  int size_d;
  int dim_d;
  float_8** buf_d;

  //---------------------------------------------------------------------------
  //
  // public methods
  //
  //---------------------------------------------------------------------------
public:

  // constructors/destructors
  //
  Circular_buffer();
  Circular_buffer(int dim, int num_elements);
  ~Circular_buffer();

  // debug
  //
  void debug();
  
  // allocation
  //
  void allocate_cc(int dim, int num_elements);

  // indexing methods
  //
  int add_cc(int dim, float_8 new_value);

  void write_cc(int dim, int index, float_8 value);
  
  void sub_cc(int dim) {
    if (--num_d[dim] < 0)
      num_d[dim] = 0;
  }

  void empty_cc();

  // overloaded operators
  //
  float_8 operator() (int dim, int index);

  // get mothods
  //
  int get_size_cc(int dim) {
    return num_d[dim];
  }

  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

  // none
};

//
// end of include file
#endif
