/*
 * class ReferenceVector
 *
 * $Date$
 * $Revision$
 *
 */

#ifndef REFERENCE_VECTOR_HH__
#define REFERENCE_VECTOR_HH__

#include "WImage/miscdefs.h"

/**
 * @addtogroup WImage
 * @{ */

/**
 * Pseudo-vector (abstract). Provide a two-dimensional array's
 * rows and columns as vectors with array addressing.
 */
/*abstract*/
class
ReferenceVector
{
public:

  /** Constructor. Simple initialization. */
  ReferenceVector (void) {
    m_vroot = 0;
  }
  /** Destructor. Does nothing. */
  virtual ~ReferenceVector (void) {};

  /** Returns the root. */
  inline int root (void) { return m_vroot; }

  /** Checks integrity. If the array's dimensions have been changed
   * (resize operation) {\em false} will be returned. */
  virtual bool sanity (void) = 0;
  /** Updates the vector's settings. This is necessary each time after
   * the array has been resized. */
  virtual void update (void) = 0;

  /** Set new root. Depending of what concrete instance is the current
   * row or col will be set.
   * @exception invalid_argument
   * a negative value was given for the new root
   * @param root
   * the new root */
  virtual void go (int root) = 0;

  /** Return a value (abstract). The value is taken from the vector's
   * position {\em pos}.
   * @param pos
   * the position
   * @return
   * the value at that position */
  virtual coeff at (int pos) = 0;

  /** Assign a value (abstract). A new value {\em val} is assigned to
   * the vector's position {\em pos}.
   * @param pos
   * the position
   * @param val
   * the new value */
  virtual void to (int pos, coeff val) = 0;
  /** Return the vector's size (abstract). Depending on the concrete
   * instance we will get the associated array's number of rows or cols.
   * @return
   * the vector's size */
  virtual int size (void) = 0;

  /** Copy another vector's content. If the vectors have different sizes
   * only as much as possible is being copied.
   * @param other
   * the other vector */
  inline void copy (ReferenceVector &other)
  {
    for (int i = 0; i < this->size () && i < other.size (); i++)
      {
        this->to (i, other.at (i));
      }
  }

#ifdef USE_DEPRECATED_API
  /** Copy another vector's content. If the vectors have different sizes
   * only as much as possible is being copied.
   * @param other
   * the other vector */
  inline void copy (ReferenceVector *other) { copy (*other); }
#endif
protected:
  /** The vector's root. Depending on whether we're a row or column vector
   * (inherited classes) this is either the vector's row or col. */
  int m_vroot;
}; /* class ReferenceVector */

/** @} */

#endif /* REFERENCE_VECTOR_HH__ */

