----------------------------------------------------------------------------- Convert a decimal string to an integer and report the precision and number of bytes required to store the value. -----------------------------------------------------------------------------
| 655 | // number of bytes required to store the value. |
| 656 | //----------------------------------------------------------------------------- |
| 657 | int32 CommandClass::ValueToInteger |
| 658 | ( |
| 659 | string const& _value, |
| 660 | uint8* o_precision, |
| 661 | uint8* o_size |
| 662 | )const |
| 663 | { |
| 664 | int32 val; |
| 665 | uint8 precision; |
| 666 | |
| 667 | // Find the decimal point |
| 668 | size_t pos = _value.find_first_of( "." ); |
| 669 | if( pos == string::npos ) |
| 670 | pos = _value.find_first_of( "," ); |
| 671 | |
| 672 | if( pos == string::npos ) |
| 673 | { |
| 674 | // No decimal point |
| 675 | precision = 0; |
| 676 | |
| 677 | // Convert the string to an integer |
| 678 | val = atol( _value.c_str() ); |
| 679 | } |
| 680 | else |
| 681 | { |
| 682 | // Remove the decimal point and convert to an integer |
| 683 | precision = (uint8) ((_value.size()-pos)-1); |
| 684 | |
| 685 | string str = _value.substr( 0, pos ) + _value.substr( pos+1 ); |
| 686 | val = atol( str.c_str() ); |
| 687 | } |
| 688 | |
| 689 | uint8_t orp = m_com.GetFlagByte(COMPAT_FLAG_OVERRIDEPRECISION); |
| 690 | if ( orp > 0 ) |
| 691 | { |
| 692 | while ( precision < orp ) { |
| 693 | precision++; |
| 694 | val *= 10; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | if ( o_precision ) *o_precision = precision; |
| 699 | |
| 700 | if( o_size ) |
| 701 | { |
| 702 | // Work out the size as either 1, 2 or 4 bytes |
| 703 | *o_size = 4; |
| 704 | if( val < 0 ) |
| 705 | { |
| 706 | if( ( val & 0xffffff80 ) == 0xffffff80 ) |
| 707 | { |
| 708 | *o_size = 1; |
| 709 | } |
| 710 | else if( ( val & 0xffff8000 ) == 0xffff8000 ) |
| 711 | { |
| 712 | *o_size = 2; |
| 713 | } |
| 714 | } |
nothing calls this directly
no test coverage detected