Skip to content

Commit

Permalink
add report type support, toXml method, and other minor modifications …
Browse files Browse the repository at this point in the history
…to Transform class

issue #30
  • Loading branch information
Valentin Noel committed Jul 31, 2013
1 parent 477c56e commit afb9fbb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
20 changes: 14 additions & 6 deletions libraries/report/src/Transform/Transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,32 @@ namespace report_generator
class Transform
{
public:
enum EReportType
{
eReportTypeXml = 0,
eReportTypeJson
};

Transform();
Transform( const Report& report );
~Transform();

void setBasicElementReport( const Report& report );

void transform();
void transformTree( const EReportType& type );

protected:
bpt::ptree translate( ReportTree::value_type& rootNode );
void extractElement( std::shared_ptr< be::Element > element );

bpt::ptree extractElement( std::shared_ptr< be::Element > element );

bpt::ptree toXml( std::vector< std::pair< std::string, std::string > > elementInfo );

template < typename ElementType >
std::shared_ptr< ElementType > translateElement( std::shared_ptr< be::Element > element );

private:
ReportTree _basicElementTree;
bpt::ptree _report;
ReportTree _basicElementTree;
bpt::ptree _report;
EReportType _type;
};

}
Expand Down
52 changes: 38 additions & 14 deletions libraries/report/src/Transform/Transform.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ void Transform::setBasicElementReport( const Report& report )
_basicElementTree = report.getReportTree();
}

void Transform::transform()
void Transform::transformTree( const EReportType& type )
{
_type = type;
for( ReportTree::value_type& rootNode : _basicElementTree.get_child( kReport ) )
{
LOG_INFO( "--> root node :" );
Expand All @@ -40,15 +41,24 @@ bpt::ptree Transform::translate( ReportTree::value_type& elementNode )
{
LOG_INFO( pair.first );
if( pair.first != kGroup )
{
extractElement( pair.second.data() );
}
else
{
for( ReportTree::value_type& elem : pair.second )
node.add_child( kGroup + ".", translate( elem ) );
}
}

return node;
}

void Transform::extractElement( std::shared_ptr< be::Element > element )
bpt::ptree Transform::extractElement( std::shared_ptr< be::Element > element )
{
LOG_INFO( "be::Element::eType: " << element->getType() );
bpt::ptree node;
std::vector< std::pair< std::string, std::string > > elemInfo;
switch( element->getType() )
{
case be::Element::eTypeUnknown : LOG_WARNING( "Element " << element->getUniqueId() << ": unknown type." ); break;
Expand All @@ -59,26 +69,40 @@ void Transform::extractElement( std::shared_ptr< be::Element > element )
switch( element->getNumberSubType() )
{
case be::Element::eNumberTypeUnknown : LOG_WARNING( "Number " << element->getUniqueId() << ": unknown type." ); break;
case be::Element::eNumberTypeInt8 : translateElement< ben::Number< ben::int8 > >( element ); break;
case be::Element::eNumberTypeUInt8 : translateElement< ben::Number< ben::uint8 > >( element ); break;
case be::Element::eNumberTypeInt16 : translateElement< ben::Number< ben::int16 > >( element ); break;
case be::Element::eNumberTypeUInt16 : translateElement< ben::Number< ben::uint16 > >( element ); break;
case be::Element::eNumberTypeInt32 : translateElement< ben::Number< ben::int32 > >( element ); break;
case be::Element::eNumberTypeUInt32 : translateElement< ben::Number< ben::uint32 > >( element ); break;
case be::Element::eNumberTypeInt64 : translateElement< ben::Number< ben::int64 > >( element ); break;
case be::Element::eNumberTypeUInt64 : translateElement< ben::Number< ben::uint64 > >( element ); break;
case be::Element::eNumberTypeFloat : translateElement< ben::Number< float > >( element ); break;
case be::Element::eNumberTypeDouble : translateElement< ben::Number< double > >( element ); break;
case be::Element::eNumberTypeIeeeExtended : translateElement< ben::Number< ben::ieeeExtended > >( element ); break;
case be::Element::eNumberTypeInt8 : elemInfo = translateElement< ben::Number< ben::int8 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeUInt8 : elemInfo = translateElement< ben::Number< ben::uint8 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeInt16 : elemInfo = translateElement< ben::Number< ben::int16 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeUInt16 : elemInfo = translateElement< ben::Number< ben::uint16 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeInt32 : elemInfo = translateElement< ben::Number< ben::int32 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeUInt32 : elemInfo = translateElement< ben::Number< ben::uint32 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeInt64 : elemInfo = translateElement< ben::Number< ben::int64 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeUInt64 : elemInfo = translateElement< ben::Number< ben::uint64 > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeFloat : elemInfo = translateElement< ben::Number< float > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeDouble : elemInfo = translateElement< ben::Number< double > >( element )->getElementInfo(); break;
case be::Element::eNumberTypeIeeeExtended : elemInfo = translateElement< ben::Number< ben::ieeeExtended > >( element )->getElementInfo(); break;
}
} break;

case be::Element::eTypeExif : LOG_INFO( "Exif !"); break;
case be::Element::eTypeData : translateElement< bed::Data >( element ); break;
case be::Element::eTypeData : elemInfo = translateElement< bed::Data >( element )->getElementInfo(); break;
case be::Element::eTypeKlv : LOG_INFO( "Klv !"); break;
}

switch( _type )
{
case eReportTypeXml : node = toXml( elemInfo ); break;
case eReportTypeJson : LOG_WARNING( "Json report not available yet." ); break;
}
return node;
}

bpt::ptree Transform::toXml( std::vector< std::pair< std::string, std::string > > elementInfo )
{
bpt::ptree xmlNode;
for( std::pair< std::string, std::string >& pair : elementInfo )
LOG_INFO( pair.first << " : " << pair.second ); // @todo: make the xml node !
return xmlNode;
}

template < typename ElementType >
std::shared_ptr< ElementType > Transform::translateElement( std::shared_ptr< be::Element > element )
Expand Down
4 changes: 2 additions & 2 deletions libraries/report/tests/transformTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ BOOST_AUTO_TEST_CASE( report_transform )
{
LOG_INFO( ">>> report_transform_transform <<<" );
Transform tr( elementReport );
tr.transform();
tr.transformTree( Transform::eReportTypeXml );
}

}

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit afb9fbb

Please sign in to comment.