Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NondeterministicZAutomaton.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <core/xmlApi.hpp>
28#include "../common/AutomatonFromXMLParser.h"
29#include "../common/AutomatonToXMLComposer.h"
30
34
35namespace core {
36
37template < class SymbolType, class StateType >
38struct xmlApi < automaton::NondeterministicZAutomaton < SymbolType, StateType > > {
46 static std::string xmlTagName() {
47 return "NondeterministicZAutomaton";
48 }
49
57 static bool first ( const ext::deque < sax::Token >::const_iterator & input ) {
59 }
60
69
77
85
93};
94
95template < class SymbolType, class StateType >
98
99 ext::set<StateType> states = automaton::AutomatonFromXMLParser::parseStates<StateType>(input);
100 ext::set< SymbolType > inputSymbols = automaton::AutomatonFromXMLParser::parseInputAlphabet< SymbolType >(input);
101 ext::set<StateType> finalStates = automaton::AutomatonFromXMLParser::parseFinalStates<StateType>(input);
102
104 automaton.setStates(std::move(states));
105 automaton.setInputAlphabet(std::move(inputSymbols));
106 automaton.setFinalStates(std::move(finalStates));
107
109
111 return automaton;
112}
113
114template < class SymbolType, class StateType >
119
120 automaton.addTransition ( std::move ( transition.first.first ), std::move ( transition.first.second ), std::move ( transition.second ) );
121}
122
123template < class SymbolType, class StateType >
125 out.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT );
126
130 composeTransitions(out, automaton);
131
132 out.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT );
133}
134
135template < class SymbolType, class StateType >
137 out.emplace_back(sax::Token("transitions", sax::Token::TokenType::START_ELEMENT));
138 for(const auto& transition : automaton.getTransitions()) {
139 out.emplace_back(sax::Token("transition", sax::Token::TokenType::START_ELEMENT));
140
142
143 out.emplace_back(sax::Token("transition", sax::Token::TokenType::END_ELEMENT));
144 }
145
146 out.emplace_back(sax::Token("transitions", sax::Token::TokenType::END_ELEMENT));
147}
148
149} /* namespace core */
static void parseTransitions(ext::deque< sax::Token >::iterator &input, T &automaton)
Definition: AutomatonFromXMLParser.h:114
static void composeStates(ext::deque< sax::Token > &, const ext::set< StateType > &states)
Definition: AutomatonToXMLComposer.h:100
static void composeInputAlphabet(ext::deque< sax::Token > &, const ext::set< SymbolType > &symbols)
Definition: AutomatonToXMLComposer.h:109
static void composeFinalStates(ext::deque< sax::Token > &, const ext::set< StateType > &states)
Definition: AutomatonToXMLComposer.h:170
Nondeterministic Z-Automaton. Computation model for unranked regular tree languages.
Definition: NondeterministicZAutomaton.h:68
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Definition: set.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
static void popToken(ext::deque< Token >::iterator &input, Token::TokenType type, const std::string &data)
Definition: FromXMLParserHelper.cpp:39
static bool isToken(ext::deque< Token >::const_iterator input, Token::TokenType type, const std::string &data)
Definition: FromXMLParserHelper.cpp:29
Definition: Token.h:17
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
Definition: ToGrammar.h:31
Definition: normalize.hpp:10
static bool first(const ext::deque< sax::Token >::const_iterator &input)
Tests whether the token stream starts with this type.
Definition: NondeterministicZAutomaton.h:57
static std::string xmlTagName()
The XML tag name of class.
Definition: NondeterministicZAutomaton.h:46
Definition: xmlApi.hpp:27