Esempio n. 1
0
void WikiAreaPages::createAreaPages_getExternalConnections( MindArea *area , MindLocalCircuitDef& circuit , MapStringToClass<MindLocalCircuitConnectionDef>& connections , bool isin ) {
	ClassList<MindLocalCircuitConnectionDef> links;
	circuit.getExternalConnections( links , isin );

	MindService *ms = MindService::getService();
	for( int k = 0; k < links.count(); k++ ) {
		MindLocalCircuitConnectionDef *c = links.get( k );

		// ignore secondary
		if( !c -> isPrimary() )
			continue;

		String key;
		if( isin == false ) {
			MindRegion *region = ms -> getMindRegion( c -> getDstRegion() );
			key = region -> getArea() -> getAreaId() + "#" + c -> getSrcRegion() + "#" + c -> getDstRegion() + "#1";
			if( connections.get( key ) == NULL )
				connections.add( key , c );
		}
		else {
			MindRegion *region = ms -> getMindRegion( c -> getSrcRegion() );
			key = region -> getArea() -> getAreaId() + "#" + c -> getDstRegion() + "#" + c -> getSrcRegion() + "#2";
			if( connections.get( key ) == NULL )
				connections.add( key , c );
		}
	}
}
Esempio n. 2
0
File: key.cpp Progetto: nszhsl/pylon
        void Down( unsigned char key, int x, int y )
        {
            if( Renderer::Key::keys[ key ] == true )
            {
                return;
            }
            last = key;
            float presstime = (float)POGEL::GetTimePassed();
            Renderer::Key::lastpressed[ key ] = presstime;
            Renderer::Key::keys[ key ] = true;
            Renderer::Key::mousepospress[ key ][ 0 ] = x;
            Renderer::Key::mousepospress[ key ][ 1 ] = y;

            cout << "Key '" << key  << "' pressed at position (" << x << "," << y << ") at time " << Renderer::Key::lastpressed[ key ] << endl;

            unsigned int numcallbacks = keyDownCallBacks.length();
            for( unsigned int i = 0; i < numcallbacks; ++i )
            {
                if( !keyDownCallBacks[ i ] )
                {
                    continue;
                }
                if( keyDownCallBacks[ i ]->remove )
                {
                    KeyCallback * func = keyDownCallBacks[ i ];
                    keyDownCallBacks.replace( i, NULL );
                    delete func;
                    continue;
                }
                if( keyDownCallBacks[ i ]->hasKeyFiltered( key ) )
                {
                    keyDownCallBacks[ i ]->operator()( key, x, y, Renderer::Key::lastpressed[ key ] );
                }
            }
        }
