Example #1
0
/**
 * This function redirects messages arriving at zombie elements onto
 * the hub. 
 * e is the zombie element whose messages are being redirected to the hub.
 * eFinfo is the Finfo holding those messages.
 * hubFinfo is the Finfo on the hub which will now handle the messages.
 * eIndex is the index to look up the element.
 */
void HSolveHub::redirectDestMessages(
	Eref hub,
	Eref e,
	const Finfo* hubFinfo,
	const Finfo* eFinfo,
	unsigned int eIndex,
	vector< unsigned int >& map, 
	vector< Element * >* elist,
	vector< Element * >* include,
	bool retain )
{
	Conn* i = e.e->targets( eFinfo->msg(), e.i );
	vector< Eref > srcElements;
	vector< int > srcMsg;
	vector< const ConnTainer* > dropList;

	while( i->good() ) {
		Element* tgt = i->target().e;
		
		// Handle messages going outside purview of solver.
		bool inElist = find( elist->begin(), elist->end(), tgt ) != elist->end();
		bool inInclude =
			include == 0 ||
			find( include->begin(), include->end(), tgt ) != include->end();
		
		if ( ! inElist && inInclude ) {
			map.push_back( eIndex );
			srcElements.push_back( i->target() );
			srcMsg.push_back( i->targetMsg() );
			if ( !retain )
				dropList.push_back( i->connTainer() );
		}
		i->increment();
	}
	delete i;

	e.dropVec( eFinfo->msg(), dropList );

	for ( unsigned int j = 0; j != srcElements.size(); j++ ) {
		bool ret = srcElements[j].add( srcMsg[j], hub, hubFinfo->msg(),
			ConnTainer::Default );
		assert( ret );
	}
}