#include "Faces.H"

Faces::~Faces(void)
{
   int i;

   for (i=0; i<num_faces; i++) {
      free(((struct Faces *) faces[i])->face);
      faces.Delete(i);
   }
}

Faces& Faces::Faces(const Faces& that, int inc)
:faces(sizeof(struct Face),inc)
{
   num_faces = 0;

   *this = that;

   return(*this);
}

Faces& operator=(const Faces& that)
{
   int i;

   for (i=0; i<num_faces; i++) {
      free(((struct Faces *) faces[i])->face);
      faces.Delete(i);
   }
   // XXX  Is there a way to just do all the deletes at once?

   for (i=0; i<that.num_faces; i++)
      faces.AddFace(that.faces[i]);

   num_faces = that.num_faces;

   return(*this);
}

void AddFace(const struct Face *newface)
{
   struct Face copy;

   copy.face_length = newface->face_length;
   copy.face = (int *) malloc(sizeof(int) * newface->face_length);
   bcopy(newface->face, copy.face, sizeof(int) * newface->face_length);

   faces += (char *) &copy;
}

void AddFace(int face_length, const int *face)
{
   struct Face copy;

   copy.face_length = face_length;
   copy.face = (int *) malloc(sizeof(int) * face_length);
   bcopy(face, copy.face, sizeof(int) * newface->face_length);

   faces += (char *) &copy;
}