void NerveTool::addSingleChain( StringList& fibersinfo , String type , ClassList<StringList>& chain , int from , int to ) {
	StringList mids;
	for( int k = from + 1; k < to; k++ )
		mids.add( chain.getRef( k ).get( 0 ) );

	addFiberItem( fibersinfo , type , chain.getRef( from ).get( 0 ) , chain.getRef( to ).get( 0 ) , mids );
}
void NerveTool::output_nerve( FILE *sout , ClassList<Nerve>& nn , int k ) {
	Nerve& n = nn.getRef( k );

	bool hasChilds = false;
	int upLevelCount = 0;
	if( nn.count() > ( k + 1 ) ) {
		Nerve& nx = nn.getRef( k + 1 );
		if( nx.level > n.level )
			hasChilds = true;
		else
			upLevelCount = n.level - nx.level;
	}
	else
		upLevelCount = n.level;

	String tabs = String( "\t" ).replicate( 2 + n.level );
	String s = tabs + "<element name=\"" + n.name + "\"";
	if( !n.synonyms.isEmpty() )
		s += "\n" + tabs + "\tsynonyms=\"" + n.synonyms + "\"";
	if( !n.origin.isEmpty() )
		s += "\n" + tabs + "\torigin=\"" + n.origin + "\"";
	if( !n.distribution.isEmpty() )
		s += "\n" + tabs + "\tdistribution=\"" + n.distribution + "\"";
	if( !n.imginfo.isEmpty() )
		s += "\n" + tabs + "\t" + n.imginfo;
	if( !n.modality.isEmpty() )
		s += "\n" + tabs + "\tmodality=\"" + n.modality + "\"";

	if( n.fibers.isEmpty() ) {
		if( hasChilds )
			s +="\n" + tabs + "\t>\n";
		else
			s +="\n" + tabs + "\t/>\n";
	}
	else {
		s += "\n" + tabs + "\t>";

		String fibersinfo;
		for( int z = 0; z < n.fibersinfo.count(); z++ )
			fibersinfo += tabs + "\t" + n.fibersinfo.get( z ) + "\n";

		s += "\n" + fibersinfo;
		if( !hasChilds )
			s += tabs + "</element>\n";
	}

	for( int z = 1; z <= upLevelCount; z++ ) {
		tabs = String( "\t" ).replicate( 2 + n.level - z );
		s += tabs + "</element>\n";
	}

	if( ( n.level == 0 && hasChilds == false ) || ( n.level > 0 && ( n.level - upLevelCount ) == 0 ) )
		s += "\n";

	fprintf( sout , "%s" , ( const char * )s );
}
Esempio n. 5
0
static void typedefMap( QMap<QString, QString> & map, ClassDom klass )
{
	const TypeAliasList aliasList = klass->typeAliasList();
	for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
		map[ ( *it )->name() ] = ( *it )->type();
	
	const ClassList classList = klass->classList();
	for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
		typedefMap( map, *it );
}
Esempio n. 6
0
void HierarchyTest::testClasses()
{
  ClassList classes;
  classes << new Class("Aligator", project);
  classes << new Class("Beaver", project);
  classes << new Class("Crocodile", project);

  QCOMPARE(project->findMembers<Class*>().size(), 3);
  QCOMPARE(project->findMembers<Class*>().toSet(), classes.toSet());
}
String WikiNerveSpecPages::getNerveDivision_fibers( ClassList<XmlNerveFiberInfo>& fibers ) {
	String s;
	for( int k = 0; k < fibers.count(); k++ ) {
		XmlNerveFiberInfo& fiber = fibers.getRef( k );
		if( k > 0 )
			s += "; ";
		s += fiber.type + ":" + getNerveDivision_fiberchain( fiber );
	}
	return( s );
}
ThreadPoolFixedTaskListItem::ThreadPoolFixedTaskListItem( String p_name , int p_threadPoolItem , ClassList<ThreadPoolTask>& p_tasks )
:	ThreadPoolItem( p_name , p_threadPoolItem ) {
	currentTask = 0;

	// assign task list
	for( int k = 0; k < p_tasks.count(); k++ ) {
		ThreadPoolTask *task = p_tasks.get( k );
		task -> thread = this;
		tasks.add( task );
	}
}
Esempio n. 9
0
void ClassLattice::deleteLattice( void )
//--------------------------------------
{
    ClassList * list;

    list = _flatClasses;

    for( int i = list->count(); i > 0; i -= 1 ) {
        delete (*list)[ i - 1 ];
    }
    delete list;
}
Esempio n. 10
0
static void typeNameList( QStringList & path, QStringList & lst, ClassDom klass )
{
	path.push_back( klass->name() );
	
	lst << path.join( "::" );
	
	const ClassList classList = klass->classList();
	for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
		typeNameList( path, lst, *it );
	
	path.pop_back();
}
// create derivaton perceptron
NN *NNRegressionFactory::createDerivationPerceptron( NNVariables *vars , NN *p , NNSamples *pSamples , int sensorFrom , int sensorTo , float ( *targetFunction )( NN *p ) )
{
	int nDerivationSensors = sensorTo - sensorFrom + 1;
	ASSERT( nDerivationSensors > 0 );

	// create perceptron - sensors are the same, targets are required derivatives of target function by given sensor
	int nSrcSensors = p -> getNSensors();
	int nSrcTargets = p -> getNTargets();
	int nDstTargets = nDerivationSensors;
	int hiddenLayerSize = ( nDstTargets + nSrcSensors ) / 2;

	// variables
	// sensors are the same
	ClassList<NNVariable> sensors;
	for( int k = 0; k < p -> getNSensors(); k++ )
		sensors.add( p -> getSensorVariable( k ) );

	// targets are derivatives - owned by NN variables
	ClassList<NNVariable> targets;
	for( int k1 = sensorFrom; k1 <= sensorTo; k1++ )
		for( int k = 0; k < p -> getNSensors(); k++ )
			targets.add( vars -> addCommonNumberDerivative() );

	NN *pd = createDefaultPerceptron( String( p -> getId() ) + "#D" , sensors , targets , hiddenLayerSize );

	// create main strategy
	String instance;
	const char *pInstance = p -> getInstance();
	if( pInstance != NULL && *pInstance != 0 )
		instance = String( pInstance ) + "::derivative";
	NNStrategyBackPropagation *psBPd = createDefaultStrategy( instance , pd );

	// populate derivation samples - in the same points as training set
	NNSamples pdSamples( nSrcSensors , nDstTargets );
	for( int m = 0; m < pSamples -> count(); m++ )
		{
			NNSample *sample = pSamples -> getByPos( m );
			NNSample *sampleD = pdSamples.add();
			sampleD -> setSensors( sample -> getSensors() );

			getDerivatives( p , sensorFrom , sensorTo , sample , sampleD -> getTargets() , targetFunction );
		}

	// learn derivative perceptron
	bool res = psBPd -> learn( &pdSamples , NULL , NULL );
	ASSERT( res );

	return( pd );
}
Esempio n. 12
0
void WikiAreaPages::createAreaPages_getInternalConnections( MindArea *area , MindLocalCircuitDef& circuit , MapStringToClass<MindLocalCircuitConnectionDef>& connections ) {
	ClassList<MindLocalCircuitConnectionDef> links;
	circuit.getInternalConnections( links );

	for( int k = 0; k < links.count(); k++ ) {
		MindLocalCircuitConnectionDef *c = links.get( k );

		// ignore secondary
		if( !c -> isPrimary() )
			continue;

		String key = c -> getSrcRegion() + "#" + c -> getDstRegion();
		if( connections.get( key ) == NULL )
			connections.add( key , c );
	}
}
Esempio n. 13
0
static void typeNameList( QStringList& path, QStringList & lst, NamespaceDom ns )
{
	if( !ns->isFile() )
		path.push_back( ns->name() );
	
	const NamespaceList namespaceList = ns->namespaceList();
	for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
		typeNameList( path, lst, *it );
	
	const ClassList classList = ns->classList();
	for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
		typeNameList( path, lst, *it );
	
	if( !ns->isFile() )
		path.pop_back();
}
void ThreadPool::create( ClassList<ThreadPoolTask>& tasks ) {
	if( !runEnabled ) {
		logger.logInfo( "ignore threadPool=" + name + ", runEnabled=false" );
		return;
	}

	int nTasks = tasks.count();
	if( nThreads > nTasks )
		nThreads = nTasks;

	ASSERTMSG( nThreads >= 1 , "nThreads is invalid" );

	int nWhole = nTasks / nThreads;
	int nPart = nTasks % nThreads;

	// split objects by threads
	int nFrom = 0;
	for( int k = 0; k < nThreads; k++ ) {
		// calculate number of objects for thread
		int n = nWhole;
		if( nPart ) {
			n++;
			nPart--;
		}

		// create list of thread tasks
		ClassList<ThreadPoolTask> threadTasks;
		threadTasks.allocate( n );
		for( int j = 0; j < n; j++ ) {
			ThreadPoolTask *task = tasks.get( nFrom + j );
			task -> pool = this;
			threadTasks.add( task );
		}

		// create thread (suspended) and add to the pool
		String threadName = name + "#" + k;
		ThreadPoolItem *thread = new ThreadPoolFixedTaskListItem( threadName , k , threadTasks );
		threads.add( thread );

		// configure thread
		nFrom += n;
	}

	logger.logInfo( String( "threadpool created: name=" ) + name + ", nThreads=" + nThreads + ", nTasks=" + nTasks );
}
Esempio n. 15
0
 __Module* __GetModule( const std::string& name )
 {
     for( unsigned int i = 0; i < moduleList.length(); ++i )
     {
         if( moduleList[ i ]->operator==( name ) )
             return moduleList[ i ];
     }
     return NULL;
 }
