From 7c369dec36cfd03208848af1884a4d89fa4c1f16 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sun, 3 Nov 2019 00:20:33 +0100 Subject: [PATCH] some more cppcheck issues --- .../generate/RandomTreeAutomatonFactory.h | 5 ++--- alib2algo/src/regexp/glushkov/GlushkovFollow.h | 11 +++++++---- alib2algo/src/regexp/glushkov/GlushkovPos.h | 16 ++++++---------- alib2algo/src/regexp/properties/RegExpEmpty.h | 18 ++++++------------ .../src/regexp/properties/RegExpEpsilon.h | 16 ++++++---------- alib2algo/src/rte/glushkov/GlushkovPos.h | 8 +++----- .../registry/XmlContainerParserRegistry.cpp | 11 +++++++---- 7 files changed, 37 insertions(+), 48 deletions(-) diff --git a/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h b/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h index 2b2eb7e694..5620dd7809 100644 --- a/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h +++ b/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h @@ -131,7 +131,6 @@ automaton::NFTA < SymbolType, unsigned > RandomTreeAutomatonFactory::LeslieConne ext::deque<bool> VStates; ext::deque<unsigned> Q; - size_t unvisited; automaton::NFTA < SymbolType, unsigned > automaton; @@ -149,16 +148,16 @@ automaton::NFTA < SymbolType, unsigned > RandomTreeAutomatonFactory::LeslieConne } else if( n == 1 ) { automaton.addTransition( nullaryAlphabet[ ext::random_devices::semirandom() % nullaryAlphabet.size( ) ], ext::vector < unsigned > { }, Q[ 0 ] ); - unvisited = 0; VStates[ 0 ] = true; } else { unsigned x = ext::random_devices::semirandom() % n; automaton.addTransition( nullaryAlphabet[ ext::random_devices::semirandom() % nullaryAlphabet.size( ) ], ext::vector < unsigned > { }, Q[ x ] ); - unvisited = n - 1; VStates[ x ] = true; } + size_t unvisited = n - 1; + while( unvisited != 0 ) { int c = ext::random_devices::semirandom() % alphabet.size( ); ext::vector < unsigned > from; diff --git a/alib2algo/src/regexp/glushkov/GlushkovFollow.h b/alib2algo/src/regexp/glushkov/GlushkovFollow.h index d75fc63850..85af764979 100644 --- a/alib2algo/src/regexp/glushkov/GlushkovFollow.h +++ b/alib2algo/src/regexp/glushkov/GlushkovFollow.h @@ -82,11 +82,14 @@ ext::set < UnboundedRegExpSymbol < SymbolType > > GlushkovFollow::follow ( const template < class SymbolType > ext::set < regexp::UnboundedRegExpSymbol < SymbolType > > GlushkovFollow::Unbounded < SymbolType >::visit ( const regexp::UnboundedRegExpAlternation < SymbolType > & node, const regexp::UnboundedRegExpSymbol < SymbolType > & symbolptr ) { - for ( const UnboundedRegExpElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbolptr ) ) - return element.template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbolptr ); + auto iter = std::find_if ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbolptr ); + } ); - throw exception::CommonException ( "GlushkovFollow::Unbounded < SymbolType >::visit(Alt)" ); + if ( iter == node.getElements ( ).end ( ) ) + throw exception::CommonException ( "GlushkovFollow::Unbounded < SymbolType >::visit(Alt)" ); + + return iter->template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbolptr ); } template < class SymbolType > diff --git a/alib2algo/src/regexp/glushkov/GlushkovPos.h b/alib2algo/src/regexp/glushkov/GlushkovPos.h index 127bc4ed74..d319818af7 100644 --- a/alib2algo/src/regexp/glushkov/GlushkovPos.h +++ b/alib2algo/src/regexp/glushkov/GlushkovPos.h @@ -52,20 +52,16 @@ bool GlushkovPos::pos ( const UnboundedRegExpSymbol < SymbolType > & symbol, con template < class SymbolType > bool GlushkovPos::Unbounded < SymbolType >::visit ( const regexp::UnboundedRegExpAlternation < SymbolType > & node, const regexp::UnboundedRegExpSymbol < SymbolType > & symbol ) { - for ( const UnboundedRegExpElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ) ) - return true; - - return false; + return std::any_of ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ); + } ); } template < class SymbolType > bool GlushkovPos::Unbounded < SymbolType >::visit ( const regexp::UnboundedRegExpConcatenation < SymbolType > & node, const regexp::UnboundedRegExpSymbol < SymbolType > & symbol ) { - for ( const UnboundedRegExpElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ) ) - return true; - - return false; + return std::any_of ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ); + } ); } template < class SymbolType > diff --git a/alib2algo/src/regexp/properties/RegExpEmpty.h b/alib2algo/src/regexp/properties/RegExpEmpty.h index d10f297836..4dc3befb38 100644 --- a/alib2algo/src/regexp/properties/RegExpEmpty.h +++ b/alib2algo/src/regexp/properties/RegExpEmpty.h @@ -127,22 +127,16 @@ bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExp < SymbolType > & template < class SymbolType > bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation) { - for(const UnboundedRegExpElement < SymbolType > & element : alternation.getElements()) { - if(! element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ) ) { - return false; - } - } - return true; + return std::all_of ( alternation.getElements ( ).begin ( ), alternation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation) { - for(const UnboundedRegExpElement < SymbolType > & element : concatenation.getElements()) { - if( element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ) ) { - return true; - } - } - return false; + return std::any_of ( concatenation.getElements ( ).begin ( ), concatenation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > diff --git a/alib2algo/src/regexp/properties/RegExpEpsilon.h b/alib2algo/src/regexp/properties/RegExpEpsilon.h index a5852a74fd..6addca6b35 100644 --- a/alib2algo/src/regexp/properties/RegExpEpsilon.h +++ b/alib2algo/src/regexp/properties/RegExpEpsilon.h @@ -126,20 +126,16 @@ bool RegExpEpsilon::languageContainsEpsilon(const regexp::UnboundedRegExp < Symb template < class SymbolType > bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation) { - for ( const UnboundedRegExpElement < SymbolType > & element : alternation.getElements ( ) ) - if ( element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ) ) - return true; - - return false; + return std::any_of ( alternation.getElements ( ).begin ( ), alternation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation) { - for ( const UnboundedRegExpElement < SymbolType > & element : concatenation.getElements ( ) ) - if ( ! element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ) ) - return false; - - return true; + return std::all_of ( concatenation.getElements ( ).begin ( ), concatenation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > diff --git a/alib2algo/src/rte/glushkov/GlushkovPos.h b/alib2algo/src/rte/glushkov/GlushkovPos.h index ddfbc8ea96..ebec88cd4c 100644 --- a/alib2algo/src/rte/glushkov/GlushkovPos.h +++ b/alib2algo/src/rte/glushkov/GlushkovPos.h @@ -59,11 +59,9 @@ template < class SymbolType > bool GlushkovPos::Formal < SymbolType >::visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, const common::ranked_symbol < SymbolType > & symbolF ) { if ( symbolF == node.getSymbol ( ) ) return true; - for ( const rte::FormalRTEElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Formal < SymbolType > > ( symbolF ) ) - return true; - - return false; + return std::any_of ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const rte::FormalRTEElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Formal < SymbolType > > ( symbolF ); + } ); } template < class SymbolType > diff --git a/alib2xml/src/registry/XmlContainerParserRegistry.cpp b/alib2xml/src/registry/XmlContainerParserRegistry.cpp index 5d069679ad..7a196b6db4 100644 --- a/alib2xml/src/registry/XmlContainerParserRegistry.cpp +++ b/alib2xml/src/registry/XmlContainerParserRegistry.cpp @@ -53,11 +53,14 @@ std::shared_ptr < abstraction::OperationAbstraction > XmlContainerParserRegistry if ( group == getEntries ( ).end ( ) ) throw exception::CommonException ( "Entry " + container + " not available" ); - for ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry : group->second ) - if ( ext::is_same_type ( type, ext::erase_template_info ( entry.first ) ) ) - return entry.second->getAbstraction ( ); + auto iter = std::find_if ( group->second.begin ( ), group->second.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry ) { + return ext::is_same_type ( type, ext::erase_template_info ( entry.first ) ); + } ); + + if ( iter == group->second.end ( ) ) + throw exception::CommonException ( "Entry for " + container + " parametrized with " + type + " not available." ); - throw exception::CommonException ( "Entry for " + container + " parametrized with " + type + " not available." ); + return iter->second->getAbstraction ( ); } ext::set < std::string > XmlContainerParserRegistry::listOverloads ( const std::string & container ) { -- GitLab