/*
  full-storage.icc -- implement Full_storage inline functions

  source file of the Flower Library

  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/


#ifndef FULL_STORAGE_ICC
#define FULL_STORAGE_ICC


INLINE void
Full_storage::init()
{
  els_p_p_=0;
  band_i_ = 0;    
  height_i_=width_i_=max_height_i_=max_width_i_=0;
}

INLINE bool
Full_storage::valid (int i, int j) const
{
  return (i>=0 && i < height_i_)
    && (j < width_i_ && j >=0);
}


INLINE
Full_storage::Full_storage (Full_storage const&s)
{
  init();
  (*this) = s;
}

INLINE Real& 
Full_storage::elem (int i,int j)
{
  assert (valid (i,j));
  return els_p_p_[i][j];
}

INLINE Real
Full_storage::elem (int i, int j) const {
  assert (valid (i,j));
  return els_p_p_[i][j];
}

INLINE
Full_storage::Full_storage() {
  init();
}


INLINE int
Full_storage::rows() const
{
  return height_i_;
}

INLINE int
Full_storage::cols() const
{
  return width_i_;
}

INLINE int
Full_storage::dim() const
{
  assert (rows()==cols ());
  return rows();
}

INLINE void
Full_storage::resize (int i)
{
  resize (i,i);
}

INLINE   
Full_storage::Full_storage (int i,int j)
{
  init();
  set_size (i,j);
}

INLINE 
Full_storage::Full_storage (int i)
{
  init();
  set_size (i);
}


INLINE
bool
Full_storage::mult_ok (int i, int ) const
{
  return i < height_i_;
}

INLINE
bool
Full_storage::trans_ok (int , int j) const
{
  return j < width_i_;
} 


INLINE
void
Full_storage::trans_next (int &i, int &j) const
{
  assert (trans_ok (i,j));
  i++;
  if (i >= height_i_) 
    {
      i= (0 >? j - band_i_);
      j ++;
    }
}

INLINE
void
Full_storage::mult_next (int &i, int &j) const
{
  assert (mult_ok (i,j));
  j++;
  if (j >= width_i_) 
    {
      j= 0 >? (i - band_i_);
      i++;
    }
}
#endif // FULL_STORAGE_ICC
