Skip to content

Commit

Permalink
add clean and doc in Comparator
Browse files Browse the repository at this point in the history
issue #31
  • Loading branch information
Valentin Noel committed Dec 2, 2013
1 parent b0024cc commit 8ec42ab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
49 changes: 20 additions & 29 deletions libraries/Comparator/src/Comparator/Comparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ void Comparator::check( spec_reader::Specification& spec, file_reader::FileReade
element->set( buffer1, size );

checker.check( element );
LOG_TRACE( "[comparator] checked :" << element->_id << ": " << statusMap.at( element->_status ) << " | display type = " << element->_dispValue );
LOG_TRACE( "[comparator] checked:" << element->_id << " = " << element->_dispValue << " (" << statusMap.at( element->_status ) << ")" );

std::shared_ptr< basic_element::Element > parent;
parent = getNextParent( element, node );
report.add( element );

while( ( node = element->next() ) != nullptr && ! file.isEndOfFile() ) // if end of specification : stop
while( ( node = element->next() ) != nullptr && ! file.isEndOfFile() )
{
ShPtrElement previous = element;
switch( element->_status )
Expand All @@ -61,7 +61,7 @@ void Comparator::check( spec_reader::Specification& spec, file_reader::FileReade

if( size > ( file.getLength() - file.getPosition() ) && ( isInUnorderedGroup( element ) || element->_isOptional ) )
{
LOG_TRACE( ">>> [comparator] Critical remaining file data size: " << size << "/" << file.getLength() - file.getPosition() );
LOG_TRACE( "[comparator] Critical remaining file data size: " << size << "/" << file.getLength() - file.getPosition() );
size = file.getLength() - file.getPosition();
}

Expand All @@ -71,14 +71,22 @@ void Comparator::check( spec_reader::Specification& spec, file_reader::FileReade
element->set( buffer, size );

checker.check( element );
LOG_TRACE( "[comparator] checked : " << element->_id << " @ " << element << " << Previous: " << previous << " << Parent: " << parent << " - " << statusMap.at( element->_status ) << " | " << element->_dispValue );
LOG_TRACE( "[comparator] checked: " << element->_id << " = " << element->_dispValue << " (" << statusMap.at( element->_status ) << ") @ " << element << " << Previous: " << previous << " << Parent: " << parent );

checkGroupSize( element, file );

report.add( element );
report.update( parent );
parent = getNextParent( element, node );

if( parent != nullptr )
{
LOG_TRACE( "[comparator] next parent: id = " << parent->_id );
}
else
LOG_TRACE( "[comparator] next parent: null" );
}

if( ! file.isEndOfFile() )
LOG_WARNING( "Did not reach the end of file, remaining " << file.getLength() - file.getPosition() << " bytes." );
}
Expand All @@ -98,37 +106,21 @@ Comparator::ShPtrElement Comparator::getNextParent( const ShPtrElement element,
{
ShPtrElement parent = element->getParent();
bool isLastInGroup = ( node->next() == nullptr && ( parent == nullptr || ( parent->_isOrdered || ( ! parent->_isOrdered && element->_status == eStatusInvalidButSkip ) ) ) );
bool isNotSkipped = ( element->_status != eStatusInvalidButOptional && element->_status != eStatusInvalidButSkip && element->_status != eStatusInvalidForIteration );

if( element->_isGroup
&& ! element->_checkedGroup
&& element->_status != eStatusInvalidButOptional
&& element->_status != eStatusInvalidButSkip
&& element->_status != eStatusInvalidForIteration )
{
LOG_TRACE( "[comparator] return parent: current element (id = " << element->_id << ")" );
parent = element;
}
else if( isLastInGroup && element->getParent() != nullptr )
if( element->_isGroup && ! element->_checkedGroup && isNotSkipped )
return element;

if( isLastInGroup && element->getParent() != nullptr )
{
parent = element->getParent();
while( parent->getSpecNode()->next() == nullptr && parent->getParent() != nullptr )
{
parent = parent->getParent();
}
parent = parent->getParent();
}
else
{
parent = element->getParent();
}

if( parent != nullptr )
{
LOG_TRACE( "[comparator] return parent: id = " << parent->_id );
return parent->getParent();
}
else
LOG_TRACE( "[comparator] return a null parent" );
return parent;
return element->getParent();
}

void Comparator::checkGroupSize( const ShPtrElement element, file_reader::FileReader& file )
Expand All @@ -146,7 +138,6 @@ void Comparator::checkGroupSize( const ShPtrElement element, file_reader::FileRe
if( previous->_id == parent->_id )
break;
groupSize += previous->_size;
std::string prevStr = previous->_id; // @todelete!
previous = previous->getPrevious();
}

Expand All @@ -166,7 +157,7 @@ void Comparator::checkGroupSize( const ShPtrElement element, file_reader::FileRe
warningMessage << "[comparator] Group size difference: " << abs( sizeDiff ) << " unexpected bytes ";
parent->_warning += warningMessage.str();
file.goForward( abs( sizeDiff ) );
LOG_WARNING( warningMessage.str() << "go forward..." );
LOG_WARNING( warningMessage.str() << ": go forward..." );
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions libraries/Comparator/src/Comparator/Comparator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,26 @@ namespace report_generator
namespace comparator
{

/**
* Comparator, check orchestrator.
*/
class Comparator
{
typedef std::shared_ptr< basic_element::Element > ShPtrElement;
typedef std::shared_ptr< spec_reader::SpecNode > ShPtrSpecNode;

public:
/**
* Comparator's constructor.
*/
Comparator();

/**
* Compare an input file to a specification, and write a report.
* @param spec Specification used as the comparison reference.
* @param reader FileReader, to extract raw data from the file checked.
* @param report Report to fill, and print or write.
*/
void check( spec_reader::Specification& spec, file_reader::FileReader& reader, report_generator::Report& report );

private:
Expand Down

0 comments on commit 8ec42ab

Please sign in to comment.