Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5296 in orxonox.OLD for trunk/src/lib/coord


Ignore:
Timestamp:
Oct 7, 2005, 10:42:22 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: modiefied PNode to match Element2D's removal methods.
see destructor header for more detail

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/coord/p_node.cc

    r5255 r5296  
    7474
    7575/**
    76  *  standard deconstructor
    77 */
     76 * standard deconstructor
     77 *
     78 * There are two general ways to delete a PNode
     79 * 1. delete instance;
     80 *   -> result
     81 *    delete this Node and all its children and children's children...
     82 *    (danger if you still need the children's instance somewhere else!!)
     83 *
     84 * 2. instance->remove2D(); delete instance;
     85 *   -> result:
     86 *    moves its children to the NullParent
     87 *    then deletes the Element.
     88 */
    7889PNode::~PNode ()
    7990{
    80   if (this->parent)
    81     this->parent->removeChild(this);
    82   else
    83   {
    84    tIterator<PNode>* iterator = this->children->getIterator();
    85    PNode* pn = iterator->firstElement();
    86    while( pn != NULL)
    87      {
    88        delete pn;
    89        pn = iterator->nextElement();
    90      }
    91    delete iterator;
    92    /* this deletes all children in the list */
     91  // remove the Node, delete it's children.
     92  tIterator<PNode>* iterator = this->children->getIterator();
     93  PNode* child = iterator->firstElement();
     94
     95  while( child != NULL)
     96  {
     97    delete child;
     98    child = iterator->nextElement();
     99  }
     100  delete iterator;
     101
     102  if (this->parent != NULL)
     103  {
     104    this->parent->children->remove(this);
     105    this->parent = NULL;
    93106  }
    94107  delete this->children;
     108
     109  // remove all other allocated memory.
    95110  if (this->toCoordinate != NULL)
    96111    delete this->toCoordinate;
     
    98113    delete this->toDirection;
    99114}
     115
    100116
    101117/**
Note: See TracChangeset for help on using the changeset viewer.