void Segment::sourceIs(Fwk::Ptr<Location> _source) { if(source_ == _source) return; if(_source && _source->entityType() == Entity::truckTerminal() && this->entityType() != Entity::truckSegment()) return; if(_source && _source->entityType() == Entity::planeTerminal() && this->entityType() != Entity::planeSegment()) return; if(_source && _source->entityType() == Entity::boatTerminal() && this->entityType() != Entity::boatSegment()) return; if(source_) { //remove from Location array source_->segment_.deleteMember(this); } if(_source) { // add to end of Location array _source->segment_.newMember(this); } source_ = _source; }
void Segment::returnSegmentIs(Fwk::Ptr<Segment> seg) { //Only change if different... also this //protects us from infinite recursion if(returnSegment_ != seg) { //Resetting Return Segment if(seg == NULL) { Fwk::Ptr<Segment> temp = returnSegment_; returnSegment_ = NULL; temp->returnSegmentIs(NULL); // also need to clear this segment from location source_->segmentDel(this->name()); } else { if(seg->mode() == mode_) { returnSegment_ = seg; seg->returnSegmentIs(this); } else { throw IncompatibleModeException("Return Segment must be of the same Mode"); } } } }
void PlaneSegment::sourceIs( Fwk::Ptr<Location> _source ) { if (_source == NULL) { if (source_ != NULL) source_->segmentDel( this ); source_ = NULL; } else if( _source != NULL && _source->type() != Location::truck() && _source->type() != Location::boat() ) { if (source_ != NULL) source_->segmentDel( this ); source_ = _source; source_->segmentIs( this ); } else { throw LocationTypeException("Plane segment " + name() + " can't be connected to a truck or boat terminal."); } return; }
void Segment::checkSourceCompat(Fwk::Ptr<Location> source) { if((source->type() == TRUCK_TERMINAL) || (source->type() == BOAT_TERMINAL) || (source->type() == PLANE_TERMINAL)) { if(this->mode() == TRUCK && source->type() != TRUCK_TERMINAL) { throw IncompatibleModeException("Truck Segment and Non-Truck Terminal"); } else if(this->mode() == BOAT && source->type() != BOAT_TERMINAL) { throw IncompatibleModeException("Boat Segment and Non-Boat Terminal"); } else if(this->mode() == PLANE && source->type() != PLANE_TERMINAL) { throw IncompatibleModeException("Plane Segment and Non-Plane Terminal"); } } }
void Stats::onLocationNew(Fwk::Ptr<Location> location) { switch (location->type()) { case Location::customer: ++numCustomerLocations_; break; case Location::port: ++numPorts_; break; case Location::truckTerminal: ++numTruckTerminals_; break; case Location::boatTerminal: ++numBoatTerminals_; break; case Location::planeTerminal: ++numPlaneTerminals_; break; default: break; } }
void Segment::sourceIs(Fwk::Ptr<Location> source) { if(source!=NULL) { //Check Source compatibility First checkSourceCompat(source); //Detaching old Source if(source_ != NULL) { source_->segmentDel(this->name()); } //Attaching new Source source->segmentAdd(this->name()); source_ = source; } else { //Detaching a source if(source_!=NULL) { source_->segmentDel(this->name()); source_ = NULL; } } }