Window* Window::child(const char *name)
{
	for (ChildList::const_iterator i = mChildren.begin(); i != mChildren.end(); ++i)
		if (strcmp((*i)->name(), name) == 0)
			return *i;
	return 0;
}
	virtual bool AddChildren(OWNERSHIP SContainer<T>* child)
	{
		if (std::find(children.begin(), children.end(), child)
				!= children.end())
		{
			return false;
		}
		children.push_back(child);
		return true;
	}
   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);
      }
   }
   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.
   }
Exemple #5
0
TreeLeaf::ChildList TreeLeaf::getChildList ()
{
    ChildList childs;
    //
    for (int i = 0; i < this->childCount(); i++)
    {
        TreeLeaf* ptr_actual = (TreeLeaf*) this->child(i);
        Q_ASSERT ( ptr_actual );
        //
        childs.push_back(ptr_actual);
    };
    //
    return childs;
}
	virtual ~SContainer()
	{
		for(unsigned i = 0; i<children.size(); ++i)
		{
			delete children[i];
		}
	}
Exemple #7
0
// called by aipOverlayGroup command to get overlay image key(s) for gf. 
list<string> ImgOverlay::getOverlayImages(spGframe_t gf, RQgroup *group) {
   list<string> keys;
 
   ChildList *il = group->getChildren();
   list<RQnode>::iterator iitr;
   for (iitr=il->begin(); iitr != il->end(); ++iitr) {
      string key = iitr->getKey();
      spDataInfo_t od = DataManager::get()->getDataInfoByKey(key,true);
      if(od == (spDataInfo_t)NULL) continue;

      // getCoPlane return a valid key if od image co-plane with base image.
      key = getCoPlane(gf, od);
      if(key.length()>0) keys.push_back(key);
   }
   return keys;
}
Exemple #8
0
void SceneNode::flatten()
{
  ChildList children;

  for(auto child : m_children)
  {
    child->set_transform(m_trans * child->m_trans);
    child->flatten();
    
    for(auto gchild : child->m_children)
    {
      children.push_back(gchild);
    }

    child->m_children.clear();
    children.push_back(child);
  }

  m_children.swap(children);
}
Exemple #9
0
void ChildListType::deserialize(ChildList& list, const ArchiveNode& node, IUniverse& universe) const {
	if (node.is_array()) {
		for (size_t i = 0; i < node.array_size(); ++i) {
			const ArchiveNode& child = node[i];
			ObjectPtr<> ptr = deserialize_object(child, universe);
			if (ptr != nullptr) {
				list.push_back(std::move(ptr));
			}
		}
	}
}
Exemple #10
0
   void DeltaDrawablePrivate::RemovedFromScene(Scene* scene, osg::Node* node)
   {
      // for now don't include this check, since we're calling
      //   DeltaDrawablePrivate::AddedToScene() first
      //if (mParentScene != scene) { return; } // we're not even in this scene; nothing to do here.

      mParentScene = NULL;

      for (ChildList::iterator itr = mChildList.begin();
         itr != mChildList.end();
         ++itr)
      {
         (*itr)->RemovedFromScene(scene);
      }

      // we've just been removed from a scene
      // if we're inactive, we should remove our Switch
      if (GetActive() == false)
      {
         RemoveSwitchNode(node);
      }
   }
Exemple #11
0
   void DeltaDrawablePrivate::AddedToScene(Scene* scene, osg::Node* node)
   {
      if (mParentScene == scene) { return; } // nothing to do here.

      mParentScene = scene;

      for (ChildList::iterator itr = mChildList.begin();
         itr != mChildList.end();
         ++itr)
      {
         (*itr)->AddedToScene(scene);
      }

      // If we've been set to inactive before being added to a Scene,
      // then we need to do add in our Switch node.
      if (mParentScene != NULL)
      {
         if (GetActive() == false)
         {
            InsertSwitchNode(node);
         }
      }
   }
	virtual bool RemoveChildren(SContainer<T>* child)
	{
		if (std::find(children.begin(), children.end(), child)
				!= children.end())
		{
			children.erase(std::find(children.begin(), children.end(), child));
			return true;
		}
		return false;
	}
