Skip to content
Snippets Groups Projects
Commit d4869235 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

update DFA components

parent 9e42c8aa
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
   
namespace automaton { 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 > { } ) { 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 { ...@@ -191,77 +191,74 @@ void DFA::composeTransitions ( std::deque < sax::Token > & out ) const {
namespace std { namespace std {
   
template < > template < >
bool automaton::DFA::Component < automaton::DFA, alphabet::Symbol, automaton::InputAlphabet >::used ( const alphabet::Symbol & symbol ) const { class ComponentConstraint2< automaton::DFA, alphabet::Symbol, automaton::InputAlphabet > {
const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); 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 ( ) ) return false;
if ( transition.first.second == symbol ) }
return true;
return false;
}
   
template < > static bool available ( const automaton::DFA &, const alphabet::Symbol & ) {
bool automaton::DFA::Component < automaton::DFA, alphabet::Symbol, automaton::InputAlphabet >::available ( const alphabet::Symbol & ) const { return true;
return true; }
}
   
template < > static void valid ( const automaton::DFA &, const alphabet::Symbol & ) {
void automaton::DFA::Component < automaton::DFA, alphabet::Symbol, automaton::InputAlphabet >::valid ( const alphabet::Symbol & ) const { }
} };
   
template < > template < >
bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::States >::used ( const automaton::State & state ) const { class ComponentConstraint2< automaton::DFA, automaton::State, automaton::States > {
const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); public:
static bool used ( const automaton::DFA & automaton, const automaton::State & state ) {
if ( automaton->getInitialState ( ) == state ) if ( automaton.getInitialState ( ) == state )
return true; return true;
if ( automaton->getFinalStates ( ).count ( state ) )
return true;
   
for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & t : automaton->getTransitions ( ) ) if ( automaton.getFinalStates ( ).count ( state ) )
if ( ( t.first.first == state ) || ( t.second == state ) )
return true; 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 < > return false;
bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::States >::available ( const automaton::State & ) const { }
return true;
}
   
template < > static bool available ( const automaton::DFA &, const automaton::State & ) {
void automaton::DFA::Component < automaton::DFA, automaton::State, automaton::States >::valid ( const automaton::State & ) const { return true;
} }
   
template < > static void valid ( const automaton::DFA &, const automaton::State & ) {
bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::FinalStates >::used ( const automaton::State & ) const { }
return false; };
}
   
template < > template < >
bool automaton::DFA::Component < automaton::DFA, automaton::State, automaton::FinalStates >::available ( const automaton::State & state ) const { class ComponentConstraint2< automaton::DFA, automaton::State, automaton::FinalStates > {
const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); 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 < > static void valid ( const automaton::DFA &, const automaton::State & ) {
void automaton::DFA::Component < automaton::DFA, automaton::State, automaton::FinalStates >::valid ( const automaton::State & ) const { }
} };
   
template < > template < >
bool automaton::DFA::Element < automaton::DFA, automaton::State, automaton::InitialState >::available ( const automaton::State & state ) const { class ElementConstraint2< automaton::DFA, automaton::State, automaton::InitialState > {
const automaton::DFA * automaton = static_cast < const automaton::DFA * > ( this ); public:
static bool available ( const automaton::DFA & automaton, const automaton::State & state ) {
return automaton->accessComponent < automaton::States > ( ).get ( ).count ( state ); return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state );
} }
   
template < > static void valid ( const automaton::DFA &, const automaton::State & ) {
void automaton::DFA::Element < automaton::DFA, automaton::State, automaton::InitialState >::valid ( const automaton::State & ) const { }
} };
   
} /* namespace std */ } /* namespace std */
   
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#define DFA_H_ #define DFA_H_
   
#include <map> #include <map>
#include <core/components.hpp> #include <core/components2.hpp>
#include "../AutomatonBase.h" #include "../AutomatonBase.h"
#include "../common/State.h" #include "../common/State.h"
#include "../../alphabet/Symbol.h" #include "../../alphabet/Symbol.h"
...@@ -25,7 +25,7 @@ class States; ...@@ -25,7 +25,7 @@ class States;
class FinalStates; class FinalStates;
class InitialState; 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: protected:
std::map < std::pair < State, alphabet::Symbol >, State > transitions; std::map < std::pair < State, alphabet::Symbol >, State > transitions;
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment