/**************************************************************************
 * Course Project Header File: PointPair.h                                *
 *                                                                        *
 * Description: This class defines a pair of 2-D points                   *
 *                                                                        *
 **************************************************************************/
#ifndef _POINT_PAIR_H
#define _POINT_PAIR_H

#include <stdio.h>
#include <stdlib.h>

#include "Point.h"

class PointPair
{
public:
  /**
   * Default Constructor.
   *     To construct a point pair that has one point at (0, 0)
   *     and the other at (1, 1).
   */
  PointPair (void);

  /**
   * Constructor.
   *     To construct a point pair containing points p1 and p2.
   *
   * parameter p1: the first point of the pair.
   * parameter p2: the second point of the pair.
   */
  PointPair (const Point& p1, const Point& p2);

  /**
   * Copy constructor.
   *     To construct a point pair that is the same as a given pair.
   *
   * parameter pair: a point pair.
   */
  PointPair (const PointPair& pair);

  /**
   * Assignment operator.
   *     Make an existing point pair be the same as a given pair.
   *
   * parameter pair: a point pair.
   * return: an assigned point pair.
   */
  PointPair& operator = (const PointPair& pair);

  /**
   * Change the two points of this point pair to two given points.
   *
   * parameter p0: the first point.
   * parameter p1: the second point.
   */
  void setPoints (const Point& p0, const Point& p1);

  /**
   * Calculate the distance between two points of this pair.
   *
   * return: distance between points of this pair.
   */
  double distance (void) const;  

  /**
   * Comparison operator.
   *     Check whether pair0 and pair1 are the same.
   *
   * return: 1 if pair0 and pair1 are the same.
   *         0 if pair0 and pair1 are not the same.
   */
  friend int operator == (const PointPair& pair0, const PointPair& pair1);

  /**
   * Comparison operator.
   *     Check whether pair0 and pair1 are different.
   *
   * return: 1 if pair0 and pair1 are different.
   *         0 if pair0 and pair1 are the same.
   */
  friend int operator != (const PointPair& pair0, const PointPair& pair1);

  /**
   * Overloaded output stream operator.
   *     This operator enables the following statements:
   *     PointPair p;
   *     cout << p;
   *
   *     The format of an output stream is:
   *     (32 43) (32 565)
   */
  friend ostream& operator << (ostream& os, const PointPair& pair)
    {
      return os << "(" << pair.p0_ <<")  (" << pair.p1_ << ")";
    }


  /**
   * Overloaded input stream operator.
   *     This operator enables the following statements:
   *     PointPair p;
   *     cin >> p;
   *
   *     The format of an input stream is:
   *     (32 43) (43 54)
   */
  friend istream& operator >> (istream& is, PointPair& pair)
    {
      char c;
  
      is >> c;
      if (c == '(') {
	is >> pair.p0_ >> c;
	if (c == ')') {
	  is >> c;
	  if (c == '(') {
	    is >> pair.p1_ >> c;
	    if (c != ')')
	      is.clear (ios::badbit);
	  }
	  else
	    is.clear (ios::badbit);
	}
	else
	  is.clear (ios::badbit);
      }
      else
	is.clear (ios::badbit);
  
      return is;
    }
private:
  // two points of this pair
  Point p0_;
  Point p1_;
};
#endif
