#include "AtomicSequentialTransition.hpp"

AtomicSequentialTransition::AtomicSequentialTransition() {
  iType = ATOMIC_SEQUENTIAL_TRANSITION;
  bStarted = false;
}

AtomicSequentialTransition::~AtomicSequentialTransition() {
  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 AtomicSequentialTransition::Update() {
  if ((vChildren.size() > 0) && (vChildren.at(0)->Complete())) {
    delete *vChildren.begin();
    vChildren.erase(vChildren.begin());
  }

  if (vChildren.size() > 0) {
    vChildren.at(0)->Update();
  }
}

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

  return true;
}