Esempio n. 16
0
int findClass( ClassList& list, ClassLattice * node )
//---------------------------------------------------
{
    for( int i = list.count(); i > 0; i -= 1 ) {
        if( list[ i - 1 ] && list[ i - 1 ]->isEqual( node ) ) {
            return i - 1;
        }
    }
    return -1;
}
Esempio n. 17
0
void NNSamples::deserialize( Object *parent , SerializeObject& so )
{
	clear();

	nSizeIn = so.getPropInt( "nSizeIn" );
	nSizeOut = so.getPropInt( "nSizeOut" );
	
	ClassList<NNSample> va;
	so.getPropObjectList( ( ClassList<Object>& )va , "sampleList" , true );

	for( int k = 0; k < va.count(); k++ )
		{
			NNSample *sample = va.get( k );
			data.add( sample -> getId() , sample );
		}

	limitType = ( LimitType )so.getPropInt( "limitType" );
	maxSize = so.getPropInt( "maxSize" );
}
Esempio n. 18
0
void
CodeVisitor::collectClassMembers(const ClassDefPtr& p, MemberInfoList& allMembers, bool inherited)
{
    ClassList bases = p->bases();
    if(!bases.empty() && !bases.front()->isInterface())
    {
        collectClassMembers(bases.front(), allMembers, true);
    }

    DataMemberList members = p->dataMembers();

    for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q)
    {
        MemberInfo m;
        m.fixedName = fixIdent((*q)->name());
        m.inherited = inherited;
        m.dataMember = *q;
        allMembers.push_back(m);
    }
}
Esempio n. 19
0
File: key.cpp Progetto: nszhsl/pylon
        void Up( unsigned char key, int x, int y )
        {
            if( Renderer::Key::keys[ key ] == false )
            {
                return;
            }
            float reltime = (float)POGEL::GetTimePassed();
            if( reltime - Renderer::Key::lastpressed[ key ] < 0.01 )
            {
                //return;
            }
            Renderer::Key::lastreleased[ key ] = reltime;
            Renderer::Key::keys[ key ] = false;
            Renderer::Key::mouseposrelease[ key ][ 0 ] = x;
            Renderer::Key::mouseposrelease[ key ][ 1 ] = y;

            cout << "Key '" << key << "' released at position (" << x << "," << y << ") at time ";
            cout << Renderer::Key::lastreleased[ key ] << ", duration of ";
            cout << ( Renderer::Key::lastreleased[ key ] - Renderer::Key::lastpressed[ key ] ) << endl;

            unsigned int numcallbacks = keyUpCallBacks.length();
            for( unsigned int i = 0; i < numcallbacks; ++i )
            {
                if( !keyUpCallBacks[ i ] )
                {
                    continue;
                }
                if( keyUpCallBacks[ i ]->remove )
                {
                    KeyCallback * func = keyUpCallBacks[ i ];
                    keyUpCallBacks.replace( i, NULL );
                    delete func;
                    continue;
                }
                if( keyUpCallBacks[ i ]->hasKeyFiltered( key ) )
                {
                    keyUpCallBacks[ i ]->operator()( key, x, y, Renderer::Key::lastreleased[ key ] );
                }
            }
        }
