Example #1
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Manifest ResourceBuff::popQty(double qty) {
  if (qty - quantity() > STORE_EPS) {
    throw CycNegQtyException("Removal quantity larger than store tot quantity.");
  }
  if (qty < 0.0) {
    throw CycNegQtyException("Removal quantity cannot be negative.");
  }

  Manifest manifest;
  rsrc_ptr mat, leftover;
  double left = qty;
  double quan;
  while (left > STORE_EPS) {
    mat = mats_.front();
    mats_.pop_front();
    quan = mat->quantity();
    if ((quan - left) > STORE_EPS) {
      // too big - split the mat before pushing
      leftover = mat->clone();
      leftover->setQuantity(quan - left);
      mat->setQuantity(left);
      mats_.push_front(leftover);
    }
    manifest.push_back(mat);
    left -= quan;
  }
  return manifest;
}
Example #2
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Manifest ResourceBuff::popNum(int num) {
  if (mats_.size() < num) {
    throw CycNegQtyException("Remove count larger than store count.");
  }

  Manifest manifest;
  for (int i = 0; i < num; i++) {
    manifest.push_back(mats_.front());
    mats_.pop_front();
  }
  return manifest;
}