#ifndef MESHPATCHPTR_H
#define MESHPATCHPTR_H

#include <print.h>

/*!
\brief Functional object to return control points, but can
 point to different mesh patches.

The index interprets the line of control points as a 2D 
 matrix.

Initialize in construction phase.  Use indexSet(...) to point
 to different mesh patches.

There is no error checking, for example on index bounds.
*/
template< typename T >
class meshpatchptr
{
public:

  /** Global points. */
  T * pt;

  /** By changing the index different patches are 
      represented. */
  uint * index;

  /** The number of columns - N+1 in the patch. */
  uintc columns;

  /** Point to a patch. */
  void indexSet(uint * pi)
    { for (uint k=0; k<columns; ++k) index[k] = pi[k]; }

  /** Read the value of the point. */
  T const operator () (uintc i, uintc j) const
    { return pt[ index[i+columns*j] ]; }
  /** Write to the point. */
  T & operator () (uintc i, uintc j) 
    { return pt[ index[i+columns*j] ]; }

  /** Pass in the global points pointer and the number of 
      columns. */
  meshpatchptr( T * pt_, uintc columns_)
    : pt(pt_), index(new uint[columns_]), columns(columns_) {}

  /** Memory cleanup. */
  ~meshpatchptr()
    { delete[] index; }

};

#endif



