www.pudn.com > aec.rar > cb.h


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

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

class Circular_buffer {

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

  // data information
  //
  int idx_d;
  int size_d;
  double *buf_d;

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

  // constructors/destructors
  //
  Circular_buffer();
  ~Circular_buffer();

  // allocation
  //
  void allocate_cc(int num_elements);

  // indexing methods
  //
  int add_cc(double new_value);

  // overloaded operators
  //
  double operator() (int index);

  operator float() {return (float)buf_d[idx_d];}

  double & operator= ( double value)  
  {
    add_cc(value);
    return buf_d[idx_d];
  }

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

  // none
};

//
// end of include file
#endif