CStringEx CTypeUnitDouble::FormatDouble( const double dvalue ) const { int decimal, sign; char *buffer; if( dvalue == 0 ) return( CStringEx( "0.0" )); #ifdef NL_OS_WINDOWS buffer = _fcvt( dvalue, 5, &decimal, &sign ); #else buffer = fcvt( dvalue, 5, &decimal, &sign ); #endif // NL_OS_WINDOWS CStringEx sx( buffer ); if( decimal <= 0 ) { sx = (std::string)(CStringEx( "0." ) + CStringEx( '0', -decimal ) + sx); } else sx.insert(decimal,"."); while( sx[sx.length()-1] == '0' ) sx.left( (int)sx.length() -1 ); if( sx[sx.length()-1] == '.' ) sx += '0'; if( sign ) sx = CStringEx( "-" + sx ); return sx; }
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 ) ); }
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::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 ) ); } }
/* CStringEx CTypeUnitDouble::Format( const CStringEx _sxvalue ) const { if( _sxvalue.empty() ) return( sxdefaultvalue ); double dvalue = atof( _sxvalue.c_str() ); if( dvalue < dlowlimit ) dvalue = dlowlimit; if( dvalue > dhighlimit ) dvalue = dhighlimit; return( FormatDouble( dvalue ) ); } */ CStringEx CTypeUnitDouble::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] == '<' ) { std::string::size_type pos = value.find( '>' ); if( pos == std::string::npos ) break; CStringEx sxoperateur = value.get_mid( 1, 1 ); CStringEx sxoperande = value.get_mid( 2, (int)pos-2); value.right( (int)(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 { double dvalue = atof( _sxvalue.c_str() ); if( dvalue < dlowlimit ) dvalue = dlowlimit; if( dvalue > dhighlimit ) dvalue = dhighlimit; return( FormatDouble( dvalue ) ); } }