ArrayElement* ToDo::clone() {
    ToDo* ret = new ToDo();
    if (getClass()) ret->setClass(*classEvent);
    if (getCompleted()) ret->setCompleted(*completed);
    if (getCreated()) ret->setCreated(*created);
    if (getDescription()) ret->setDescription(*description);
    if (getDtStamp()) ret->setDtStamp(*dtStamp);
    if (getDtStart()) ret->setDtStart(*dtStart);
    if (getGeo()) ret->setGeo(*geo);
    if (getLastMod()) ret->setLastMod(*lastMod);
    if (getLocation()) ret->setLocation(*location);
    if (getOrganizer()) ret->setOrganizer(*organizer);
    if (getPercent()) ret->setPercent(*percent);
    if (getPriority()) ret->setPriority(*priority);
    if (getRecurID()) ret->setRecurID(*recurID);
    if (getSequence()) ret->setSequence(*seq);
    if (getStatus()) ret->setStatus(*status);
    if (getSummary()) ret->setSummary(*summary);
    if (getUid()) ret->setUid(*uid);
    if (getUrl()) ret->setUrl(*url);
    if (getDue()) ret->setDue(*due);
    if (getDuration()) ret->setDuration(*duration);
    if (getAttach()) ret->setAttach(*attach);
    if (getAttendee()) ret->setAttendee(*attendee);
    if (getCategories()) ret->setCategories(*categories);
    if (getComment()) ret->setComment(*comment);
    if (getContact()) ret->setContact(*contact);
    if (getExDate()) ret->setExDate(*exDate);
    if (getExRule()) ret->setExRule(*exRule);
    if (getRStatus()) ret->setRStatus(*rStatus);
    if (getRelated()) ret->setRelated(*related);
    if (getResources()) ret->setResources(*resources);
    if (getRDate()) ret->setRDate(*rDate);
    if (getRRule()) ret->setRRule(*rRule);
    if (getXProp()) ret->setXProp(*xProp);

    return ret;
}
Exemple #2
0
DECLARE_EXPORT void Demand::updateProblems()
{
  // The relation between the demand and the related problem classes is such
  // that the demand object is the only active one. The problem objects are
  // fully controlled and managed by the associated demand object.

  // A flag for each problem type that may need to be created
  bool needsNotPlanned(false);
  bool needsEarly(false);
  bool needsLate(false);
  bool needsShort(false);
  bool needsExcess(false);

  // Problem detection disabled on this demand
  if (!getDetectProblems()) return;

  // Check which problems need to be created
  if (deli.empty())
  {
    // Check if a new ProblemDemandNotPlanned needs to be created
    if (getQuantity()>0.0) needsNotPlanned = true;
  }
  else
  {
    // Loop through the deliveries
    for (OperationPlanList::iterator i = deli.begin(); i!=deli.end(); ++i)
    {
      // Check for ProblemLate problem
      long d(getDue() - (*i)->getDates().getEnd());
      if (d < 0L) needsLate = true;
      // Check for ProblemEarly problem
      else if (d > 0L) needsEarly = true;
    }

    // Check for ProblemShort problem
    double plannedqty = getPlannedQuantity();
    if (plannedqty + ROUNDING_ERROR < qty) needsShort = true;

    // Check for ProblemExcess Problem
    if (plannedqty - ROUNDING_ERROR > qty) needsExcess = true;
  }

  // Loop through the existing problems
  for (Problem::iterator j = Problem::begin(this, false);
      j!=Problem::end(); )
  {
    // Need to increment now and define a pointer to the problem, since the
    // problem can be deleted soon (which invalidates the iterator).
    Problem& curprob = *j;
    ++j;
    // The if-statement keeps the problem detection code concise and
    // concentrated. However, a drawback of this design is that a new Problem
    // subclass will also require a new Demand subclass. I think such a link
    // is acceptable.
    if (typeid(curprob) == typeid(ProblemEarly))
    {
      // if: problem needed and it exists already
      if (needsEarly) needsEarly = false;
      // else: problem not needed but it exists already
      else delete &curprob;
    }
    else if (typeid(curprob) == typeid(ProblemDemandNotPlanned))
    {
      if (needsNotPlanned) needsNotPlanned = false;
      else delete &curprob;
    }
    else if (typeid(curprob) == typeid(ProblemLate))
    {
      if (needsLate) needsLate = false;
      else delete &curprob;
    }
    else if (typeid(curprob) == typeid(ProblemShort))
    {
      if (needsShort) needsShort = false;
      else delete &curprob;
    }
    else if (typeid(curprob) == typeid(ProblemExcess))
    {
      if (needsExcess) needsExcess = false;
      else delete &curprob;
    }
    // Note that there may be other demand exceptions that are not caught in
    // this loop. These are problems defined and managed by subclasses.
  }

  // Create the problems that are required but aren't existing yet.
  if (needsNotPlanned) new ProblemDemandNotPlanned(this);
  if (needsLate) new ProblemLate(this);
  if (needsEarly) new ProblemEarly(this);
  if (needsShort) new ProblemShort(this);
  if (needsExcess) new ProblemExcess(this);
}