// file: circular_buffer/cb_add_cc.cc
//

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

// method: add
//
// arguments: 
//
//  int dim: (input) dimensions of circular buffer
//  float_8 new_value: (input) new value that will be added in
//
// return: int indicating the current pointer
//
// this method adds new value to the back circular buffer.
//
int Circular_buffer::add_cc(int dim, float_8 new_value) {

  // increment the pointer
  //
  idx_d[dim]++;
  if (++num_d[dim] > size_d) {
    num_d[dim] = size_d;
  }
  int idx = idx_d[dim];

  if (idx >= size_d)
    {idx -= size_d;}
  else if (idx < (int)0)
    {idx += size_d;}
    
  // assign the value
  //
  buf_d[dim][idx] = new_value;
  idx_d[dim] = idx;
  
  // return the new pointer
  //
  return idx;
}
