#ifndef SIMPLEXD1INDEXED_H
#define SIMPLEXD1INDEXED_H

#include <typedefs.h>

/*!
\brief Indexed line.

The indexes refer to points.
 These may or may not be ordered depending on the
 application.
*/
template< typename INDX=uint >
class simplexD1indexed
{
public:

  /** Indexes to points or vertexes. */
  INDX pi[2];

  /** Construct a null line. */
  simplexD1indexed()
    { pi[0] = pi[1] = 0; }
  /** Construct a line. */
  simplexD1indexed(INDX const a, INDX const b )
    { pi[0]=a; pi[1]=b; }

  /** Are two lines the same? */
  boolc operator == (simplexD1indexed<INDX> const & t) const;

  /** Set all fields to 0. */
  void setnull()
    { pi[0] = pi[1] = 0; }
  /** Is this a line? Are all the fields set to zero? */
  boolc isnull() const;

  /** Global << calls this. */
  ostream & print(ostream & os) const
    { return os << pi[0] << " " << pi[1]; }

  /** Serialize this object. */
  operator stringc () const;

};

template< typename INDX >
ostream & operator << ( ostream & os, simplexD1indexed<INDX> const & s)
  { return s.print(os); }


//---------------------------------------------------------
// Implementation

template< typename INDX >
simplexD1indexed<INDX>::operator stringc () const
{
  stringstream ss;
  ss << pi[0] << " " << pi[1];
  return ss.str();
}

template< typename INDX >
boolc simplexD1indexed<INDX>::operator == 
(
  simplexD1indexed<INDX> const & t
) const
{
  if (pi[0]==t.pi[0])
  {
    if (pi[1]==t.pi[1])
      return true;
  }

  if (pi[0]==t.pi[1])
  {
    if (pi[1]==t.pi[0])
      return true;
  }

  return false;
}

template< typename INDX >
boolc simplexD1indexed<INDX>::isnull() const
{
  if (pi[0]!=0)
    return false;

  if (pi[1]!=0)
    return false;

  return true;
}



#endif



