Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 4, 2005, 2:29:11 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented a better backloop-check in the track-system
also implemented a new function in tList: inList() that returns tru, if a certain element is already in the List and false otherwise

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/track/track_manager.cc

    r4502 r4508  
    149149
    150150/**
    151    \brief checks if there are any BackLoops in the Track (Backloops only
    152    \param trackElem the trackElement to check about
    153    \param depth the depth to search in
     151   \brief checks if there are any BackLoops in the Track
    154152   \returns true if NO loop was found, false Otherwise
    155153   You actually have to act on false!!
    156    it simply does this by looking if the current trackElem is found again somewhere else in the Track
    157 
    158    \todo this has to be reimplemented
    159 */
    160 bool TrackElement::backLoopCheck(const TrackElement* trackElem, unsigned int depth) const
    161 {
    162   if(depth == 0 || this != trackElem)
    163     {
    164       if (this->children)
    165         {
    166           tIterator<TrackElement>* iterator = this->children->getIterator();
    167           TrackElement* enumElem = iterator->nextElement();
    168           while (enumElem)
    169             {
    170               if(!enumElem->backLoopCheck(trackElem, depth + 1))
    171                 return false;
    172               enumElem = iterator->nextElement();
    173             }
    174           delete iterator;
    175         }
    176     }
    177   else
    178     return false;
    179 
     154*/
     155bool TrackElement::backLoopCheck(void) const
     156{
     157  tList<const TrackElement>* trackList = new tList<const TrackElement>;
     158 
     159  this->backLoopCheckAtomic(trackList);
     160 
     161  delete trackList;
    180162  // only returns if everything worked out
    181163  return true;
    182164}
     165
     166/**
     167   \brief checks if there are any BackLoops in the Track.
     168   \param trackList A list of stored tracks, to search in.
     169   \returns true if NO loop was found, false Otherwise
     170   You actually have to act on false!!
     171*/
     172bool TrackElement::backLoopCheckAtomic(tList<const TrackElement>* trackList) const
     173{
     174  if (trackList->inList(this))
     175    return false;
     176
     177  trackList->add(this);
     178
     179  if (this->children)
     180    {
     181      tIterator<TrackElement>* iterator = this->children->getIterator();
     182      TrackElement* enumElem = iterator->nextElement();
     183      while (enumElem)
     184        {
     185          if (!enumElem->backLoopCheckAtomic(trackList))
     186            return false;
     187        }
     188      delete iterator;
     189    }
     190  return true;
     191}
     192
    183193
    184194/**
     
    264274    PRINT(0)("   is Joined at the End\n");
    265275 
    266   if(!this->backLoopCheck(this)) /* this should not happen */
     276  if(!this->backLoopCheck()) /* this should not happen */
    267277    PRINT(2)(" THERE IS A BACKLOOP TO THIS ELEMENT\n");
    268278}
     
    916926  // checking if there is a back-loop-connection and ERROR if it is.
    917927  tmpTrackElem = this->firstTrackElem->findByID(trackIDs[0]);
    918   if (!tmpTrackElem->backLoopCheck(tmpTrackElem))
     928  if (!tmpTrackElem->backLoopCheck())
    919929    {
    920930      PRINTF(2)("Backloop connection detected at joining trackElements\n -> TRACK WILL NOT BE JOINED\n");
Note: See TracChangeset for help on using the changeset viewer.