/*****************************************************************************
Copyright 1998 MBARI                                                      
******************************************************************************
Summary  : I/O Buffer class
Filename : Buffer.h
Author   : Michael B. Matthews                                                
Project  : iView                                                       
Version  : 1.0                                                          
Created  : 9.2.97                                                      
Modified : 25.3.98                                                             
Archived :                                                              
Notes    : 
****************************************************************************/

#ifndef Buffer_h
#define Buffer_h



/******************************************************************************
Class   : I / O  B U F F E R                                              
Purpose : Provides I/O buffering functions for floating point numbers 
Notes   : 
******************************************************************************/

class IO_Buffer 
{
public:
  Int32 count;
  Int index;
  Int size;
  Flt32 average;
  Flt32 averageSquared;
  Flt32* u;

  IO_Buffer(Int n, Flt32 v = 0);
  ~IO_Buffer() { delete[] u; }

  Void Fill(Flt32 value);
  Void Init() { Fill(0); }
  Void Update(Flt32 x);
  Flt32 Average(Int n = 0);
  Flt32 Variance(Int n = 0);
  Flt32 Max_Difference();
  Flt32 Max();
  Flt32 Min();
  inline Void Clear() { index = -1; count = 0; average = averageSquared = 0; }
  inline Flt32 Output() { return u[index]; }
  inline Int Index() { return index; }
  inline Int Size() { return size; }
  inline Int32 Count() { return count; }
  inline Flt32 operator[](Int i) { return u[i % size]; }
};


#endif

