Skip to content

Commit

Permalink
add minor modifications for const methods in SpecNode (and clean)
Browse files Browse the repository at this point in the history
issue #31
  • Loading branch information
Valentin Noel committed Aug 5, 2013
1 parent 440d8cc commit 7e96861
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
3 changes: 3 additions & 0 deletions libraries/specReader/src/SpecList/SpecList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ void SpecList::initDirectoryPaths()
std::vector< std::string > dirList;
if( const char* env_options = std::getenv( "QC_SPECS_DIR" ) )
boost::algorithm::split( dirList, env_options, boost::algorithm::is_any_of(" ") );

if( dirList.size() == 0 )
LOG_WARNING( "initDirectoryPaths: No specification file found.");

for( std::string& dirPath : dirList )
addDirectoryPath( dirPath );
Expand Down
49 changes: 23 additions & 26 deletions libraries/specReader/src/SpecNode/SpecNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@
namespace spec_reader
{

SpecNode::SpecNode( const bpt::ptree::const_iterator node, const size_t& index, const size_t& indexTotal )
: _node( node )
, _parent( NULL )
, _index( index )
, _indexTotal( indexTotal )
{
}

SpecNode::SpecNode( const bpt::ptree::const_iterator node, const size_t& index, const size_t& indexTotal, SpecNode* parent )
SpecNode::SpecNode( const bpt::ptree::const_iterator node, const size_t& index, const size_t& indexTotal, const SpecNode* parent )
: _node( node )
, _parent( parent )
, _index( index )
Expand All @@ -26,22 +18,22 @@ SpecNode::~SpecNode()
{
}

std::string SpecNode::getId()
std::string SpecNode::getId() const
{
return getProperty( kId );
}

std::string SpecNode::getLabel()
std::string SpecNode::getLabel() const
{
return getProperty( kLabel );
}

std::string SpecNode::getType()
std::string SpecNode::getType() const
{
return getProperty( kType );
}

std::string SpecNode::getDisplayType()
std::string SpecNode::getDisplayType() const
{
return getProperty( kDisplayType, "" );
}
Expand Down Expand Up @@ -155,27 +147,27 @@ std::map< std::string, std::string > SpecNode::getMap()
}


bool SpecNode::isBigEndian()
bool SpecNode::isBigEndian() const
{
return ( getProperty( kEndian, kEndianBig ) == kEndianBig );
}

bool SpecNode::isOptional()
bool SpecNode::isOptional() const
{
return ( getProperty( kOptional, kOptionalFalse ) == kOptionalTrue );
return ( getProperty( kOptional, kFalse ) == kTrue );
}

bool SpecNode::isOrdered()
bool SpecNode::isOrdered() const
{
return ( getProperty( kOrdered, kOrderedTrue ) == kOrderedTrue );
return ( getProperty( kOrdered, kTrue ) == kTrue );
}

bool SpecNode::hasGroup()
bool SpecNode::hasGroup() const
{
return _node->second.get_child_optional( kGroup );
}

SpecNode SpecNode::next()
SpecNode SpecNode::next() const
{
bpt::ptree::const_iterator node = _node;
size_t index = _index;
Expand All @@ -186,7 +178,7 @@ SpecNode SpecNode::next()
return SpecNode( ++node, ++index, _indexTotal );
}

SpecNode SpecNode::firstChild()
SpecNode SpecNode::firstChild() const
{
try
{
Expand All @@ -207,7 +199,7 @@ SpecNode* SpecNode::parent()
{
if( _parent == NULL )
throw std::runtime_error( "parent: This node has no parent." );
return _parent;
return const_cast< SpecNode*>( _parent );
}
catch( std::runtime_error& e )
{
Expand All @@ -216,18 +208,23 @@ SpecNode* SpecNode::parent()
}
}

size_t SpecNode::getIndex()
bool SpecNode::isLastNode() const
{
return ( _index == _indexTotal - 1 );
}

size_t SpecNode::getIndex() //@todo Delete !!!!
{
return _index;
}

size_t SpecNode::getIndexTotal()
size_t SpecNode::getIndexTotal() //@todo Delete !!!!
{
return _indexTotal;
}


std::string SpecNode::getProperty( const std::string& prop )
std::string SpecNode::getProperty( const std::string& prop ) const
{
try
{
Expand All @@ -240,7 +237,7 @@ std::string SpecNode::getProperty( const std::string& prop )
}
}

std::string SpecNode::getProperty( const std::string& prop, const std::string& defaultValue )
std::string SpecNode::getProperty( const std::string& prop, const std::string& defaultValue ) const
{
return _node->second.get< std::string >( prop, defaultValue );
}
Expand Down
35 changes: 18 additions & 17 deletions libraries/specReader/src/SpecNode/SpecNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ class SpecNode
{
public:

SpecNode( const bpt::ptree::const_iterator node, const size_t& index, const size_t& indexTotal );
SpecNode( const bpt::ptree::const_iterator node, const size_t& index, const size_t& indexTotal, SpecNode* parent );
SpecNode( const bpt::ptree::const_iterator node, const size_t& index, const size_t& indexTotal, const SpecNode* parent = NULL );
~SpecNode();

std::string getId();
std::string getLabel();
std::string getType();
std::string getDisplayType();
std::string getId() const;
std::string getLabel() const;
std::string getType() const;
std::string getDisplayType() const;

std::string getCount();
std::string getRequired();
Expand All @@ -33,27 +32,29 @@ class SpecNode

std::map< std::string, std::string > getMap();

bool isBigEndian();
bool isOptional();
bool isOrdered();
bool isBigEndian() const;
bool isOptional() const;
bool isOrdered() const;

bool hasGroup();
bool hasGroup() const;
std::string getGroupSize();

SpecNode next();
SpecNode firstChild();
SpecNode next() const;
SpecNode firstChild() const;
SpecNode* parent();

size_t getIndex();
size_t getIndexTotal();
bool isLastNode() const;

size_t getIndex(); //@todo Delete !!!!
size_t getIndexTotal(); //@todo Delete !!!!

protected:
std::string getProperty( const std::string& prop );
std::string getProperty( const std::string& prop, const std::string& defaultValue );
std::string getProperty( const std::string& prop ) const;
std::string getProperty( const std::string& prop, const std::string& defaultValue ) const;

private:
bpt::ptree::const_iterator _node;
SpecNode* _parent;
const SpecNode* _parent;
size_t _index;
size_t _indexTotal;
};
Expand Down

0 comments on commit 7e96861

Please sign in to comment.