unsigned int DeltaDrawablePrivate::GetChildIndex(const DeltaDrawable* child) const { for (unsigned int childNum = 0; childNum < mChildList.size(); ++childNum) { if (mChildList[childNum] == child) { return childNum; } } return mChildList.size(); // node not found. }
virtual ~SContainer() { for(unsigned i = 0; i<children.size(); ++i) { delete children[i]; } }
void DeltaDrawablePrivate::RemoveChild(DeltaDrawable* child) { if (!child) return; unsigned int pos = GetChildIndex(child); if (pos < mChildList.size()) { child->SetParent(NULL); child->AddedToScene(NULL); mChildList.erase(mChildList.begin() + pos); } }
//----------------------------------------------------------------------------// void GridLayoutContainer::setGridDimensions(size_t width, size_t height) { // copy the old children list ChildList oldChildren = d_children; // remove all child windows while (getChildCount() != 0) { Window* wnd = static_cast<Window*>(d_children[0]); removeChild(wnd); } // we simply fill the grid with dummies to ensure everything works smoothly // when something is added to the grid, it simply replaces the dummy for (size_t i = 0; i < width * height; ++i) { Window* dummy = createDummy(); addChild(dummy); } const size_t oldWidth = d_gridWidth; const size_t oldHeight = d_gridHeight; const AutoPositioning oldAO = d_autoPositioning; d_gridWidth = width; d_gridHeight = height; // now we have to map oldChildren to new children for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { // we have to skip if we are out of the old grid if (x >= oldWidth || y >= oldHeight) continue; const size_t oldIdx = mapFromGridToIdx(x, y, oldWidth, oldHeight); Window* previous = static_cast<Window*>(oldChildren[oldIdx]); if (isDummy(previous)) { WindowManager::getSingleton().destroyWindow(previous); } else { addChildToPosition(previous, x, y); } oldChildren[oldIdx] = 0; } } setAutoPositioning(oldAO); // oldAOIdx could mean something completely different now! // todo: perhaps convert oldAOOdx to new AOIdx? setNextAutoPositioningIdx(0); // we have to destroy windows that don't fit the new grid if they are set // to be destroyed by parent for (size_t i = 0; i < oldChildren.size(); ++i) { if (oldChildren[i] && static_cast<Window*>(oldChildren[i])->isDestroyedByParent()) { WindowManager::getSingleton().destroyWindow(static_cast<Window*>(oldChildren[i])); } } }
/////////////////// // Post-conditions (memory management): // Every node listed in bterms is either affixed to this node or deleted. // // Distributes a conjunction of clauses. // int SymNode::distribute(){ if(t != SAND){ cerr << "distribute called on a non \"and\" node"<<endl; assert(t != SAND); } debout("d1"); //Ensure that there are no ANDs as children removeParens(); debout("d1.1"); CLIter current; ChildList * bterms = new ChildList(); current = children.begin(); // Separate the complex terms from the BTerms; // children will contain only complex terms (i.e. ORs) while( current != children.end() ){ if((*current)->t == BTERM){ bterms->push_back(*current); current = children.erase(current); }else{ current++; } } debout("d2"); // Continue to call distr(Node,Node) until all of my children are // distributed. Recall that children contain ONLY complex nodes. while(children.size() > 1 ){ debout( "d3.1"); SymNode *result = distr( *(children.begin()), *(++children.begin()) ); // BK 8/21/2009 cull to save run-time if (result->t != SAND){ for(CLIter rc = result->children.begin(); rc != result->children.end(); ){ if( (*rc)->cullNode2() ){ rc++; }else{ rc = result->children.erase(rc); } } } // END BK 8/21/2009 children.pop_front(); children.pop_front(); debout("d3.2\nresult tree"); deb(result->printTree(0)); debout("d3.2.1"); //MARK added this assert(result!=0); if(result->t == SAND){ // Result is an AND node, so add its children to the bterms list debout("result->t == SAND)"); bterms->splice(bterms->begin(),result->children); noDuplicateNodes(*bterms); delete result; debout("leave result->t == SAND"); debout("bterms size: "); deboutnn(bterms->size()); }else if( result->t == SOR ){ // Result being an OR, means we added to the children list noDuplicateNodes(result->children); addChild(result); }else if(result->t == BTERM){ bterms->push_back(result); }else if(result->t == FTYPE){ delete result; }else{ cerr << "a returned result was not an \"and\" or an \"or\" or a BTERM" <<endl; assert(0); } } debout("d4"); if( children.size() == 0 && bterms->size() == 1 ){ cerr << "not possible yet.1" <<endl; assert(0); this->t = BTERM; this->bt = (*(bterms->begin()))->bt; delete bterms; // BK fixed unreachable leak return 1; }else if( children.size() == 0 && bterms->size() > 1){ //I stay an AND, but if we culled the ORs then I should be culled as well //That scenario isn't implemented yet children.swap(*bterms); delete bterms; return 1; }else if( children.size() == 0 && bterms->size() == 0){ cerr << "not possible yet." <<endl; assert(0); } // Distribute the leaf bterms into the remaining complex term. debout("d5"); if( children.size() == 1 ){ this->t = SOR; this->bt = -1; SymNode *result = *(children.begin()); children.pop_front(); while (bterms->begin() != bterms->end()){ SymNode* cur = *(bterms->begin()); bterms->pop_front(); result = distr(result, cur); // BK 8/21/2009 cull to save run-time for(CLIter rc = result->children.begin(); rc != result->children.end(); ){ if((*rc)->cullNode2() ){ rc++; }else{ rc = result->children.erase(rc); } } noDuplicateNodes(result->children); // END BK 8/21/2009 debout("distr returned a:"); deb(result->printTree(0)); } // copy the children of the resulting OR into the current children list this->addChildren( result ); delete result; delete bterms; // BK fixed leak (8/7/2007) return 1; }else{ cerr << "there should at least be one child and no bterms or no children and more than 1 bterm" <<endl; assert(0); } // BK: check the size of the bterms array pointer assert (bterms->size() == 0); delete bterms; // BK fixed leak (8/7/2007) return 1; }
unsigned int DeltaDrawablePrivate::GetNumChildren() const { return mChildList.size(); }
virtual bool HasChildren() const { return children.size() != 0; }