Skip to content

Commit

Permalink
more cleaning
Browse files Browse the repository at this point in the history
issue #30
  • Loading branch information
MarcAntoine-Arnaud committed Jul 26, 2013
1 parent 532ddff commit 9eeeb29
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 102 deletions.
2 changes: 1 addition & 1 deletion libraries/basicElement/src/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ size_t Element::_lastUniqueId = 0;

Element::Element( EType type )
: _type ( type )
, _status ( eStatusUnknown )
, _uniqueId ( _lastUniqueId++ )
, _status ( eStatusUnknown )
, _subType ( 0 )
, _bigEndianData ( true )
{
Expand Down
7 changes: 3 additions & 4 deletions libraries/basicElement/src/Element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class Element
virtual EStatus checkData() = 0;

// static EType getType( const std::string& type ); // @todo
protected:

private:
std::string _id;
Expand All @@ -95,9 +94,9 @@ class Element

protected:
EStatus _status;
int _subType;
size_t _size;
bool _bigEndianData;
int _subType;
size_t _size;
bool _bigEndianData;
};

}
Expand Down
4 changes: 2 additions & 2 deletions libraries/report/src/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Report::~Report()

void Report::addBasicElement( std::shared_ptr< be::Element > element )
{
//_elementMap.insert( std::make_pair( element->getUniqueId(), element ) );
//_basicElementTree.add( element->getId(), element->getUniqueId() );
_elementMap.insert( std::make_pair( element->getUniqueId(), element ) );
_basicElementTree.add( element->getId(), element->getUniqueId() );
}

std::shared_ptr< be::Element > Report::getBasicElement( const size_t uniqueId )
Expand Down
25 changes: 12 additions & 13 deletions libraries/specReader/src/SpecList/SpecList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void SpecList::initDirectoryPaths()
if( const char* env_options = std::getenv( "QC_SPECS_DIR" ) )
boost::algorithm::split( dirList, env_options, boost::algorithm::is_any_of(" ") );

BOOST_FOREACH( std::string dirPath, dirList )
for( std::string& dirPath : dirList )
addDirectoryPath( dirPath );
}

Expand All @@ -33,27 +33,27 @@ void SpecList::addDirectoryPath( const std::string& directoryPath )
bfs::path path( directoryPath );
try
{
if( !exists( path ) )
if( ! exists( path ) )
throw std::runtime_error( " does not exist" );

if ( !is_directory( path ) )
if( ! is_directory( path ) )
throw std::runtime_error( " is not a directory" );

_directories.push_back( directoryPath );
}
catch( const std::runtime_error& ex )
{
LOG_WARNING( "Init Directory Path: "<< path.string() << ex.what() );
}
catch( const bfs::filesystem_error& ex )
{
LOG_ERROR( "Init Directory Path: " << ex.what() );
}
catch( const std::runtime_error& ex )
{
LOG_ERROR( "Init Directory Path: "<< path.string() << ex.what() );
}
}

