diff --git a/alib2data/src/automaton/FSM/DFA.cpp b/alib2data/src/automaton/FSM/DFA.cpp index 55873abc4fe9185d601e8bb7a9e9e358e57ad3e7..65773b1e44a56d308c5274e7ec1ffe57c000e714 100644 --- a/alib2data/src/automaton/FSM/DFA.cpp +++ b/alib2data/src/automaton/FSM/DFA.cpp @@ -19,7 +19,7 @@ namespace automaton { -DFA::DFA ( std::set < State > states, std::set < alphabet::Symbol > inputAlphabet, State initialState, std::set < State > finalStates ) : std::Components < DFA, alphabet::Symbol, std::tuple < InputAlphabet >, std::tuple < >, automaton::State, std::tuple < States, FinalStates >, std::tuple < InitialState > > ( std::make_tuple ( std::move ( inputAlphabet ) ), std::tuple < > ( ), std::make_tuple ( std::move ( states ), std::move ( finalStates ) ), std::make_tuple ( std::move ( initialState ) ) ) { +DFA::DFA ( std::set < State > states, std::set < alphabet::Symbol > inputAlphabet, State initialState, std::set < State > finalStates ) : std::Components2 < DFA, alphabet::Symbol, std::tuple < InputAlphabet >, std::tuple < >, automaton::State, std::tuple < States, FinalStates >, std::tuple < InitialState > > ( std::make_tuple ( std::move ( inputAlphabet ) ), std::tuple < > ( ), std::make_tuple ( std::move ( states ), std::move ( finalStates ) ), std::make_tuple ( std::move ( initialState ) ) ) { } DFA::DFA ( State initialState ) : DFA ( std::set < State > { initialState }, std::set < alphabet::Symbol > { }, initialState, std::set < State > { } ) { @@ -191,77 +191,74 @@ void DFA::composeTransitions ( std::deque < sax::Token > & out ) const { namespace std { template < > -bool automaton::DFA::Component < automaton::DFA, alphabet::Symbol, automaton::InputAlphabet >::used ( const alphabet::Symbol & symbol ) const { - const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); +class ComponentConstraint2< automaton::DFA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::DFA & automaton, const alphabet::Symbol & symbol ) { + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & transition : automaton.getTransitions ( ) ) + if ( transition.first.second == symbol ) + return true; - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & transition : automaton->getTransitions ( ) ) - if ( transition.first.second == symbol ) - return true; - - return false; -} + return false; + } -template < > -bool automaton::DFA::Component < automaton::DFA, alphabet::Symbol, automaton::InputAlphabet >::available ( const alphabet::Symbol & ) const { - return true; -} + static bool available ( const automaton::DFA &, const alphabet::Symbol & ) { + return true; + } -template < > -void automaton::DFA::Component < automaton::DFA, alphabet::Symbol, automaton::InputAlphabet >::valid ( const alphabet::Symbol & ) const { -} + static void valid ( const automaton::DFA &, const alphabet::Symbol & ) { + } +}; template < > -bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::States >::used ( const automaton::State & state ) const { - const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); - - if ( automaton->getInitialState ( ) == state ) - return true; - - if ( automaton->getFinalStates ( ).count ( state ) ) - return true; +class ComponentConstraint2< automaton::DFA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::DFA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & t : automaton->getTransitions ( ) ) - if ( ( t.first.first == state ) || ( t.second == state ) ) + if ( automaton.getFinalStates ( ).count ( state ) ) return true; - return false; -} + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & t : automaton.getTransitions ( ) ) + if ( ( t.first.first == state ) || ( t.second == state ) ) + return true; -template < > -bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::States >::available ( const automaton::State & ) const { - return true; -} + return false; + } -template < > -void automaton::DFA::Component < automaton::DFA, automaton::State, automaton::States >::valid ( const automaton::State & ) const { -} + static bool available ( const automaton::DFA &, const automaton::State & ) { + return true; + } -template < > -bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::FinalStates >::used ( const automaton::State & ) const { - return false; -} + static void valid ( const automaton::DFA &, const automaton::State & ) { + } +}; template < > -bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::FinalStates >::available ( const automaton::State & state ) const { - const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); +class ComponentConstraint2< automaton::DFA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::DFA &, const automaton::State & ) { + return false; + } - return automaton->accessComponent < automaton::States > ( ).get ( ).count ( state ); -} + static bool available ( const automaton::DFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } -template < > -void automaton::DFA::Component < automaton::DFA, automaton::State, automaton::FinalStates >::valid ( const automaton::State & ) const { -} + static void valid ( const automaton::DFA &, const automaton::State & ) { + } +}; template < > -bool automaton::DFA::Element < automaton::DFA, automaton::State, automaton::InitialState >::available ( const automaton::State & state ) const { - const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); - - return automaton->accessComponent < automaton::States > ( ).get ( ).count ( state ); -} +class ElementConstraint2< automaton::DFA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::DFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } -template < > -void automaton::DFA::Element < automaton::DFA, automaton::State, automaton::InitialState >::valid ( const automaton::State & ) const { -} + static void valid ( const automaton::DFA &, const automaton::State & ) { + } +}; } /* namespace std */ diff --git a/alib2data/src/automaton/FSM/DFA.h b/alib2data/src/automaton/FSM/DFA.h index e3a5b356c5037bc304ffd72925741bc09752301f..17a55b5fa81de55dabb3d630dca708ef7bc5120a 100644 --- a/alib2data/src/automaton/FSM/DFA.h +++ b/alib2data/src/automaton/FSM/DFA.h @@ -9,7 +9,7 @@ #define DFA_H_ #include <map> -#include <core/components.hpp> +#include <core/components2.hpp> #include "../AutomatonBase.h" #include "../common/State.h" #include "../../alphabet/Symbol.h" @@ -25,7 +25,7 @@ class States; class FinalStates; class InitialState; -class DFA : public AutomatonBase, public std::Components < DFA, alphabet::Symbol, std::tuple < InputAlphabet >, std::tuple < >, automaton::State, std::tuple < States, FinalStates >, std::tuple < InitialState > > { +class DFA : public AutomatonBase, public std::Components2 < DFA, alphabet::Symbol, std::tuple < InputAlphabet >, std::tuple < >, automaton::State, std::tuple < States, FinalStates >, std::tuple < InitialState > > { protected: std::map < std::pair < State, alphabet::Symbol >, State > transitions;