Esempio n. 20
0
int NerveTool::execute_img( String& s , FILE *sout , int level , ClassList<Nerve>& nn ) {
	// extract
	if( !s.startsFrom( "<img src=\"" ) )
		return( 101 );

	s.remove( 0 , strlen( "<img src=\"" ) );

	int idx = s.find( "\"" );
	if( idx < 0 )
		return( 102 );

	String s1 = s.getMid( 0 , idx );
	s.remove( 0 , idx + 1 );
	s.trim();

	s.trimTrailing( '>' );
	String height;
	if( s.startsFrom( "height=" ) )
		height = s.getMid( strlen( "height=" ) );

	// create string
	String img = "imgsrc=\"" + s1 + "\"";
	if( !height.isEmpty() )
		img += " imgheight=\"" + height + "\"";

	// find nerve to add to - upper with level - 1
	for( int k = nn.count() - 1; k >= 0; k-- ) {
		Nerve& n = nn.getRef( k );
		if( n.level < level ) {
			if( !n.imginfo.isEmpty() )
				return( false );

			n.imginfo = img;
			return( 0 );
		}
	}

	return( 100 );
}
void NNRegressionFactory::scaleBySamplesStddev( NNSamples *samples , NNVariables *vars , ClassList<NNVariable>& sensors , ClassList<NNVariable>& targets )
{
	// scale inputs
	for( int k = 0; k < samples -> sizeIn(); k++ )
		{
			float meanV , stddevV;
			samples -> getSensorStat( k , &meanV , &stddevV );

			NNVariable *var = vars -> addCommonNumber( true , meanV - stddevV , true , meanV + stddevV );
			sensors.add( var );
		}

	// scale outputs
	for( int k = 0; k < samples -> sizeOut(); k++ )
		{
			float meanV , stddevV;
			samples -> getTargetStat( k , &meanV , &stddevV );

			NNVariable *var = vars -> addCommonNumber( true , meanV - stddevV , true , meanV + stddevV );
			targets.add( var );
		}
}
Esempio n. 22
0
bool
FreezeScript::AnalyzeTransformVisitor::checkClasses(const ClassDeclPtr& from, const ClassDeclPtr& to)
{
    string fromScoped = from->scoped();
    string toScoped = to->scoped();

    if(fromScoped == toScoped)
    {
        return true;
    }

    //
    // The types don't match, so check them for compatibility. Specifically,
    // look up the old type id in the new Slice and see if it has the target
    // type as a base class.
    //
    TypeList l = to->unit()->lookupTypeNoBuiltin(from->scoped(), false);
    if(!l.empty())
    {
        ClassDeclPtr decl = ClassDeclPtr::dynamicCast(l.front());
        if(decl)
        {
            ClassDefPtr def = decl->definition();
            if(def)
            {
                ClassList bases = def->allBases();
                for(ClassList::iterator p = bases.begin(); p != bases.end(); ++p)
                {
                    if((*p)->scoped() == toScoped)
                    {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
Esempio n. 23
0
void refreshClasses(ClassViewPart *part, KComboView *view, const QString &dom)
{
    view->clear();

    view->setCurrentText(EmptyClasses);
    NamespaceDom nsdom;
    if (dom == "::")
        nsdom = part->codeModel()->globalNamespace();
    else
    {
        nsdom = namespaceByName(part->codeModel()->globalNamespace(), dom);
        if (!nsdom)
            return;
    }
    ClassList classes = nsdom->classList();
    for (ClassList::const_iterator it = classes.begin(); it != classes.end(); ++it)
    {
        ClassItem *item = new ClassItem(part, view->listView(), part->languageSupport()->formatModelItem(*it), *it);
        view->addItem(item);
        item->setOpen(true);
    }
}
	void testWorkflow( XmlCall& call ) {
		// parameters
		String threadPoolName = call.getParam( "threadPoolName" );
		int nTasks = call.getIntParam( "nTasks" );
		int taskTimeMs = call.getIntParam( "taskTimeMs" );
		int runTimeSec = call.getIntParam( "runTimeSec" );
		int suspendTimeSec = call.getIntParam( "suspendTimeSec" );
		int resumeTimeSec = call.getIntParam( "resumeTimeSec" );

		// create task list
		ClassList<ThreadPoolTask> tasks;
		for( int k = 0; k < nTasks; k++ ) {
			ThreadPoolTest_Task *task = new ThreadPoolTest_Task( String( "T" ) + k , taskTimeMs );
			tasks.add( task );
		}

		// create and configure thread pool
		logger.logInfo( "Create thread pool..." );
		ThreadService *ts = ThreadService::getService();
		ts -> createThreadPool( threadPoolName , call.getXml().getChildNode( "threadpoolconfiguration" ) , tasks );

		// workflow
		logger.logInfo( "Start thread pool..." );
		ts -> startThreadPool( threadPoolName );
		ts -> threadSleepMs( runTimeSec * 1000 );

		logger.logInfo( "Suspend thread pool..." );
		ts -> suspendThreadPool( threadPoolName );
		ts -> threadSleepMs( suspendTimeSec * 1000 );
		logger.logInfo( "Resume thread pool..." );
		ts -> resumeThreadPool( threadPoolName );
		ts -> threadSleepMs( resumeTimeSec * 1000 );
		logger.logInfo( "Stop thread pool..." );
		ts -> stopThreadPool( threadPoolName );

		// drop tasks
		tasks.destroy();
		logger.logInfo( "Finished." );
	}
void NNRegressionFactory::scaleBySamplesSimple( NNSamples *samples , NNVariables *vars , ClassList<NNVariable>& sensors , ClassList<NNVariable>& targets )
{
	// scale inputs
	for( int k = 0; k < samples -> sizeIn(); k++ )
		{
			float minV , maxV;
			samples -> getSensorRange( k , &minV , &maxV );

			ASSERT( minV < maxV );
			NNVariable *var = vars -> addCommonNumber( true , minV , true , maxV );
			sensors.add( var );
		}

	// scale outputs
	for( int k = 0; k < samples -> sizeOut(); k++ )
		{
			float minV , maxV;
			samples -> getTargetRange( k , &minV , &maxV );

			ASSERT( minV < maxV );
			NNVariable *var = vars -> addCommonNumber( true , minV , true , maxV );
			targets.add( var );
		}
}
Esempio n. 26
0
/// \brief Get all subclasses of a given class.
///
/// \p Current class, whose direct and indirect subclasses are
///    to be collected.
/// \p IndirectSubs placeholder for collected results
void ClassHierarchyAnalysis::getIndirectSubClasses(ClassDecl *Cur,
                                                   ClassList &IndirectSubs) {
  unsigned Idx = IndirectSubs.size();

  if (!hasKnownDirectSubclasses(Cur))
    return;

  // Produce a set of all indirect subclasses in a
  // breadth-first order;

  // First add subclasses of direct subclasses.
  for (auto C : getDirectSubClasses(Cur)) {
    // Get direct subclasses
    if (!hasKnownDirectSubclasses(C))
      continue;
    auto &DirectSubclasses = getDirectSubClasses(C);
    // Remember all direct subclasses of the current one.
    for (auto S : DirectSubclasses) {
      IndirectSubs.push_back(S);
    }
  }

  // Then recursively add direct subclasses of already
  // added subclasses.
  while (Idx != IndirectSubs.size()) {
    auto C = IndirectSubs[Idx++];
    // Get direct subclasses
    if (!hasKnownDirectSubclasses(C))
      continue;
    auto &DirectSubclasses = getDirectSubClasses(C);
    // Remember all direct subclasses of the current one.
    for (auto S : DirectSubclasses) {
      IndirectSubs.push_back(S);
    }
  }
}
Esempio n. 27
0
int NerveTool::execute_line( String& s , FILE *sout , ClassList<Nerve>& nn ) {
	if( s.startsFrom( "<img" ) )
		return( execute_img( s , sout , 0 , nn ) );

	// parse string
	int level = s.find( "*" );
	if( level < 0 )
		return( 1 );

	if( level < 2 )
		return( 13 );

	s.remove( 0 , level + 1 );
	level -= 2;

	if( nn.count() > 0 ) {
		Nerve *np = nn.last();
		if( np -> level < level )
			if( level != np -> level + 1 )
				return( 14 );
	}

	s.trim();
	if( s.startsFrom( "<img" ) )
		return( execute_img( s , sout , level , nn ) );

	if( !s.startsFrom( "*" ) )
		return( 2 );

	s.remove( 0 , 1 );

	// name
	int idx = s.find( "*" );
	if( idx < 0 )
		return( 3 );

	String name = s.getMid( 0 , idx );
	s.remove( 0 , idx + 1 );

	// synonyms
	String synonyms;
	if( s.startsFrom( " (" ) ) {
		s.remove( 0 , 2 );
		idx = s.find( ")" );
		if( idx < 0 )
			return( 4 );

		synonyms = s.getMid( 0 , idx );
		s.remove( 0 , idx + 1 );
	}

	String origin;
	String branches;
	String distribution;
	String modality;
	String fibers;
	if( s.startsFrom( "; " ) ) {
		s.remove( 0 , 2 );

		if( !extract_item( sout , origin , s , "ORIGIN" ) )
			return( 6 );

		if( !extract_item( sout , branches , s , "BRANCHES" ) )
			return( 8 );

		if( !extract_item( sout , distribution , s , "DISTRIBUTION" ) )
			return( 7 );

		if( !extract_item( sout , modality , s , "MODALITY" ) )
			return( 9 );

		if( !extract_item( sout , fibers , s , "FIBERS" ) )
			return( 10 );
	}

	if( !s.isEmpty() )
		return( 11 );

	Nerve *n = new Nerve;
	n -> fibers = fibers;

	String fibersinfo;
	if( !fibers.isEmpty() )
		if( !extract_fibers( sout , n -> fibersinfo , fibers ) ) {
			fprintf( sout , "wrong fibers=%s\n" , ( const char * )fibers );
			delete n;
			return( 12 );
		}

	n -> name = name;
	n -> synonyms = synonyms;
	n -> level = level;
	n -> origin = origin;
	n -> branches = branches;
	n -> distribution = distribution;
	n -> modality = modality;
	nn.add( n );

	return( 0 );
}
Esempio n. 28
0
void NerveTool::output_data( FILE *sout , ClassList<Nerve>& nn ) {
	for( int k = 0; k < nn.count(); k++ )
		output_nerve( sout , nn , k );
}
Esempio n. 29
0
bool NerveTool::extract_fiberitems( FILE *sout , StringList& fibersinfo , String type , String& value ) {
	// parse value: x,y -> x,y -> x,y ...
	ClassList<StringList> chain;

	value.trim();
	while( !value.isEmpty() ) {
		String part;
		int idx = value.find( "->" );
		if( idx < 0 ) {
			if( chain.count() == 0 )
				return( false );

			part = value;
			value.clear();
		}
		else {
			part = value.getMid( 0 , idx );
			value.remove( 0 , idx + 2 );
			value.trim();

			if( value.isEmpty() )
				return( false );
		}

		// parse part
		StringList *z = new StringList;
		chain.add( z );
		if( !extract_codes( part , z ) ) {
			fprintf( sout , "wrong part=%s\n" , ( const char * )part );
			return( false );
		}

		// prohibit many-to-many		
		if( z -> count() > 1 && chain.count() > 1 ) {
			StringList& zp = chain.getRef( chain.count() - 2 );
			if( zp.count() > 1 )
				return( false );
		}
	}

	// chain of more than one
	if( chain.count() < 2 )
		return( false );

	// split chain
	int startChain = 0;
	int startChainCount = 0;
	for( int k = 0; k < chain.count(); k++ ) {
		StringList& z = chain.getRef( k );
		int zn = z.count();

		// starter
		if( k == 0 ) {
			startChainCount = zn;
			continue;
		}

		// many to one - split
		if( startChainCount > 1 ) {
			if( zn != 1 )
				return( false );

			addManyToOne( fibersinfo , type , chain.getRef( startChainCount ) , z.get( 0 ) );
			startChain = k;
			startChainCount = zn;
			continue;
		}

		// allow x -> y -> z as is
		if( zn == 1 ) {
			if( k == chain.count() - 1 ) {
				addSingleChain( fibersinfo , type , chain , startChain , k );
				break;
			}

			continue;
		}

		// x -> y -> x,y - split to x -> y and y -> x,y
		if( ( k - 1 ) > startChain ) {
			addSingleChain( fibersinfo , type , chain , startChain , k - 1 );
			startChain = k - 1;
			startChainCount = 1;
		}

		addOneToMany( fibersinfo , type , chain.getRef( startChain ).get( 0 ) , z );
		startChain = k;
		startChainCount = zn;
	}

	chain.destroy();

	return( true );
}
Esempio n. 30
0
bool
CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
{
    string scoped = p->scoped();
    string name = getName(p);
    string type = getTypeVar(p);
    string abs = getAbsolute(p, _ns);
    string prxName = getName(p, "Prx");
    string prxType = getTypeVar(p, "Prx");
    string prxAbs = getAbsolute(p, _ns, "", "Prx");
    ClassList bases = p->bases();
    ClassDefPtr base;
    OperationList ops = p->operations();
    OperationList::iterator oli;
    DataMemberList members = p->dataMembers();
    bool isInterface = p->isInterface();
    bool isAbstract = isInterface || p->allOperations().size() > 0; // Don't use isAbstract() - see bug 3739

    startNamespace(p);

    //
    // Define the class.
    //
    if(isInterface)
    {
        _out << sp << nl << "if(!interface_exists('" << escapeName(abs) << "'))";
        _out << sb;
        _out << nl << "interface " << name;
        if(!bases.empty())
        {
            _out << " extends ";
            for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
            {
                if(q != bases.begin())
                {
                    _out << ", ";
                }
                _out << getAbsolute(*q, _ns);
            }
        }
        _out << sb;
        for(oli = ops.begin(); oli != ops.end(); ++oli)
        {
            _out << nl << "public function " << fixIdent((*oli)->name()) << '(';
            ParamDeclList params = (*oli)->parameters();
            for(ParamDeclList::iterator q = params.begin(); q != params.end(); ++q)
            {
                if(q != params.begin())
                {
                    _out << ", ";
                }
                _out << '$' << fixIdent((*q)->name());
            }
            _out << ");";
        }
        _out << eb;
    }
    else
    {
        _out << sp << nl << "if(!class_exists('" << escapeName(abs) << "'))";
        _out << sb;
        _out << nl;
        if(isAbstract)
        {
            _out << "abstract ";
        }
        _out << "class " << name;
        if(!bases.empty() && !bases.front()->isInterface())
        {
            base = bases.front();
            bases.pop_front();
        }
        if(base)
        {
            _out << " extends " << getAbsolute(base, _ns);
        }
        else
        {
            if(!p->isLocal())
            {
                _out << " extends " << scopedToName("::Ice::ObjectImpl", _ns);
            }
        }
        if(!bases.empty())
        {
            _out << " implements ";
            for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
            {
                if(q != bases.begin())
                {
                    _out << ", ";
                }
                _out << getAbsolute(*q, _ns);
            }
        }

        _out << sb;

        //
        // __construct
        //
        _out << nl << "public function __construct(";
        MemberInfoList allMembers;
        collectClassMembers(p, allMembers, false);
        writeConstructorParams(allMembers);
        _out << ")";
        _out << sb;
        if(base)
        {
            _out << nl << "parent::__construct(";
            int count = 0;
            for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q)
            {
                if(q->inherited)
                {
                    if(count)
                    {
                        _out << ", ";
                    }
                    _out << '$' << q->fixedName;
                    ++count;
                }
            }
            _out << ");";
        }
        {
            for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q)
            {
                if(!q->inherited)
                {
                    writeAssign(*q);
                }
            }
        }
        _out << eb;

        if(!ops.empty())
        {
            _out << sp;
            for(oli = ops.begin(); oli != ops.end(); ++oli)
            {
                _out << nl << "abstract public function " << fixIdent((*oli)->name()) << '(';
                ParamDeclList params = (*oli)->parameters();
                for(ParamDeclList::iterator q = params.begin(); q != params.end(); ++q)
                {
                    if(q != params.begin())
                    {
                        _out << ", ";
                    }
                    _out << '$' << fixIdent((*q)->name());
                }
                _out << ");";
            }
        }

        if(!p->isLocal())
        {
            //
            // ice_staticId
            //
            _out << sp << nl << "public static function ice_staticId()";
            _out << sb;
            _out << nl << "return '" << scoped << "';";
            _out << eb;
        }

        //
        // __toString
        //
        _out << sp << nl << "public function __toString()";
        _out << sb;
        _out << nl << "global " << type << ';';
        _out << nl << "return IcePHP_stringify($this, " << type << ");";
        _out << eb;

        if(!members.empty())
        {
            _out << sp;
            bool isProtected = p->hasMetaData("protected");
            for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q)
            {
                _out << nl;
                if(isProtected || (*q)->hasMetaData("protected"))
                {
                    _out << "protected ";
                }
                else
                {
                    _out << "public ";
                }
                _out << "$" << fixIdent((*q)->name()) << ";";
            }
        }

        _out << eb; // End of class.
    }

    //
    // Define the proxy class.
    //
    if(!p->isLocal())
    {
        _out << sp << nl << "class " << prxName << "Helper";
        _out << sb;

        _out << sp << nl << "public static function checkedCast($proxy, $facetOrCtx=null, $ctx=null)";
        _out << sb;
        _out << nl << "return $proxy->ice_checkedCast('" << scoped << "', $facetOrCtx, $ctx);";
        _out << eb;

        _out << sp << nl << "public static function uncheckedCast($proxy, $facet=null)";
        _out << sb;
        _out << nl << "return $proxy->ice_uncheckedCast('" << scoped << "', $facet);";
        _out << eb;

        _out << eb;
    }

    if(_classHistory.count(scoped) == 0 && p->canBeCyclic())
    {
        //
        // Emit a forward declaration for the class in case a data member refers to this type.
        //
        _out << sp << nl << type << " = IcePHP_declareClass('" << scoped << "');";
    }

    //
    // Emit the type information.
    //
    _out << sp << nl << type << " = IcePHP_defineClass('" << scoped << "', '" << escapeName(abs) << "', "
         << (isAbstract ? "true" : "false") << ", ";
    if(!base)
    {
        _out << "$Ice__t_Object";
    }
    else
    {
        _out << getTypeVar(base);
    }
    _out << ", ";
    //
    // Interfaces
    //
    if(!bases.empty())
    {
        _out << "array(";
        for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
        {
            if(q != bases.begin())
            {
                _out << ", ";
            }
            _out << getTypeVar(*q);
        }
        _out << ')';
    }
    else
    {
        _out << "null";
    }
    _out << ", ";
    //
    // Members
    //
    // Data members are represented as an array:
    //
    //   ('MemberName', MemberType)
    //
    // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type.
    //
    if(!members.empty())
    {
        _out << "array(";
        for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q)
        {
            if(q != members.begin())
            {
                _out << ',' << nl;
            }
            _out.inc();
            _out << nl << "array('" << fixIdent((*q)->name()) << "', ";
            writeType((*q)->type());
            _out << ')';
            _out.dec();
        }
        _out << ')';
    }
    else
    {
        _out << "null";
    }
    _out << ");";

    if(!p->isLocal())
    {
        _out << sp << nl << prxType << " = IcePHP_defineProxy(" << type << ");";

        //
        // Define each operation. The arguments to IcePHP_defineOperation are:
        //
        // $ClassType, 'opName', Mode, SendMode, (InParams), (OutParams), ReturnType, (Exceptions)
        //
        // where InParams and OutParams are arrays of type descriptions, and Exceptions
        // is an array of exception type ids.
        //
        if(!ops.empty())
        {
            _out << sp;
            for(oli = ops.begin(); oli != ops.end(); ++oli)
            {
                ParamDeclList params = (*oli)->parameters();
                ParamDeclList::iterator t;
                int count;

                _out << nl << "IcePHP_defineOperation(" << type << ", '" << (*oli)->name() << "', "
                     << getOperationMode((*oli)->mode(), _ns) << ", " << getOperationMode((*oli)->sendMode(), _ns)
                     << ", ";
                for(t = params.begin(), count = 0; t != params.end(); ++t)
                {
                    if(!(*t)->isOutParam())
                    {
                        if(count == 0)
                        {
                            _out << "array(";
                        }
                        else if(count > 0)
                        {
                            _out << ", ";
                        }
                        writeType((*t)->type());
                        ++count;
                    }
                }
                if(count > 0)
                {
                    _out << ')';
                }
                else
                {
                    _out << "null";
                }
                _out << ", ";
                for(t = params.begin(), count = 0; t != params.end(); ++t)
                {
                    if((*t)->isOutParam())
                    {
                        if(count == 0)
                        {
                            _out << "array(";
                        }
                        else if(count > 0)
                        {
                            _out << ", ";
                        }
                        writeType((*t)->type());
                        ++count;
                    }
                }
                if(count > 0)
                {
                    _out << ')';
                }
                else
                {
                    _out << "null";
                }
                _out << ", ";
                TypePtr returnType = (*oli)->returnType();
                if(returnType)
                {
                    writeType(returnType);
                }
                else
                {
                    _out << "null";
                }
                _out << ", ";
                ExceptionList exceptions = (*oli)->throws();
                if(!exceptions.empty())
                {
                    _out << "array(";
                    for(ExceptionList::iterator u = exceptions.begin(); u != exceptions.end(); ++u)
                    {
                        if(u != exceptions.begin())
                        {
                            _out << ", ";
                        }
                        _out << getTypeVar(*u);
                    }
                    _out << ')';
                }
                else
                {
                    _out << "null";
                }
                _out << ");";
            }
        }
    }

    _out << eb;

    endNamespace();

    if(_classHistory.count(scoped) == 0)
    {
        _classHistory.insert(scoped); // Avoid redundant declarations.
    }

    return false;
}