Skip to content

Commit

Permalink
add first version of Checker check() method
Browse files Browse the repository at this point in the history
issue #33
  • Loading branch information
Valentin Noel committed Oct 22, 2013
1 parent 7550d33 commit 36a8567
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
103 changes: 101 additions & 2 deletions libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

#include "Checker.hpp"

#include <Common/log.hpp>
#include <BasicElement/SubElements/Data.hpp>
#include <BasicElement/SubElements/Number.hpp>
#include <ElementChecker/Translator/Translator.hpp>

#include <algorithm>

namespace element_checker
{

Expand All @@ -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;
}

}
Expand Down
10 changes: 10 additions & 0 deletions libraries/ElementChecker/src/ElementChecker/Checker/Checker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#include <iostream>
#include <memory>

namespace basic_element
{
class Data;
class Number;
}

namespace element_checker
{

Expand All @@ -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;
};
Expand Down

0 comments on commit 36a8567

Please sign in to comment.