Exemple #13
0
   bool DeltaDrawablePrivate::AddChild(DeltaDrawable* child, DeltaDrawable* parent)
   {
      if (!CanBeChild(child))
      {
         Log::GetInstance().LogMessage(Log::LOG_WARNING, __FILE__,
            "DeltaDrawable: '%s' cannot be added as a child to '%s'",
            child->GetName().c_str(), parent->GetName().c_str());
         return false;
      }

      child->SetParent(parent);
      mChildList.push_back(child);

      if (mParentScene)
      {
         child->AddedToScene(mParentScene);
      }

      return true;
   }
std::tuple<ChildList,ChildList, ChildList> AttendanceSheets::assignToRooms(std::vector<Child> childrenInNursery, int month, int year) {
    ChildList poosRoos;
    ChildList piglets;
    ChildList tiggers;

    for (auto child: childrenInNursery) {
        // Get middle of month
        int daysInMonth = TimeUtils::daysInMonth(month, year);
        system_clock::time_point middleOfMonth = TimeUtils::dateToTimePoint(daysInMonth/2, month, year);

        int ageOnDate = getAgeOnDate(child.dob, middleOfMonth);
        if (ageOnDate < 2) poosRoos.push_back(child);
        else if (ageOnDate < 3) piglets.push_back(child);
        else tiggers.push_back(child);

    }

    auto listsByRooms = std::make_tuple (poosRoos, piglets, tiggers);
    return listsByRooms;
}
//----------------------------------------------------------------------------//
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]));
        }
    }
}
	virtual void SortChildren() { std::sort(children.begin(), children.end());}