void SpecList::addSpecFromDirectories()
{
BOOST_FOREACH( std::string filepath, _directories )
for( std::string& filepath : _directories )
{
LOG_INFO( "Searching specs in path : " << filepath );
bfs::path path( filepath );
Expand All @@ -73,7 +73,6 @@ void SpecList::addSpecification( const Specification& spec )
_specifications.push_back( spec );
}


void SpecList::clearSpecifications()
{
_specifications.clear();
Expand All @@ -84,11 +83,11 @@ void SpecList::clearDirectories()
_directories.clear();
}

Specification SpecList::getSpec( const std::string& specId ) const
Specification SpecList::getSpec( const std::string& specId )
{
try
{
BOOST_FOREACH( Specification spec, _specifications )
for( Specification& spec : _specifications )
{
if( spec.getId() == specId )
return spec;
Expand All @@ -102,9 +101,9 @@ Specification SpecList::getSpec( const std::string& specId ) const
}
}

void SpecList::getSpecList( std::map< std::string, std::string >& specIds ) const
void SpecList::getSpecList( std::map< std::string, std::string >& specIds )
{
BOOST_FOREACH( Specification spec, _specifications )
for( Specification& spec : _specifications )
{
specIds[ spec.getId() ] = spec.getLabel();
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/specReader/src/SpecList/SpecList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class SpecList
void clearSpecifications();
void clearDirectories();

Specification getSpec( const std::string& specId ) const;
void getSpecList( std::map< std::string, std::string >& specIds ) const;
Specification getSpec( const std::string& specId );
void getSpecList( std::map< std::string, std::string >& specIds );

size_t getSpecNumber() const;

Expand Down
50 changes: 25 additions & 25 deletions libraries/specReader/src/SpecNode/SpecNode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "SpecNode.hpp"
#include <boost/foreach.hpp>

#include <specDefinition.hpp>

namespace spec_reader
{

Expand All @@ -15,7 +17,6 @@ SpecNode::~SpecNode()
{
}


std::string SpecNode::getId()
{
return getProperty( kId );
Expand All @@ -36,7 +37,6 @@ std::string SpecNode::getDisplayType()
return getProperty( kDisplayType, "" );
}


std::string SpecNode::getCount()
{
return getProperty( kCount, "" );
Expand All @@ -52,7 +52,6 @@ std::string SpecNode::getGroupSize()
return getProperty( kGroupSize, "" );
}


std::vector< std::string > SpecNode::getValues()
{
std::vector< std::string > values;
Expand All @@ -61,7 +60,7 @@ std::vector< std::string > SpecNode::getValues()
std::string stringValue = _node->second.get< std::string >( kValues );
if( stringValue.empty() )
{
BOOST_FOREACH( const bpt::ptree::value_type& value, valuesNode.get( ) )
for( const bpt::ptree::value_type& value : valuesNode.get( ) )
values.push_back( value.second.get_value< std::string >() );
}
else
Expand All @@ -77,16 +76,17 @@ std::vector< std::pair< std::string, std::string > > SpecNode::getRange()
std::vector< std::pair< std::string, std::string > > ranges;
if( boost::optional< const bpt::ptree& > rangeNode = _node->second.get_child_optional( kRange ) )
{
BOOST_FOREACH( const bpt::ptree::value_type& r, rangeNode.get() )
for( const bpt::ptree::value_type& rangeElement : rangeNode.get() )
{
std::pair< std::string, std::string > range;
if( r.second.get_child_optional( kMin ) )
range.first = r.second.get< std::string >( kMin );
std::pair< std::string, std::string > range { "", "" };
if( rangeElement.second.get_child_optional( kMin ) )
range.first = rangeElement.second.get< std::string >( kMin );

if( r.second.get_child_optional( kMax ) )
range.second = r.second.get< std::string >( kMax );
if( rangeElement.second.get_child_optional( kMax ) )
range.second = rangeElement.second.get< std::string >( kMax );

ranges.push_back( range );
if( range.first != "" || range.second != "" )
ranges.push_back( range );
}
}
return ranges;
Expand All @@ -98,32 +98,30 @@ std::vector< std::pair< std::string, std::string > > SpecNode::getRepetition()
if( boost::optional< const bpt::ptree& > repetitionNode = _node->second.get_child_optional( kRepetition ) )
{
std::string repetitionExpr = _node->second.get< std::string >( kRepetition );
if( !repetitionExpr.empty() )
if( ! repetitionExpr.empty() )
{
LOG_TRACE( " --- CASE EXPRESSION --- " );
std::pair< std::string, std::string > repetition;
repetition.first = repetitionExpr;
repetition.second = repetitionExpr;
repetitions.push_back( repetition );
}
else
{
LOG_TRACE( " --- CASE MULTIPLE --- " );
BOOST_FOREACH( const bpt::ptree::value_type& r, repetitionNode.get() )
for( const bpt::ptree::value_type& repetitionElement : repetitionNode.get() )
{
std::pair< std::string, std::string > repetition;
if( !r.second.get_child_optional( kMin ) && !r.second.get_child_optional( kMax ) )
std::pair< std::string, std::string > repetition { "", "" };
if( ! repetitionElement.second.get_child_optional( kMin ) && ! repetitionElement.second.get_child_optional( kMax ) )
{
std::string repetitionExpr = r.second.data();
std::string repetitionExpr = repetitionElement.second.data();
repetition.first = repetitionExpr;
repetition.second = repetitionExpr;
}

if( r.second.get_child_optional( kMin ) )
repetition.first = r.second.get< std::string >( kMin );
if( repetitionElement.second.get_child_optional( kMin ) )
repetition.first = repetitionElement.second.get< std::string >( kMin );

if( r.second.get_child_optional( kMax ) )
repetition.second = r.second.get< std::string >( kMax );
if( repetitionElement.second.get_child_optional( kMax ) )
repetition.second = repetitionElement.second.get< std::string >( kMax );

repetitions.push_back( repetition );
}
Expand All @@ -135,12 +133,13 @@ std::vector< std::pair< std::string, std::string > > SpecNode::getRepetition()
std::map< std::string, std::string > SpecNode::getMap()
{
std::map< std::string, std::string > map;

if( boost::optional< const bpt::ptree& > mapNode = _node->second.get_child_optional( kMap ) )
{
BOOST_FOREACH( const bpt::ptree::value_type& m, mapNode.get() )
for( const bpt::ptree::value_type& mapElements : mapNode.get() )
{
std::string index = m.second.ordered_begin()->first;
map[ index ] = m.second.get< std::string >( index );
std::string index = mapElements.second.ordered_begin()->first;
map[ index ] = mapElements.second.get< std::string >( index );
}
}
return map;
Expand Down Expand Up @@ -174,6 +173,7 @@ SpecNode SpecNode::next()

if( _index >= _indexTotal - 1 )
return SpecNode( node, _indexTotal, _indexTotal );

return SpecNode( ++node, ++index, _indexTotal );
}

Expand Down
34 changes: 0 additions & 34 deletions libraries/specReader/src/SpecNode/SpecNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,6 @@

namespace bpt = boost::property_tree;

const std::string kId = "id";
const std::string kLabel = "label";

const std::string kAscii = "ascii";
const std::string kHexa = "hexa";
const std::string kType = "type";
const std::string kCount = "count";
const std::string kValues = "values";
const std::string kMap = "map";
const std::string kRange = "range";
const std::string kMin = "min";
const std::string kMax = "max";

const std::string kGroup = "group";
const std::string kGroupSize = "groupSize";

const std::string kRepetition = "repeated";
const std::string kRequired = "required";

const std::string kEndian = "endian";
const std::string kEndianBig = "big";
const std::string kEndianLittle = "little";

const std::string kOptional = "optional";
const std::string kOptionalTrue = "true";
const std::string kOptionalFalse = "false";

const std::string kOrdered = "ordered";
const std::string kOrderedTrue = "true";
const std::string kOrderedFalse = "false";

const std::string kData = "data";
const std::string kDisplayType = "displayType";

namespace spec_reader
{

Expand Down
11 changes: 3 additions & 8 deletions libraries/specReader/src/Specification/Specification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
#include <boost/foreach.hpp>
#include <boost/filesystem.hpp>

namespace bfs = boost::filesystem;
#include <specDefinition.hpp>

const std::string kExtension = "extension";
const std::string kFooter = "footer";
const std::string kHeader = "header";
const std::string kStandard = "standard";
namespace bfs = boost::filesystem;

namespace spec_reader
{
Expand Down Expand Up @@ -40,7 +37,6 @@ bool Specification::setFromFile( const std::string& filepath )
if ( path.extension() != ".json" )
throw std::runtime_error( " - Invalid extension: '.json' expected" );

LOG_TRACE( path.string() << ": Reading JSON..." );
bpt::read_json( path.string(), _specTree );
return true;
}
Expand All @@ -60,7 +56,6 @@ void Specification::setFromString( const std::string& string )
std::istringstream isstream( string );
try
{
LOG_TRACE( "Reading JSON..." );
bpt::read_json( isstream, _specTree );
}
catch( const std::exception& ex )
Expand Down Expand Up @@ -115,7 +110,7 @@ std::vector< std::string > Specification::getSupportedExtensions( )
try
{
std::vector< std::string > list;
BOOST_FOREACH( bpt::ptree::value_type &node, _specTree.get_child( kStandard + "." + kExtension ) )
for( bpt::ptree::value_type& node : _specTree.get_child( kStandard + "." + kExtension ) )
{
list.push_back( node.second.data() );
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/specReader/src/Specification/Specification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Specification
Specification();
~Specification();

void setFromTree ( const bpt::ptree& spec );
void setFromTree ( const bpt::ptree& spec );
bool setFromFile ( const std::string& filepath );
void setFromString( const std::string& string );

Expand Down
Loading

0 comments on commit 9eeeb29

Please sign in to comment.