Exemplo n.º 1
0
	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;
	}
Exemplo n.º 2
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;
	}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
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();
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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);
      }
   }
Exemplo n.º 7
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);
         }
      }
   }
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
	virtual void SortChildren() { std::sort(children.begin(), children.end());}