-
Jan Trávníček authoredJan Trávníček authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ExtendedNFA.h 3.06 KiB
/*
* ExtendedNFA.h
*
* Created on: Mar 25, 2013
* Author: Jan Travnicek
*/
#ifndef EXTENDED_NFA_H_
#define EXTENDED_NFA_H_
#include <map>
#include "../AutomatonBase.h"
#include "../common/SingleInitialState.h"
#include "../common/InputAlphabet.h"
#include "../../regexp/RegExp.h"
#include "CompactNFA.h"
#include "EpsilonNFA.h"
#include "MultiInitialStateNFA.h"
#include "NFA.h"
#include "DFA.h"
namespace automaton {
/**
* Represents Finite Automaton.
* Can store nondeterministic finite automaton without epsilon transitions.
*/
class ExtendedNFA : public std::acceptor<ExtendedNFA, VisitableAutomatonBase, std::acceptor<ExtendedNFA, alib::VisitableObjectBase, AutomatonBase> >, public SingleInitialState, public InputAlphabet {
protected:
std::map<std::pair<State, regexp::RegExp>, std::set<State> > transitions;
public:
explicit ExtendedNFA(State initialState);
explicit ExtendedNFA(const CompactNFA& other);
explicit ExtendedNFA(const EpsilonNFA& other);
explicit ExtendedNFA(const MultiInitialStateNFA& other);
explicit ExtendedNFA(const NFA& other);
explicit ExtendedNFA(const DFA& other);
virtual AutomatonBase* clone() const;
virtual AutomatonBase* plunder() &&;
/**
* @copydoc Automaton::removeState(const State&)
*/
virtual bool removeState(const State& state);
/**
* @copydoc Automaton::removeInputSymbol(const Symbol&)
*/
virtual bool removeInputSymbol(const alphabet::Symbol& symbol);
/**
* Adds transition defined by parameters to the automaton.
* @param current current state
* @param input input symbol
* @param next next state
* @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton
*/
bool addTransition(State current, regexp::RegExp input, State next);
/**
* Removes transition from the automaton.
* @param transition transition to remove
* @throws AutomatonException when transition doesn't exists.
*/
bool removeTransition(const State& current, const regexp::RegExp& input, const State& next);
/**
* @return automaton transitions
*/
const std::map<std::pair<State, regexp::RegExp>, std::set<State> >& getTransitions() const;
/**
* @return automaton transitions from state
*/
std::map<std::pair<State, regexp::RegExp>, std::set<State> > getTransitionsFromState(const State& from) const;
/**
* @return automaton transitions to state
*/
std::map<std::pair<State, regexp::RegExp>, std::set<State> > getTransitionsToState(const State& from) const;
virtual int compare(const ObjectBase& other) const {
return -other.compare(*this);
}
virtual int compare(const ExtendedNFA& other) const;
virtual void operator>>(std::ostream& os) const;
virtual explicit operator std::string() const;
virtual int selfTypeId() const {
return typeId(*this);
}
};
} /* namespace automaton */
namespace std {
template<>
struct compare<automaton::ExtendedNFA> {
int operator()(const automaton::ExtendedNFA& first, const automaton::ExtendedNFA& second) const {
return first.compare(second);
}
};
} /* namespace std */
#endif /* EXTENDED_NFA_H_ */