Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6078 in orxonox.OLD for trunk/src/lib/coord/p_node.cc


Ignore:
Timestamp:
Dec 13, 2005, 2:55:08 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: PNode compiles again
PNode is now handled with the erase function of stl, rather than remove (which is totally the wrong way when iterating through a list and delete elements)

File:
1 edited

Legend:

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

    r6075 r6078  
    2121#include "class_list.h"
    2222
     23#include <algorithm>
    2324#include "compiler.h"
    2425#include "debug.h"
     
    3233/**
    3334 * @brief standard constructor
    34  */
    35 PNode::PNode (PNode* parent)
    36 {
    37   init();
    38   if (parent != NULL)
    39     parent->addChild(this);
    40 }
    41 
    42 /**
    43  * @brief initializes a PNode
    44  * @param parent the parent for this PNode
    45  */
    46 void PNode::init()
     35 * @param parent the Parent of this Node. __NULL__ if __No Parent__ requested, PNode::getNullParent(), if connected to NullParent directly (default)
     36 * @param nodeFlags all flags to set. THIS_WILL_OVERWRITE Default_Values. look at creation of NullParent for more Info.
     37 */
     38PNode::PNode (PNode* parent, long nodeFlags)
    4739{
    4840  this->setClassID(CL_PARENT_NODE, "PNode");
     
    5143  this->bRelDirChanged = true;
    5244  this->parent = NULL;
    53   this->parentMode = PNODE_PARENT_MODE_DEFAULT;
     45  this->parentMode = nodeFlags;
    5446  this->bActive = true;
    5547
     
    5850  this->toDirection = NULL;
    5951  this->bias = 1.0;
     52
     53  if (parent != NULL)
     54    parent->addChild(this);
    6055}
    6156
     
    8782      deleteNode = tmp;
    8883      ++tmp;
    89       printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
     84//      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
    9085      if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) ||
    9186          ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))
    9287      {
    93         if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT)
     88        if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL)
    9489          delete (*deleteNode);
    9590        else
     
    10297  if (this->parent != NULL)
    10398   {
    104      this->parent->children.remove(this);
     99     this->parent->eraseChild(this);
    105100     this->parent = NULL;
    106101   }
     
    462457{
    463458  if( likely(child->parent != NULL))
    464       child->parent->children.remove(child);
     459      child->parent->eraseChild(child);
    465460  if (this->checkIntegrity(child))
    466461  {
     
    510505void PNode::reparent()
    511506{
    512   if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT)
    513     this->setParent(PNode::getNullParent());
     507  if (this->parentMode & PNODE_REPARENT_TO_NULL)
     508    this->setParent((PNode*)NULL);
    514509  else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
    515510    this->setParent(this->parent->getParent());
     511  else
     512    this->setParent(PNode::getNullParent());
     513}
     514
     515void PNode::eraseChild(PNode* child)
     516{
     517  std::list<PNode*>::iterator childRemover = std::find(this->children.begin(), this->children.end(), child);
     518  if(childRemover != this->children.end())
     519    this->children.erase(childRemover);
    516520}
    517521
     
    524528void PNode::removeNode()
    525529{
    526   if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE)
    527   {
    528     list<PNode*>::iterator child = this->children.begin();
    529     list<PNode*>::iterator reparenter;
    530     while (child != this->children.end())
    531     {
    532       reparenter = child;
    533       child++;
     530  list<PNode*>::iterator child = this->children.begin();
     531  list<PNode*>::iterator reparenter;
     532  while (child != this->children.end())
     533  {
     534    reparenter = child;
     535    child++;
     536    if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE ||
     537        (*reparenter)->parentMode & PNODE_REPARENT_ON_PARENTS_REMOVE)
     538    {      printf("TEST----------------%s ---- %s\n", this->getClassName(), (*reparenter)->getClassName());
    534539      (*reparenter)->reparent();
     540      printf("REPARENTED TO: %s::%s\n",(*reparenter)->getParent()->getClassName(),(*reparenter)->getParent()->getName());
    535541    }
    536542  }
    537543  if (this->parent != NULL)
    538     this->parent->children.remove(this);
     544    this->parent->eraseChild(this);
    539545}
    540546
     
    630636 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
    631637 */
    632 void PNode::addNodeModeFlags(unsigned short nodeFlags)
     638void PNode::addNodeFlags(unsigned short nodeFlags)
    633639{
    634640  this->parentMode |= nodeFlags;
     
    640646 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
    641647 */
    642 void PNode::removeNodeModeFlags(unsigned short nodeFlags)
     648void PNode::removeNodeFlags(unsigned short nodeFlags)
    643649{
    644650  this->parentMode &= !nodeFlags;
     651}
     652
     653/**
     654 * @returns the NullParent (and if needed creates it)
     655 */
     656PNode* PNode::createNullParent()
     657{
     658  if (likely(PNode::nullParent == NULL))
     659  {
     660    PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL);
     661    PNode::nullParent->setName("NullParent");
     662  }
     663  return PNode::nullParent;
    645664}
    646665
Note: See TracChangeset for help on using the changeset viewer.