diff --git a/libraries/basicElement/src/Number/Number.hpp b/libraries/basicElement/src/Number/Number.hpp index 56b1587..bd7563e 100644 --- a/libraries/basicElement/src/Number/Number.hpp +++ b/libraries/basicElement/src/Number/Number.hpp @@ -37,8 +37,9 @@ class Number : public Element void getData ( char* buffer ) const; size_t getSize () const; NumberType getValue() const; - Range< NumberType >& getRange(); Map < NumberType >& getMap (); + void addRange( const NumberType& min, const NumberType& max ); + std::vector< Range< NumberType > >& getRange(); std::string toString() const; @@ -53,9 +54,9 @@ class Number : public Element void setSubType(); private: - Range< NumberType > _range; - Map < NumberType > _map; - NumberData _numData; + std::vector< Range< NumberType > > _ranges; + Map < NumberType > _map; + NumberData _numData; }; diff --git a/libraries/basicElement/src/Number/Number.tcc b/libraries/basicElement/src/Number/Number.tcc index aa69420..b301fce 100644 --- a/libraries/basicElement/src/Number/Number.tcc +++ b/libraries/basicElement/src/Number/Number.tcc @@ -93,11 +93,16 @@ NumberType Number< NumberType >::getValue() const } +template< typename NumberType > +void Number< NumberType >::addRange( const NumberType& min, const NumberType& max ) +{ + _ranges.push_back( Range< NumberType >( min, max ) ); +} template< typename NumberType > -Range< NumberType >& Number< NumberType >::getRange() +std::vector< Range< NumberType > >& Number< NumberType >::getRange() { - return _range; + return _ranges; } template< typename NumberType > @@ -129,14 +134,17 @@ Element::EStatus Number< NumberType >::checkData() { _status = eStatusInvalid; - if( !_range.isSet() ) + if( _ranges.empty() ) { _status = eStatusPassOver; return eStatusPassOver; } - if( _range.isInRange( _numData.value ) ) - _status = eStatusValid; + for( Range< NumberType > range : _ranges ) + { + if( range.isInRange( _numData.value ) ) + _status = eStatusValid; + } return _status; } diff --git a/libraries/basicElement/tests/element/numberTests.hpp b/libraries/basicElement/tests/element/numberTests.hpp index f022ddf..320db1f 100644 --- a/libraries/basicElement/tests/element/numberTests.hpp +++ b/libraries/basicElement/tests/element/numberTests.hpp @@ -92,8 +92,8 @@ BOOST_AUTO_TEST_CASE( basic_element_number ) num.setLabel( label ); BOOST_CHECK_EQUAL( num.getLabel(), label ); - num.getRange().setRange( min, max ); - BOOST_CHECK_EQUAL( num.getRange().isSet(), true ); + num.addRange( min, max ); + BOOST_CHECK_EQUAL( num.getRange().at(0).isSet(), true ); num.getMap().addPair( min, label ); BOOST_CHECK_EQUAL( num.getMap().getLabel(0), label ); @@ -586,16 +586,37 @@ BOOST_AUTO_TEST_CASE( basic_element_number_checkData ) } { nbe::Number< nbe::uint32 > num; - num.getRange().setRange( 254, 256 ); + num.addRange( 254, 256 ); num.setData( dataInt32Low, sizeof( dataInt32High ) ); BOOST_CHECK_EQUAL( num.checkData(), be::Element::eStatusValid ); } { nbe::Number< nbe::uint32 > num; - num.getRange().setRange( 256, 256 ); + num.addRange( 256, 256 ); num.setData( dataInt32Low, sizeof( dataInt32High ) ); BOOST_CHECK_EQUAL( num.checkData(), be::Element::eStatusInvalid ); } + { + nbe::Number< nbe::uint32 > num; + num.addRange( 254, 256 ); + num.addRange( 0, 1 ); + num.setData( dataInt32Low, sizeof( dataInt32High ) ); + BOOST_CHECK_EQUAL( num.checkData(), be::Element::eStatusValid ); + } + { + nbe::Number< nbe::uint32 > num; + num.addRange( 245, 254 ); + num.addRange( 0, 1 ); + num.setData( dataInt32Low, sizeof( dataInt32High ) ); + BOOST_CHECK_EQUAL( num.checkData(), be::Element::eStatusInvalid ); + } + { + nbe::Number< nbe::uint32 > num; + num.addRange( 245, 256 ); + num.addRange( 254, 1000 ); + num.setData( dataInt32Low, sizeof( dataInt32High ) ); + BOOST_CHECK_EQUAL( num.checkData(), be::Element::eStatusValid ); + } { nbe::Number< nbe::ieeeExtended > num; @@ -604,13 +625,13 @@ BOOST_AUTO_TEST_CASE( basic_element_number_checkData ) } { nbe::Number< nbe::ieeeExtended > num; - num.getRange().setRange( 0, 2 ); + num.addRange( 0, 2 ); num.setData( dataIeeeExtendedOneLittleEndian, sizeof( dataIeeeExtendedOneLittleEndian ) ); BOOST_CHECK_EQUAL( num.checkData(), be::Element::eStatusValid ); } { nbe::Number< nbe::ieeeExtended > num; - num.getRange().setRange( 1.5, 3.2 ); + num.addRange( 1.5, 3.2 ); num.setData( dataIeeeExtendedOneLittleEndian, sizeof( dataIeeeExtendedOneLittleEndian ) ); BOOST_CHECK_EQUAL( num.checkData(), be::Element::eStatusInvalid ); }