diff --git a/libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp b/libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp index 8635cb6..ff96a50 100644 --- a/libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp +++ b/libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp @@ -1,6 +1,12 @@ - #include "Checker.hpp" +#include +#include +#include +#include + +#include + namespace element_checker { @@ -11,7 +17,100 @@ Checker::Checker( const std::shared_ptr< basic_element::Element > element ) void Checker::check() { - std::cout << _element->getType() << std::cout; + LOG_INFO( _element->getType() ); + + switch( _element->getType() ) + { + case eTypeUnknown : + { + LOG_ERROR( "Unknown element type, cannot check it" ); + _element->setStatus( eStatusInvalid ); + break; + } + case eTypeNumber : + { + std::shared_ptr< basic_element::Number > number = std::static_pointer_cast< basic_element::Number >( _element ); + _element->setStatus( checkNumber( number ) ); + break; + } + case eTypeExif : + { + break; + } + case eTypeData : + { + std::shared_ptr< basic_element::Data > data = std::static_pointer_cast< basic_element::Data >( _element ); + _element->setStatus( checkData( data ) ); + break; + } + case eTypeKlv : + { + break; + } + } + +} + +EStatus Checker::checkData( std::shared_ptr< basic_element::Data > data ) +{ + if( data->getSize() == 0 ) + LOG_WARNING( data->getId() << ": Null data size !" ); + + if( data->getValues().empty() ) + { + return eStatusPassOver; + } + + EStatus status = eStatusInvalid; + switch( data->getSubType() ) + { + case eSubTypeAscii : + case eSubTypeHexa : + { + std::string orig = Translator( data.get() ).get(); + std::string lowCase = orig; + std::string upCase = orig; + std::transform( lowCase.begin(), lowCase.end(), lowCase.begin(), ::tolower ); + std::transform( upCase.begin(), upCase.end(), upCase.begin(), ::toupper ); + + for( std::string value : data->getValues() ) + if( value == orig || value == lowCase || value == upCase ) + status = eStatusValid; + + if( status == eStatusInvalid ) + data->addErrorLabel( "Invalid value" ); + return status; + } + + case eSubTypeRaw : + { + return eStatusPassOver; + } + + case eSubTypeUnknown : + default: + { + data->addErrorLabel( "Invalid subtype" ); + break; + } + } + return status; +} + +EStatus Checker::checkNumber( std::shared_ptr< basic_element::Number > number ) +{ + EStatus status = eStatusInvalid; + + if( number->getRange().empty() ) + { + return eStatusPassOver; + } + + // if( isNumberInRange() ) // @todo + // status = eStatusValid; + + // LOG_TRACE( "status: " << status ); + return status; } } diff --git a/libraries/ElementChecker/src/ElementChecker/Checker/Checker.hpp b/libraries/ElementChecker/src/ElementChecker/Checker/Checker.hpp index 45cab33..3768078 100644 --- a/libraries/ElementChecker/src/ElementChecker/Checker/Checker.hpp +++ b/libraries/ElementChecker/src/ElementChecker/Checker/Checker.hpp @@ -7,6 +7,12 @@ #include #include +namespace basic_element +{ + class Data; + class Number; +} + namespace element_checker { @@ -18,6 +24,10 @@ class Checker void check(); +private: + EStatus checkData ( std::shared_ptr< basic_element::Data > data ); + EStatus checkNumber( std::shared_ptr< basic_element::Number > number ); + private: std::shared_ptr< basic_element::Element > _element; };