CTypeUnitIntSigned::CTypeUnitIntSigned( const CStringEx _sxll, const CStringEx _sxhl, const CStringEx _sxdv, const CStringEx _sxf ) : CTypeUnit( _sxll, _sxhl, _sxdv, _sxf )
{
	ilowlimit = atoiInt64( sxlowlimit.c_str() ); 
	ihighlimit = atoiInt64( sxhighlimit.c_str() ); 
	idefaultvalue = atoiInt64( sxdefaultvalue.c_str() ); 
	if( sxformula.empty() )
		sxformula = CStringEx( "sint(" +_sxll +"," +_sxhl +")" );
}
CStringEx CTypeUnitIntSigned::CalculateResult( const CStringEx _sxbasevalue, const CStringEx _sxvalue ) const	
{
	nlassert( !_sxbasevalue.empty() );
	if( _sxvalue.empty() )
		return( _sxbasevalue );

	std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
	CStringEx value( _sxvalue );
	value.purge();
	while( value[0] == '<' )
	{
		unsigned int pos = value.find( '>' );
		if( pos == -1 )
			break;
		CStringEx sxoperateur = value.get_mid( 1, 1 );
		CStringEx sxoperande = value.get_mid( 2, pos-2);
		value.right( value.size()-pos-1 );
		modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
	}
	if( modificationValues.size() )
	{
		sint64 ir = atoiInt64( _sxbasevalue.c_str() );
		for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
		{
			sint64 ivalue = atoiInt64( it->second.c_str() );
			if( it->first == "+" )
				ir += ivalue;
			else if( it->first == "*" )
					ir *= ivalue;
				else if( it->first == "-" )
						ir -= ivalue;
					else if( it->first == "/" )
							ir /= ivalue;   
						else if( it->first == "^" )
								ir = (sint64)( pow( (double)(ir), (double)(ivalue) ) );   
		}
		if( ir < ilowlimit )
			ir = ilowlimit;
		if( ir > ihighlimit )
			ir = ihighlimit;
		char pc[256];
		itoaInt64( ir, pc, 10 );
		return( CStringEx( pc ) );
	}
	else
	{
		sint64 ivalue = atoiInt64( _sxvalue.c_str() );
		if( ivalue < ilowlimit )
			ivalue = ilowlimit;
		if( ivalue > ihighlimit )
			ivalue = ihighlimit;
		char pc[256];
		itoaInt64( ivalue, pc, 10 );
		return( CStringEx( pc ) );
	}

	return( Format( _sxvalue ) );
}
Beispiel #3
0
void CLogicVariable::read (xmlNodePtr node)
{
	xmlCheckNodeName (node, "VARIABLE");

	_Name = getXMLProp (node, "Name");
	_Value = atoiInt64 (getXMLProp (node, "Value").c_str());
	NLMISC::fromString(getXMLProp(node, "Verbose"), _Verbose);
}
Beispiel #4
0
void CLogicEventMessage::read (xmlNodePtr node, const char *subName)
{
	xmlCheckNodeName (node, string(string(subName)+string("EVENT_MESSAGE")).c_str());

	Destination = getXMLProp (node, "Destination");
	DestinationId = atoiInt64(getXMLProp (node, "DestinationId").c_str());
	MessageId = getXMLProp (node, "MessageId");
	Arguments = getXMLProp (node, "Arguments");
}
Beispiel #5
0
void CLogicCounter::read (xmlNodePtr node)
{
	xmlCheckNodeName (node, "COUNTER");

	_Name = getXMLProp (node, "Name");
	_Value = atoiInt64 (getXMLProp (node, "Value").c_str());
	_Verbose = atoi(getXMLProp (node, "Verbose").c_str()) == 1;
	Period.setValue(atoiInt64(getXMLProp (node, "Period").c_str()));
	Phase.setValue(atoiInt64(getXMLProp (node, "Phase").c_str()));
	Step.setValue(atoiInt64(getXMLProp (node, "Step").c_str()));
	LowLimit.setValue(atoiInt64(getXMLProp (node, "LowLimit").c_str()));
	HighLimit.setValue(atoiInt64(getXMLProp (node, "HighLimit").c_str()));
	Mode.setValue(atoiInt64(getXMLProp (node, "Mode").c_str()));
	Control.setValue(atoiInt64(getXMLProp (node, "Control").c_str()));
}
CStringEx CTypeUnitIntSigned::Format( const CStringEx _sxvalue ) const
{
	if( _sxvalue.empty() )
		return( sxdefaultvalue );

	std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
	CStringEx value( _sxvalue );
	value.purge();
	while( value[0] == '<' )
	{
		unsigned int pos = value.find( '>' );
		if( pos == -1 )
			break;
		CStringEx sxoperateur = value.get_mid( 1, 1 );
		CStringEx sxoperande = value.get_mid( 2, pos-2);
		value.right( value.size()-pos-1 );
		modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
	}
	if( modificationValues.size() )
	{
		CStringEx sxr;
		for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
		{
			sxr += CStringEx( "<" );
			sxr += it->first;
			sxr += it->second;
			sxr += CStringEx( ">" );
		}
		return( sxr );
	}
	else
	{
		sint64 ivalue = atoiInt64( _sxvalue.c_str() );
		if( ivalue < ilowlimit )
			ivalue = ilowlimit;
		if( ivalue > ihighlimit )
			ivalue = ihighlimit;

		char pc[256];
		itoaInt64( ivalue, pc, 10 );
		return( CStringEx( pc ) );
	}
}
void CTypeUnitIntSigned::SetHighLimit( const CStringEx _sxhl )
{
	sxhighlimit = _sxhl;
	ihighlimit = atoiInt64( sxhighlimit.c_str() ); 
}
void CTypeUnitIntSigned::SetLowLimit( const CStringEx _sxll )
{
	sxlowlimit = _sxll;
	ilowlimit = atoiInt64( sxlowlimit.c_str() ); 
}
void CTypeUnitIntSigned::SetDefaultValue( const CStringEx _sxdv )
{
	sxdefaultvalue = _sxdv;
	idefaultvalue = atoiInt64( sxdefaultvalue.c_str() ); 
}