Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::addTimeConstraint ( TimeConstraint ctr  ) 

Adds a new time constraint (already allocated). Returns true on success, false for already existing constraints.

Definition at line 2168 of file rules.cpp.

References internalStructureComputed, timeConstraintsList, and TimeConstraint::type.

Referenced by addSimpleActivity(), addSplitActivity(), and read().

{
      bool ok=true;

      //TODO: improve this

      //check if this constraint is already added, for ConstraintActivityPreferredTime
      if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_TIME){
            TimeConstraint *ctr2;
            for(ctr2=this->timeConstraintsList.first(); ctr2; ctr2=this->timeConstraintsList.next())
                  if(
                   (ctr2->type==CONSTRAINT_ACTIVITY_PREFERRED_TIME) &&
                   (((ConstraintActivityPreferredTime*)ctr2)->activityId
                   ==
                   ((ConstraintActivityPreferredTime*)ctr)->activityId)
                  )
                        break;

            if(ctr2)
                  ok=false;
      }

      //check if this constraint is already added, for ConstraintMinNDaysBetweenActivities
      if(ctr->type==CONSTRAINT_MIN_N_DAYS_BETWEEN_ACTIVITIES){
            TimeConstraint *ctr2;
            for(ctr2=this->timeConstraintsList.first(); ctr2; ctr2=this->timeConstraintsList.next())
                  if(ctr2->type==CONSTRAINT_MIN_N_DAYS_BETWEEN_ACTIVITIES)
                        if(
                         *((ConstraintMinNDaysBetweenActivities*)ctr2)
                         ==
                         *((ConstraintMinNDaysBetweenActivities*)ctr)
                         )
                              break;

            if(ctr2)
                  ok=false;
      }

      if(ok){
            this->timeConstraintsList.append(ctr);
            this->internalStructureComputed=false;
            return true;
      }
      else
            return false;
}


Generated by  Doxygen 1.6.0   Back to index