コード例 #1
0
ファイル: OrgOp.cpp プロジェクト: eriser/es
bool COrgOp::Load( CStr &roSrc, unsigned int uiIDOffset )
{
	CStr oStrLine;
	CStr oStrToken;
	CList<COp *> oLstPatch;
	unsigned int uiIDIn = 0;
	unsigned int uiIdxIn = 0;
	unsigned int uiCountIn = 0;
	unsigned int uiPortIn = 0;
	unsigned int uiIndexIn = 0;
	unsigned int uiCountOut = 0;
	unsigned int uiPortOut = 0;
	unsigned int uiInteralInt = 0;
	unsigned int uiInteralUInt = 0;
	unsigned int uiInteralFlt = 0;
	unsigned int i = 0;
	unsigned int uiMaxIPortIn = 0;
	unsigned int uiMaxIPortOut = 0;
	unsigned int uiMaxIInternalInt = 0;
	unsigned int uiMaxIInternalUInt = 0;
	unsigned int uiMaxIInternalFlt = 0;
	COp *poOp = 0;
	
	// <mod date="2010-12-07">
	CList<CArray<unsigned int> *> oLstArrID;
	CArray<unsigned int> * poArrID = 0;
	// </mod>
	
	// Alle Operatoren einlesen, erstellen und pseudo-patchen.
	while( 1 )
	{
		if( !Decode_GetNextLine( oStrLine, roSrc ) )
			break;
		i = 0;
		while( 1 )
		{
			if( !Decode_GetNextToken( oStrToken, oStrLine ) )
				break;

			if( !oStrToken.GetSize() )
			{
				if( i > 1 ) // Komprimierung :: -> :0:
					oStrToken = '0';
				else if( i == 0 )
					ORG_OP_LOG( "Fehler: Klassen-Name nicht vorhanden." );
			}

			// class
			if( i == 0 )
			{
				poOp = Create( oStrToken );
				if( poOp == 0 )
				{
					ORG_OP_LOG( "Fehler: Unbekannte Klasse: %s\n", oStrToken.GetData() );
					return false;
				}
				oLstPatch.Append( poOp );
			}
			// instance
			else if( i == 1 )
			{
#ifdef OP_USE_RUNTIME_INFO
				poOp->SetNameInstance( oStrToken );
#endif // OP_USE_RUNTIME_INFO
			}
			// id
			else if( i == 2 )
			{
				unsigned int uiID;
				ORG_OP_SSCANF( oStrToken, "%x", &uiID );
				poOp->SetID( uiID + uiIDOffset ); // Um keinen Konflikt zu erzeugen.
			}
			// flags
			else if( i == 3 )
			{
				unsigned int uiFlags;
				ORG_OP_SSCANF( oStrToken, "%x", &uiFlags );
				poOp->SetFlags( uiFlags );
			}
			// count_input
			else if ( i == 4 )
			{
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountIn );
				if( poOp->GetFlags() & OP_FLAG_DYNAMIC_INPUTS )
				{
					poOp->SetCountIn( uiCountIn );
				}
				else if( poOp->GetCountIn() != uiCountIn )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Inputs unterstuetzt! "
						     "Keine dynamischen Inputs!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiPortIn = 0;
				uiIndexIn = 0;
				uiMaxIPortIn = 3 * uiCountIn + 4 + 1;
				
				// <mod date="2010-12-07">
				poArrID = new CArray<unsigned int>( uiCountIn );
				oLstArrID.Append( poArrID );
				// </mod>
			}
			// inputs
			else if( i < uiMaxIPortIn )
			{
				unsigned int uiVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%x", &uiVal );
				switch( uiIndexIn )
				{
				case 0: // id
					uiIDIn = uiVal;
				break;
				case 1: // port
					uiIdxIn = uiVal;
				break;
				case 2: // flags
					if( uiIDIn )
						uiIDIn += uiIDOffset; // Um keinen Konflikt zu erzeugen.
					
					// <mod date="2010-12-07">
					poArrID->At( uiPortIn ) = uiIDIn;
					poOp->In( uiPortIn ) = COp::CLink( 0, uiIdxIn, uiVal );
					//poOp->In( uiPortIn ) = COp::CLink( reinterpret_cast<COp *>( uiIDIn ), uiIdxIn, uiVal );
					// </mod>
					
					++uiPortIn;
				break;
				}
				++uiIndexIn;
				if( uiIndexIn == 3 )
					uiIndexIn = 0;
			}

			// count_output
			else if( i == uiMaxIPortIn )
			{
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountOut );
				if( poOp->GetFlags() & OP_FLAG_DYNAMIC_OUTPUTS )
				{
					poOp->SetCountOut( uiCountOut );
				}
				else if( poOp->GetCountOut() != uiCountOut )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Outputs unterstuetzt! "
						     "Keine dynamischen Outputs!\n", poOp->GetNameClass(), uiCountOut );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiPortOut = 0;
				uiMaxIPortOut = uiCountOut + uiMaxIPortIn + 1;
			}
			// outputs
			else if( i < uiMaxIPortOut )
			{
				double dVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%lf", &dVal );
				poOp->Out( uiPortOut ) = dVal;
				++uiPortOut;
			}

			// int internal count
			else if( i == uiMaxIPortOut )
			{
				unsigned int uiCountInternalInt;
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountInternalInt );
				if( poOp->GetCountInternalInt() != uiCountInternalInt )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Int-Interals unterstuetzt!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiInteralInt = 0;
				uiMaxIInternalInt = uiMaxIPortOut + uiCountInternalInt + 1;
			}
			// int internals
			else if( i < uiMaxIInternalInt )
			{
				int iVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%d", &iVal );
				poOp->SetValueInternalInt( uiInteralInt, iVal );
				++uiInteralInt;
			}
			// uint internal count
			else if( i == uiMaxIInternalInt )
			{
				unsigned int uiCountInternalUInt;
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountInternalUInt );
				if( poOp->GetCountInternalUInt() != uiCountInternalUInt )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d UInt-Interals unterstuetzt!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiInteralUInt = 0;
				uiMaxIInternalUInt = uiMaxIInternalInt + uiCountInternalUInt + 1;
			}
			// uint internals
			else if( i < uiMaxIInternalUInt )
			{
				unsigned int uiVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%u", &uiVal );
				poOp->SetValueInternalUInt( uiInteralUInt, uiVal );
				++uiInteralUInt;
			}
			// flt internal count
			else if( i == uiMaxIInternalUInt )
			{
				unsigned int uiCountInternalFlt;
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountInternalFlt );
				if( poOp->GetCountInternalFlt() != uiCountInternalFlt )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Float-Interals unterstuetzt!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiInteralFlt = 0;
				uiMaxIInternalFlt = uiMaxIInternalUInt + uiCountInternalFlt + 1;
			}
			// flt internals
			else if( i < uiMaxIInternalFlt )
			{
				double dVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%lf", &dVal );
				poOp->SetValueInternalFlt( uiInteralFlt, dVal );
				++uiInteralFlt;
			}
			else
				break;
			++i;
		}
	}

	// Pseudo-Patch nun mit echten Verbindungen versehen.
	i = oLstPatch.GetSize();
	/*
	if( i < 2 )
	{
		ORG_OP_LOG( "Fehler: Weniger als 2 Operatoren eingelesen!\n" );
		return false;
	}
	*/

	// Altes Patch löschen.
	//Clear();
	//m_poOpRootL_ = 0;
	//m_poOpRootR_ = 0;
	
	
	// <mod date="2010-12-07">
	oLstArrID.MoveToBack();
	// </mod>
	
	while( i )
	{
		--i;
		poOp = oLstPatch[i];
		
		// <mod date="2010-12-07">
		oLstArrID.GetPrev( &poArrID );
		// </mod>
		
		if( poOp )
		{
			unsigned int uiIn = poOp->GetCountIn();
			while( uiIn )
			{
				--uiIn;
				
				// <mod date="2010-12-07">
				const unsigned int uiTmpIDNext = poArrID->At( uiIn );
				//unsigned int uiTmpIDNext =
				//	reinterpret_cast<unsigned int>( poOp->In( uiIn ).GetOp() );
				// </mod>
				
				if( !uiTmpIDNext ) // ID 0 ist ungültig.
					continue;

				// Ganze Liste durchiterieren, und nach der ID aus dem aktuellen
				// Input-Array Ausschau halten!
				COp *poOpNext;
				oLstPatch.MoveToFront();
				while( oLstPatch.GetNext( &poOpNext ) )
				{
					if( poOpNext->GetID() == uiTmpIDNext )
					{
						poOp->In( uiIn ).SetOp( poOpNext );
					}
				}
			}
		}

		//if( i == 0 )
		//	m_poOpRootL_ = poOp;
		//else if ( i == 1 )
		//	m_poOpRootR_ = poOp;
	}
	
	// <mod date="2010-12-07">
	LIST_DELETE( oLstArrID, CArray<unsigned int> );
	// </mod>
	
	// Alle aufglösten Operatoren in die echte Liste einfügen...
	oLstPatch.MoveToFront();
	while( oLstPatch.GetNext( &poOp ) )
	{
#ifdef OP_USE_USER_DATA
		poOp->m_pvData = 0;
#endif // OP_USE_USER_DATA
		m_oLstOp.Append( poOp );
	}

	//UpdateAll();
	ValidateAll();
	return true;
}