00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdgeorges.h"
00027 #include "nel/georges/type_unit_int_unsigned.h"
00028 #include "nel/misc/common.h"
00029
00030 using namespace NLMISC;
00031
00032
00033 namespace NLGEORGES
00034 {
00035
00037
00039
00040 CTypeUnitIntUnsigned::CTypeUnitIntUnsigned( const CStringEx _sxll, const CStringEx _sxhl, const CStringEx _sxdv, const CStringEx _sxf ) : CTypeUnit( _sxll, _sxhl, _sxdv, _sxf )
00041 {
00042 ilowlimit = atoiInt64( sxlowlimit.c_str() );
00043 ihighlimit = atoiInt64( sxhighlimit.c_str() );
00044 idefaultvalue = atoiInt64( sxdefaultvalue.c_str() );
00045 if( sxformula.empty() )
00046 sxformula = CStringEx( "uint(" +_sxll +"," +_sxhl +")" );
00047 }
00048
00049 CTypeUnitIntUnsigned::~CTypeUnitIntUnsigned()
00050 {
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 CStringEx CTypeUnitIntUnsigned::Format( const CStringEx _sxvalue ) const
00072 {
00073 if( _sxvalue.empty() )
00074 return( sxdefaultvalue );
00075
00076 std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
00077 CStringEx value( _sxvalue );
00078 value.purge();
00079 while( value[0] == '<' )
00080 {
00081 unsigned int pos = value.find( '>' );
00082 if( pos == -1 )
00083 break;
00084 CStringEx sxoperateur = value.get_mid( 1, 1 );
00085 CStringEx sxoperande = value.get_mid( 2, pos-2);
00086 value.right( value.size()-pos-1 );
00087 modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
00088 }
00089 if( modificationValues.size() )
00090 {
00091 CStringEx sxr;
00092 for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
00093 {
00094 sxr += CStringEx( "<" );
00095 sxr += it->first;
00096 sxr += it->second;
00097 sxr += CStringEx( ">" );
00098 }
00099 return( sxr );
00100 }
00101 else
00102 {
00103 uint64 ivalue = atoiInt64( _sxvalue.c_str() );
00104 if( ivalue < ilowlimit )
00105 ivalue = ilowlimit;
00106 if( ivalue > ihighlimit )
00107 ivalue = ihighlimit;
00108
00109 char pc[256];
00110 itoaInt64( ivalue, pc, 10 );
00111 return( CStringEx( pc ) );
00112 }
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 CStringEx CTypeUnitIntUnsigned::CalculateResult( const CStringEx _sxbasevalue, const CStringEx _sxvalue ) const
00126 {
00127 nlassert( !_sxbasevalue.empty() );
00128 if( _sxvalue.empty() )
00129 return( _sxbasevalue );
00130
00131 std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
00132 CStringEx value( _sxvalue );
00133 value.purge();
00134 while( value[0] == '<' )
00135 {
00136 unsigned int pos = value.find( '>' );
00137 if( pos == -1 )
00138 break;
00139 CStringEx sxoperateur = value.get_mid( 1, 1 );
00140 CStringEx sxoperande = value.get_mid( 2, pos-2);
00141 value.right( value.size()-pos-1 );
00142 modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
00143 }
00144 if( modificationValues.size() )
00145 {
00146 sint64 ir = atoiInt64( _sxbasevalue.c_str() );
00147 for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
00148 {
00149 sint64 ivalue = atoiInt64( it->second.c_str() );
00150 if( it->first == "+" )
00151 ir += ivalue;
00152 else if( it->first == "*" )
00153 ir *= ivalue;
00154 else if( it->first == "-" )
00155 ir -= ivalue;
00156 else if( it->first == "/" )
00157 ir /= ivalue;
00158 else if( it->first == "^" )
00159 {
00160 ir = (sint64)( pow( (double)(ir), (double)(ivalue) ) );
00161 }
00162 }
00163 uint64 uir = ir;
00164 if( uir < ilowlimit )
00165 uir = ilowlimit;
00166 if( uir > ihighlimit )
00167 uir = ihighlimit;
00168 char pc[256];
00169 itoaInt64( uir, pc, 10 );
00170 return( CStringEx( pc ) );
00171 }
00172 else
00173 {
00174 uint64 ivalue = atoiInt64( _sxvalue.c_str() );
00175 if( ivalue < ilowlimit )
00176 ivalue = ilowlimit;
00177 if( ivalue > ihighlimit )
00178 ivalue = ihighlimit;
00179 char pc[256];
00180 itoaInt64( ivalue, pc, 10 );
00181 return( CStringEx( pc ) );
00182 }
00183 return( Format( _sxvalue ) );
00184 }
00185
00186 void CTypeUnitIntUnsigned::SetDefaultValue( const CStringEx _sxdv )
00187 {
00188 sxdefaultvalue = _sxdv;
00189 idefaultvalue = atoiInt64( sxdefaultvalue.c_str() );
00190 }
00191
00192 void CTypeUnitIntUnsigned::SetLowLimit( const CStringEx _sxll )
00193 {
00194 sxlowlimit = _sxll;
00195 ilowlimit = atoiInt64( sxlowlimit.c_str() );
00196 }
00197
00198 void CTypeUnitIntUnsigned::SetHighLimit( const CStringEx _sxhl )
00199 {
00200 sxhighlimit = _sxhl;
00201 ihighlimit = atoiInt64( sxhighlimit.c_str() );
00202 }
00203
00204 }
00205
00206