Exemple #17
0
bool Importer::traverse(NodeHandler *handler, void *n, void *c, Core::BaseObject *target) {
	xmlNodePtr node = reinterpret_cast<xmlNodePtr>(n);
	xmlNodePtr childs = reinterpret_cast<xmlNodePtr>(c);
	ChildList remaining;
	TagSet mandatory;

	handler->init(target, n, mandatory);

	bool result = true;

	for ( xmlNodePtr child = childs; child != NULL; child = child->next ) {
		if ( child->type != XML_ELEMENT_NODE ) continue;

		handler->propagate(NULL, false, true);

		try {
			handler->get(target, child);
		}
		catch ( std::exception &e ) {
			if ( handler->isOptional )
				SEISCOMP_WARNING("(optional) %s.%s: %s", node->name, child->name, e.what());
			else
				throw e;
		}

		if ( !handler->isOptional )
			mandatory.erase((const char*)child->name);

		if ( handler->object == NULL && handler->isAnyType ) {
			if ( _any.get(target, child) ) {
				handler->object = _any.object;
				handler->childHandler = _any.childHandler;
				handler->newInstance = _any.newInstance;
			}
		}

		Core::BaseObject *newTarget = handler->object;
		MemberNodeHandler *memberHandler = handler->memberHandler;
		NodeHandler *childHandler = handler->childHandler;
		bool newInstance = handler->newInstance;
		bool optional = handler->isOptional;

		if ( newTarget ) {
			if ( childHandler == NULL ) {
				childHandler = _typemap->getHandler(newTarget->className());
				if ( childHandler == NULL ) {
					SEISCOMP_WARNING("No class handler for %s", newTarget->className());
					if ( newInstance )
						delete newTarget;
					handler->object = NULL;
					newTarget = NULL;
					childHandler = &_none;
				}
			}
		}
		else
			childHandler = &_none;

		try {
			if ( traverse(childHandler, child, child->children, handler->object) ) {
				if ( newTarget && newInstance && !memberHandler )
					remaining.push_back(newTarget);

			}
			else {
				if ( newTarget && newInstance )
					delete newTarget;
				newTarget = NULL;
				if ( optional )
					SEISCOMP_INFO("Invalid %s element: ignoring", child->name);
				else {
					SEISCOMP_WARNING("%s is not optional within %s", child->name, node->name);
					result = false;
				}
			}
		}
		catch ( std::exception &e ) {
			SEISCOMP_WARNING("%s: %s", child->name, e.what());
			if ( newTarget ) {
				if ( newInstance )
					delete newTarget;

				if ( !optional ) {
					SEISCOMP_WARNING("%s is not optional within %s", child->name, node->name);
					result = false;
				}
				else
					SEISCOMP_WARNING("%s: ignoring optional member %s: invalid", node->name, child->name);

				newTarget = NULL;
			}
		}

		if ( memberHandler ) {
			if ( !memberHandler->finalize(target, newTarget) ) {
				if ( newTarget && newInstance )
					remaining.push_back(newTarget);
			}
		}
	}

	handler->finalize(target, &remaining);

	if ( target != NULL ) {
		for ( ChildList::iterator it = remaining.begin(); it != remaining.end(); ++it )
			if ( *it != NULL ) delete *it;
	}
	else {
		for ( ChildList::iterator it = remaining.begin(); it != remaining.end(); ++it ) {
			if ( *it != NULL ) {
				if ( _result == NULL )
					_result = *it;
				else
					delete *it;
			}
		}
	}

	if ( !mandatory.empty() ) {
		std::string attribs;
		for ( TagSet::iterator it = mandatory.begin(); it != mandatory.end(); ++it ) {
			if ( it != mandatory.begin() ) attribs += ", ";
			attribs += *it;
		}
		SEISCOMP_WARNING("%s: missing mandatory attribute%s: %s", node->name, mandatory.size() == 1?"":"s", attribs.c_str());
		return false;
	}

	return result;
}
Exemple #18
0
///////////////////
// 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;
}
Exemple #19
0
///////////////////////
// Post-condition (memory management):
//   Always return a pointer to this node.
//
SymNode* SymNode::toDNF(){
  debout("toDNF");
  CLIter iter,end,dup;
  if( t == BTERM || t == FTYPE || t == ETYPE || t == TTYPE){
    debout("p:isLiteral");
    return this;
  }
  //Ensure all of the clauses are in DNF
  iter = children.begin();
  end = children.end();

  ChildList *newList = new ChildList();
  while( iter != end ){
    debout("loop:p1");
    SymNode *returned;
    returned = (*iter)->toDNF();
    if( returned != NULL ){
      newList->push_back(*iter);
    }
    iter++;
  }
  debout("p2");
  this->children.swap( *newList );
  newList->clear();
  delete newList;

  deboutnn( "toDNF: children.size(): ");
  debout(children.size() );

  //All chilren are false if they have been pruned by DNF  
  if( children.empty() ){
    debout("p:shouldn\'t be happening");
    assert(0);
    this->destroyTree();
    return new SymNode(FTYPE,-1);
  }
  debout("p3");
  if( t == SOR ){
    debout("p3.1");
    
    //Then we are fine because all of the clauses are in DNF
    this->removeParens();
    //noDuplicateNodes(this->children);
    return this;
  } else if( t == SAND ){
    debout("p4");
    //We need to distribute "and" over the clauses that are in DNF already
    //It's exponential time!!!!!!!!!
    //TEMP MARK

    // BK: this never happens, because distribute has not line: return 0;
    if( this->distribute() ==  0 ){ 
      assert(0); //Shouldn't be happening
      debout("p6 this->distribute() == 0");
      //The children are false according to our restrictions and so this is false and therefor useless
      this->destroyTree();  // BK fixed possible leak
      delete this;
      return new SymNode(FTYPE,-1);
    }
    debout("p5");
    //noDuplicateNodes(this->children);
    return this;
  }else{
    //raise exception "not" is not implemented
    assert(0);
  }
  return NULL;
}
Exemple #20
0
// Compares all pairs of children, finding and removing duplicate BTERMs
void noDuplicateNodes( ChildList &l )
{
  //This is shallow!
  //ONLY SAFE WHEN DELETING BTERMS for now (note is prev to Aug 2009)

  // BK Aug 21, 2009: seems to be deep compare and deep delete
  ChildList dups;
  CLIter n1 = l.begin();
  CLIter n2 = ++(l.begin());
  CLIter end = l.end();
  while( n1 != end ){
    //assert((*n1)->t == BTERM);
    while( n2 != end ){
      //Comparison
      if( (*n1)->equals(*n2) ){
	dups.push_back(*n2);
      }
      n2++;
    }
    n1++;
    n2 = n1;
    n2++;
  }

  dups.sort();
  dups.unique();
  
  for(n2 = dups.begin(); n2 != dups.end(); n2++){
    for(n1 = l.begin(); n1 != l.end(); n1++){
      if(*n1 == *n2){
	(*n1)->destroyTree();
	l.erase(n1);
	break;
      }
    }
  }
  dups.clear();
}
Exemple #21
0
 unsigned int DeltaDrawablePrivate::GetNumChildren() const
 {
    return mChildList.size();
 }
Exemple #22
0
void Window::rebuildChildrenList()
{
	mChildren.clear();
	EnumChildWindows(mHWND, sCollectChildrenCallback, reinterpret_cast<LPARAM>(this));
}
	virtual bool HasChildren() const
	{
		return children.size() != 0;
	}