void MatLabUdmChart::setupChart( Udm::Object udmParent ) {

	SLSF::Block parentBlock = SLSF::Block::Cast( udmParent );
	SLSF::Parameter parameter = SLSF::Parameter::Create( parentBlock );
	parameter.RefId() = getRefId();
	parameter.name() = "ExecuteAtInitialization";
	int executeAtInitialization = MatLabEngine::globalEngine().getMxIntValue( getMatLabObject() + ".ExecuteAtInitialization" );
	parameter.Value() = executeAtInitialization ? "on" : "off";

	State chart = getUdmChart();

	chart.Name() = chart.name() = forceGetUniqueName().c_str();
	chart.RefId() = getRefId();

#if PARADIGM != CyberComposition_PARADIGM
	ConnectorRefSet connectorRefSet = chart.referedbyConnectorRef();
	for( ConnectorRefSet::iterator crsItr = connectorRefSet.begin() ; crsItr != connectorRefSet.end() ; ++crsItr ) {
		crsItr->name() = chart.name();
	}
#endif

	chart.Description() = MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Description" );
	std::string decomposition = MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Decomposition" );
	if (  decomposition == "OR" || decomposition.find( "_OR" )  !=  std::string::npos  ) {
		chart.Decomposition() = "OR_STATE";
	} if (  decomposition == "AND" || decomposition.find( "_AND" )  !=  std::string::npos  ) {
		chart.Decomposition() = "AND_STATE";
	}

	chart.Order() = "0";
}
void MatLabUdmEvent::setupEvent( void ) {
	Event event = getUdmEvent();

	event.Description() = MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Description" ).c_str();
	event.Name() = event.name() = getUniqueName().c_str();
	event.RefId() = getRefId();

	std::string eventScope = MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Scope" );
	std::transform( eventScope.begin(), eventScope.end(), eventScope.begin(), ToUpper() );
	event.Scope() = ( eventScope + "_EVENT" ).c_str();

	int port = MatLabEngine::globalEngine().getMxIntValue( getMatLabObject() + ".Port" );
	event.Port() = port > 0 ? port : -1;

	static std::string funcTestString( "FUNCTION" );

	std::string eventTrigger = MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Trigger" );
	std::transform( eventTrigger.begin(), eventTrigger.end(), eventTrigger.begin(), ToUpper() );
	event.Trigger() = eventTrigger.compare( 0, funcTestString.size(), funcTestString ) == 0 ? "FUNCTION_CALL_EVENT" : ( eventTrigger + "_EDGE_EVENT" ).c_str();

	SLSF::TypeBaseRef typeBaseRef = SLSF::TypeBaseRef::Create( event );

	SLSF::Matrix ESMoLMatrix = SLSF::Matrix::Create( UdmEngine::getUdmTypesRoot() );
	ESMoLMatrix.Type() = "boolean";
	ESMoLMatrix.rows() = 1;
	ESMoLMatrix.columns() = 1;

	UdmEngine::integrateTypeBase( ESMoLMatrix );
	typeBaseRef.ref() = ESMoLMatrix;
	typeBaseRef.name() = ESMoLMatrix.name();
}
void MatLabUdmJunction::setupJunction( void ) {

	Junction junction = getUdmJunction();
	junction.RefId() = getRefId();

	registerForTransitions();
}
void MatLabUdmState::setupState( void ) {

	State udmState = getUdmState();
	udmState.name() = getUniqueName().c_str();
	udmState.RefId() = getRefId();
	udmState.Description() = MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Description" );

	// GET LABEL STRING, PERFORM SUBSTITUTIONS FOR READABILITY
	std::string labelString = RegexCommon::eliminateContinuations(  MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".LabelString" )  );
	labelString = boost::regex_replace( labelString, MatLabEngine::matLabComment(), "" );


	std::string stateType = MatLabEngine::globalEngine().getMxStringValue(  std::string( "class( " + getMatLabObject() + " )" )  );

	if ( stateType == "Stateflow.Box" ) {
		udmState.Decomposition() = "GROUP_STATE";
		return;
	}

	// REGISTER THIS STATE SO TRANSITIONS CAN LOCATE IT AND USE IT AS AN ENDPOINT
	registerForTransitions();

	std::string stateOrder = boost::lexical_cast< std::string >(
	 MatLabEngine::globalEngine().getMxIntValue( getMatLabObject() + ".ExecutionOrder" )
	);
	udmState.Order() = stateOrder.empty() ? "0" : stateOrder;

	static boost::regex nameRegex(  std::string( "\\A\\s*(\\w*)\\s*/?\\s*" ), boost::regex_constants::perl  );
	static boost::regex actionRegex(  std::string( "((\\w+)\\s*:\\s*(.*?\\S?)\\s*)(?:\\w+\\s*:|\\z)" ), boost::regex_constants::perl  );
	static boost::regex defaultActionRegex(  std::string( "\\A\\s*(.*\\S?)\\s*\\Z" ), boost::regex_constants::perl  );
	boost::match_results< std::string::const_iterator > results;

	if (  regex_search( labelString, results, nameRegex )  ) {
		udmState.Name() = std::string( results[1].first, results[1].second ).c_str();
		labelString = std::string(  results[0].second, static_cast< std::string::const_iterator >( labelString.end() )  );
	}

	while (  regex_search( labelString, results, actionRegex )  ) {
		std::string actionName( results[2].first, results[2].second );
		std::transform( actionName.begin(), actionName.end(), actionName.begin(), ToLower() );
		std::string actionValue( results[3].first, results[3].second );
		if      ( actionName.substr(0, 2) == "en" ) udmState.EnterAction()  = actionValue.c_str();
		else if ( actionName.substr(0, 1) == "d" )  udmState.DuringAction() = actionValue.c_str();
		else if ( actionName.substr(0, 2) == "ex" ) udmState.ExitAction()   = actionValue.c_str();

		labelString.replace(
		 results[1].first - labelString.begin(),
		 results[1].second - results[1].first,
		 ""
		);
	}

	regex_search( labelString, results, defaultActionRegex );
	std::string defaultEnterAction( results[1].first, results[1].second );
	if (  defaultEnterAction != ""  &&  std::string( udmState.EnterAction() ) == ""  ) {
		udmState.EnterAction() = defaultEnterAction;
	}

	udmState.Decomposition() = MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Type" ) + "_STATE";
}
void MatLabUdmFunction::setupFunction( void ) {
	State udmFunction = getUdmFunction();

	udmFunction.Name() = udmFunction.name() = getUniqueName().c_str();
	udmFunction.Decomposition() = "FUNC_STATE";
	udmFunction.Order() = "-1";
	udmFunction.RefId() = getRefId();

	udmFunction.EnterAction() = RegexCommon::eliminateContinuations(  MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".LabelString" )  );
}
void MatLabUdmEMFunction::setupEMFunction( void ) {

	State udmEMFunction = getUdmEMFunction();

	udmEMFunction.Name() = udmEMFunction.name() = getUniqueName().c_str();
	udmEMFunction.RefId() = getRefId();
	udmEMFunction.Decomposition() = "FUNC_STATE";
	udmEMFunction.Order() = "-2";

	udmEMFunction.EnterAction() = RegexCommon::eliminateContinuations(  MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".LabelString" )  );

	std::string functionBody = RegexCommon::eliminateContinuations(  MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".Script" )  );
	functionBody = boost::regex_replace( functionBody, RegexCommon::getFunctionHeaderRegex(), "" );
	
	udmEMFunction.DuringAction() = functionBody;
}
예제 #7
0
bool JsAgent::wrapLocalValue(const Variant& var, JsValue& value) {
	if(var.isInt()) {
		value.tag = VT_Int;
		value.intValue = var.asInt();
	} 
	else if(var.isString()) {
		value.tag = VT_String;
		value.strValue = var.asString();
	}
	else if(var.isObject()) {
		NPObject* pObject = var.asObject();
		if(pObject->_class == GetNPClass<JsObjectWrapper>()) {
			uint32_t id = 0;
			value.tag = VT_Object;
			value.intValue = id;
		}
		else {
			uint32_t id = getRefId(pObject);
			value.tag = VT_JsObject;
			value.intValue = id;
		}
	}
	else if(var.isNull()) {
		value.tag = VT_Null;
	}
	else if(var.isBool()) {
		value.tag = VT_Bool;
		value.boolValue = var.asBool();
	}
	else if(var.isDouble()) {
		value.tag = VT_Double;
		value.doubleValue = var.asDouble();
	}
	else if(var.isVoid()) {
		value.tag = VT_Void;
	}
	else {
		return false;
	}
	return true;
}
void MatLabUdmTruthTable::setupTruthTable( void ) {
	State udmTruthTable = getUdmTruthTable();

	udmTruthTable.Name() = udmTruthTable.name() = getUniqueName().c_str();
	udmTruthTable.RefId() = getRefId();
	udmTruthTable.Decomposition() = "FUNC_STATE";
	udmTruthTable.Order() = "-2";

	udmTruthTable.EnterAction() = RegexCommon::eliminateContinuations(  MatLabEngine::globalEngine().getMxStringValue( getMatLabObject() + ".LabelString" )  );

	std::string conditionTable = MatLabEngine::globalEngine().getData( getMatLabObject() + ".ConditionTable" );
	StringVectorManager conditionSTM = getStringVectorManager( conditionTable );

	std::string actionTable = MatLabEngine::globalEngine().getData( getMatLabObject() + ".ActionTable" );
	StringVectorManager actionSTM = getStringVectorManager( actionTable );

	std::string functionBody;

	StringMatrix conditionStringMatrix = conditionSTM.getStringMatrix();
	int noConditions = (int) conditionStringMatrix[0]->size() - 2;
	int noConditionTerms = (int) conditionStringMatrix.size() - 1;

	static boost::regex crnlPattern( "\\r|\\n", boost::regex_constants::perl );

	for( int ix = 0 ; ix < noConditions ; ++ix ) {

		if ( ix != 0 ) functionBody += "else";
		functionBody += "if ";

		std::string condition;
		for( int jx = 0 ; jx < noConditionTerms ; ++jx ) {
			StringVector &stringVector = *conditionStringMatrix[ jx ];
			std::string tf = stringVector[ ix + 2 ];

			std::string rawCondition = "(" + boost::regex_replace( stringVector[1], crnlPattern, " " ) + ")";

			if (  tf.find( '-' ) != std::string::npos  ) continue;
			if (  tf.find( 'F' ) != std::string::npos  ) rawCondition = "!" + rawCondition;

			if ( !condition.empty() ) condition += " && ";
			condition += rawCondition;
		}
		if ( condition.empty() ) condition = "1";
		functionBody += condition + "\n";

		StringVector actionVector;
		std::string actions = ( *conditionStringMatrix.back() )[ ix + 2 ];

		static boost::regex actionPattern( "[0-9]+|[A-Za-z_][A-Za-z_0-9]*" );
		boost::match_results< std::string::const_iterator > results;
		while (  boost::regex_search( actions, results, actionPattern )  ) {
			actionVector.push_back( results[0] );
			actions = results.suffix();
		}

		static boost::regex newlinePattern( "\n" );
		for( StringVector::iterator stvItr = actionVector.begin() ; stvItr != actionVector.end() ; ++stvItr ) {
			std::string actionSpec = *stvItr;
			if (  isdigit( actionSpec[0] )  ) {
				int actionNo = boost::lexical_cast< int >( actionSpec ) - 1;
				std::string action = (*actionSTM.getStringMatrix()[ actionNo ])[ 1 ];
				action = boost::regex_replace( action, newlinePattern, "\n  " );
				functionBody += "  " + action + "\n";
			} else {
				std::string action = (*actionSTM.getStringVectorMap()[ actionSpec ])[ 1 ];
				action = boost::regex_replace( action, newlinePattern, "\n  " );
				functionBody += "  " + action + "\n";
			}
		}

	}

	functionBody += "end\n";

	udmTruthTable.DuringAction() = functionBody;
}
예제 #9
0
파일: types.hpp 프로젝트: Brainiarc7/TS
 bool isMismatchedChr() const {
     assert(m_dataPtr);
     return (getRefId() != getMateRefId());
 }