#include "ParallelTransition.hpp"

ParallelTransition::ParallelTransition() {
  iType = PARALLEL_TRANSITION;
  bStarted = false;
}

ParallelTransition::~ParallelTransition() {
  while (vChildren.size() > 0) {
    std::vector<Transition*>::iterator it = vChildren.begin();

    if (it != vChildren.end()) {
      delete *it;
      vChildren.erase(it);
    }
  }

  while (vToBeDeleted.size() > 0) {
    std::vector<AlterableObject*>::iterator it = vToBeDeleted.begin();

    if (it != vToBeDeleted.end()) {
      delete *it;
      vToBeDeleted.erase(it);
    }
  }
}

void ParallelTransition::Update() {
  for (unsigned int i = 0; i < vChildren.size(); i++) {
    if (vChildren.at(i)->Complete()) {
      delete *(vChildren.begin() + i);
      vChildren.erase(vChildren.begin() + i);
    }
    else {
      vChildren.at(i)->Update();
    }
  }
}

bool ParallelTransition::Complete() {
  for (unsigned int i = 0; i < vChildren.size(); i++) {
    if (!vChildren.at(i)->Complete()) {
      return false;
    }
  }

  return true;
}