47 template <
typename TransitionType>
53 template <
typename TransitionType>
55 : m_namePool(namePool)
60 template <
typename TransitionType>
65 if (type == StartState) {
66 QHashIterator<StateId, StateType>
it(m_states);
67 while (it.hasNext()) {
69 Q_ASSERT(it.value() != StartState && it.value() != StartEndState);
76 m_states.insert(
id, type);
79 if (type == StartState || type == StartEndState)
85 template <
typename TransitionType>
94 template <
typename TransitionType>
101 template <
typename TransitionType>
105 QHashIterator<StateId, StateType>
it(m_states);
106 while (it.hasNext()) {
108 if (it.value() == StartState || it.value() == StartEndState) {
109 m_currentState = it.key();
117 template <
typename TransitionType>
121 m_transitions.clear();
122 m_epsilonTransitions.clear();
127 template <
typename TransitionType>
131 if (!m_transitions.contains(m_currentState)) {
138 m_currentState = entry.
value(transition).first();
139 m_lastTransition = transition;
146 template <
typename TransitionType>
150 if (!m_transitions.contains(m_currentState)) {
160 template <
typename TransitionType>
161 template <
typename InputType>
165 if (!m_transitions.contains(m_currentState)) {
171 QHashIterator<TransitionType, QVector<StateId> >
it(entry);
172 while (it.hasNext()) {
174 if (inputEqualsTransition(input, it.key())) {
175 m_currentState = it.value().first();
176 m_lastTransition = it.key();
184 template <
typename TransitionType>
185 template <
typename InputType>
191 template <
typename TransitionType>
195 return (m_states.value(m_currentState) == StartEndState || m_states.value(m_currentState) == EndState);
198 template <
typename TransitionType>
201 return m_lastTransition;
204 template <
typename TransitionType>
207 QHashIterator<StateId, StateType>
it(m_states);
208 while (it.hasNext()) {
210 if (it.value() == StartState || it.value() == StartEndState)
218 template <
typename TransitionType>
226 template <
typename TransitionType>
230 qWarning(
"device must be open for writing");
237 QHashIterator<StateId, QHash<TransitionType, QVector<StateId> > >
it(m_transitions);
238 QHashIterator<StateId, StateType> it3(m_states);
240 s <<
"digraph " << graphName <<
" {\n";
241 s <<
" mindist = 2.0\n";
244 while (it.hasNext()) {
247 QHashIterator<TransitionType, QVector<StateId> > it2(it.value());
248 while (it2.hasNext()) {
250 for (
int i = 0; i < it2.value().count(); ++i)
251 s <<
" " << it.key() <<
" -> " << it2.value().at(i) <<
" [label=\"" << transitionTypeToString(it2.key()) <<
"\"]\n";
255 QHashIterator<StateId, QVector<StateId> > it4(m_epsilonTransitions);
256 while (it4.hasNext()) {
260 for (
int i = 0; i < states.
count(); ++i)
261 s <<
" " << it4.key() <<
" -> " << states.
at(i) <<
" [label=\"ε\"]\n";
265 while (it3.hasNext()) {
269 if (it3.value() == StartState) {
270 style =
QLatin1String(
"shape=circle, style=filled, color=blue");
271 }
else if (it3.value() == StartEndState) {
272 style =
QLatin1String(
"shape=doublecircle, style=filled, color=blue");
273 }
else if (it3.value() == InternalState) {
274 style =
QLatin1String(
"shape=circle, style=filled, color=red");
275 }
else if (it3.value() == EndState) {
276 style =
QLatin1String(
"shape=doublecircle, style=filled, color=green");
279 s <<
" " << it3.key() <<
" [" << style <<
"]\n";
286 if (device->
write(graph) == -1)
293 template <
typename TransitionType>
300 for (
int i = 0; i < stateTable.count(); ++i) {
301 if (stateTable.at(i).first == nfaState)
302 return stateTable.at(i).second;
309 QSetIterator<StateId>
it(nfaState);
310 bool hasStartState =
false;
311 bool hasEndState =
false;
312 while (it.hasNext()) {
313 const StateId state = it.next();
314 if (m_states.value(state) == EndState) {
316 }
else if (m_states.value(state) == StartState) {
317 hasStartState =
true;
322 type = StartEndState;
325 }
else if (hasEndState) {
338 template <
typename TransitionType>
348 QHashIterator<StateId, StateType> stateTypeIt(m_states);
349 while (stateTypeIt.hasNext()) {
351 if (stateTypeIt.value() == StartState) {
352 startState = stateTypeIt.key();
364 while (!workStates.
isEmpty()) {
380 QSetIterator<StateId>
it(states);
381 while (it.hasNext()) {
382 input << m_transitions.
value(it.next()).
keys();
387 const StateId dfaBegin = dfaStateForNfaState(states, table, dfa);
389 for (
int i = 0; i < input.
count(); ++i) {
392 const QSet<StateId> followStates = epsilonClosure(move(states, input.
at(i)));
395 const StateId dfaEnd = dfaStateForNfaState(followStates, table, dfa);
402 workStates.
append(followStates);
409 template <
typename TransitionType>
static uint hash(const uchar *p, int n)
void addTransition(StateId start, TransitionType transition, StateId end)
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
The QByteArray class provides an array of bytes.
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
static void clear(QVariant::Private *d)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
const T value(const Key &key) const
Returns the value associated with the key.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void append(const T &t)
Inserts value at the end of the list.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
T takeFirst()
Removes the first item in the list and returns it.
T value(int i) const
Returns the value at index position i in the vector.
const T & at(int i) const
Returns the item at index position i in the list.
void append(const T &t)
Inserts value at the end of the vector.
Q_CORE_EXPORT void qWarning(const char *,...)
T value(int i) const
Returns the value at index position i in the list.
const T & at(int i) const
Returns the item at index position i in the vector.
The QTextStream class provides a convenient interface for reading and writing text.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
A state machine used for evaluation.
void flush()
Flushes any buffered data waiting to be written to the device.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
static const KeyPair *const end
The QIODevice class is the base interface class of all I/O devices in Qt.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
StateId addState(StateType type)
The QList class is a template class that provides lists.