// file: circular_buffer/cb_opt_0.cc
//

// isip include files
//
#include "CircularBuffer.h"

// method: operator
//
// arguments:
//
//  int dim: (input) indicated dimension
//  int index: (input) indicated index
//
// return: float_8 the value of corresponding element
//
// this method overloads () operator.
//
float_8 Circular_buffer::operator() (int dim, int index) {

  // note that the index is actually an offset from idx_d
  //
  int idx = idx_d[dim] + index;

  // check the index
  //
  if (idx >= size_d)
    {idx -= size_d;}
  else if (idx < (int)0)
    {idx += size_d;}

  // return the corresponding value
  //
  return buf_d[dim][idx];
}
