Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRTEIteration.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 "FormalRTEElement.h"
28
30
31#include <ext/utility>
32
33namespace rte {
34
44template < class SymbolType >
45class FormalRTEIteration : public ext::UnaryNode < FormalRTEElement < SymbolType > > {
49 FormalRTESymbolSubst < SymbolType > m_substitutionSymbol;
50
54 void accept ( typename FormalRTEElement < SymbolType >::ConstVisitor & visitor ) const override {
55 visitor.visit ( * this );
56 }
57
61 void accept ( typename FormalRTEElement < SymbolType >::Visitor & visitor ) override {
62 visitor.visit ( * this );
63 }
64
65public:
73
80 explicit FormalRTEIteration ( const FormalRTEElement < SymbolType > & element, FormalRTESymbolSubst < SymbolType > substitutionSymbol );
81
86
90 FormalRTEIteration < SymbolType > * clone ( ) && override;
91
95 bool testSymbol ( const common::ranked_symbol < SymbolType > & symbol ) const override;
96
100 void computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType > > & alphabetF, ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
101
105 bool checkAlphabet ( const ext::set < common::ranked_symbol < SymbolType > > & alphabetF, const ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
106
112 const FormalRTEElement < SymbolType > & getElement ( ) const;
113
120
127
134
140 void setElement ( const FormalRTEElement < SymbolType > & element );
141
147 void setElement ( FormalRTEElement < SymbolType > && element );
148
155
159 std::strong_ordering operator <=> ( const FormalRTEElement < SymbolType > & other ) const override {
160 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
161
162 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
163 }
164
172 std::strong_ordering operator <=> ( const FormalRTEIteration < SymbolType > & ) const;
173
177 bool operator == ( const FormalRTEElement < SymbolType > & other ) const override {
178 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
179
180 return false;
181 }
182
191
195 void operator >>( ext::ostream & out ) const override;
196
201 FormalRTESymbolSubst < DefaultSymbolType > subst ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( m_substitutionSymbol ).getSymbol ( ) ) );
202 return ext::smart_ptr < FormalRTEElement < DefaultSymbolType > > ( new FormalRTEIteration < DefaultSymbolType > ( std::move ( * std::move ( getElement ( ) ).normalize ( ) ), std::move ( subst ) ) );
203 }
204};
205
206template < class SymbolType >
207FormalRTEIteration < SymbolType >::FormalRTEIteration ( FormalRTEElement < SymbolType > && element, FormalRTESymbolSubst < SymbolType > substitutionSymbol ) : ext::UnaryNode < FormalRTEElement < SymbolType > > ( std::move ( element ) ), m_substitutionSymbol ( std::move ( substitutionSymbol ) ) {
208}
209
210template < class SymbolType >
212}
213
214template < class SymbolType >
216 return this->getChild ( );
217}
218
219template < class SymbolType >
221 return this->getChild ( );
222}
223
224template < class SymbolType >
226 return m_substitutionSymbol;
227}
228
229template < class SymbolType >
231 return m_substitutionSymbol;
232}
233
234template < class SymbolType >
236 setElement ( ext::move_copy ( element ) );
237}
238
239template < class SymbolType >
241 this->setChild ( std::move ( element ) );
242}
243
244template < class SymbolType >
246 m_substitutionSymbol = std::move ( symbol );
247}
248
249template < class SymbolType >
251 return new FormalRTEIteration ( * this );
252}
253
254template < class SymbolType >
255FormalRTEIteration < SymbolType > * FormalRTEIteration < SymbolType >::clone ( ) && {
256 return new FormalRTEIteration ( std::move ( * this ) );
257}
258
259template < class SymbolType >
261 return getElement ( ) <=> other.getElement ( );
262}
263
264template < class SymbolType >
266 return getElement ( ) == other.getElement ( );
267}
268
269template < class SymbolType >
271 out << "(FormalRTEIteration " << m_substitutionSymbol << " " << getElement ( ) << ")";
272}
273
274template < class SymbolType >
276 return this->getElement ( ).testSymbol ( symbol );
277}
278
279template < class SymbolType >
281 alphabetK.insert ( m_substitutionSymbol.getSymbol ( ) );
282 this->getElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK );
283}
284
285template < class SymbolType >
287 return alphabetK.count ( getSubstitutionSymbol ( ).getSymbol ( ) ) > 0 && getElement ( ).checkAlphabet ( alphabetF, alphabetK );
288}
289
290} /* namespace rte */
291
293
static common::ranked_symbol< DefaultSymbolType > normalizeRankedSymbol(common::ranked_symbol< SymbolType > &&symbol)
Definition: SymbolNormalize.h:81
Definition: ranked_symbol.hpp:20
Unary node is specialisation of Anyary node to one child.
Definition: tree_base.hpp:377
Definition: ostream.h:14
Definition: set.hpp:44
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
Definition: typeindex.h:37
Definition: FormalRTEElement.h:59
virtual void visit(const FormalRTEAlternation< SymbolType > &alternation)=0
Definition: FormalRTEElement.h:70
virtual void visit(FormalRTEAlternation< SymbolType > &alternation)=0
Definition: FormalRTEElement.h:54
Represents the iteration operator in the regular tree expression. The node has exactly one child.
Definition: FormalRTEIteration.h:45
void operator>>(ext::ostream &out) const override
< FormalRTEElement < SymbolType > >::operator >> ( ext::ostream & ) const
Definition: FormalRTEIteration.h:270
const FormalRTEElement< SymbolType > & getElement() const
Definition: FormalRTEIteration.h:215
bool testSymbol(const common::ranked_symbol< SymbolType > &symbol) const override
< SymbolType >::testSymbol ( const common::ranked_symbol < SymbolType > & ) const
Definition: FormalRTEIteration.h:275
const FormalRTESymbolSubst< SymbolType > & getSubstitutionSymbol() const
Definition: FormalRTEIteration.h:225
FormalRTEIteration(FormalRTEElement< SymbolType > &&element, FormalRTESymbolSubst< SymbolType > substitutionSymbol)
Creates a new instance of the substitution node with explicit tree to iterate and a symbol representi...
Definition: FormalRTEIteration.h:207
FormalRTEIteration< SymbolType > * clone() const &override
< SymbolType >::clone ( ) const &
void setElement(const FormalRTEElement< SymbolType > &element)
Definition: FormalRTEIteration.h:235
bool operator==(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator == ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTEIteration.h:177
void computeMinimalAlphabet(ext::set< common::ranked_symbol< SymbolType > > &alphabetF, ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const override
< SymbolType >::computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType > > &,...
Definition: FormalRTEIteration.h:280
ext::smart_ptr< FormalRTEElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: FormalRTEIteration.h:200
std::strong_ordering operator<=>(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTEIteration.h:159
bool checkAlphabet(const ext::set< common::ranked_symbol< SymbolType > > &alphabetF, const ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const override
< SymbolType >::checkAlphabet ( const ext::set < common::ranked_symbol < SymbolType > > &,...
Definition: FormalRTEIteration.h:286
void setSubstitutionSymbol(FormalRTESymbolSubst< SymbolType > symbol)
Definition: FormalRTEIteration.h:245
Represents the substitution symbol in the regular tree expression. The node can't have any children.
Definition: FormalRTESymbolSubst.h:43
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: Permutation.hpp:18
Definition: sigHandler.cpp:20
auto move_copy(const T &param)
Allow moving of copied instance of the source.
Definition: utility.hpp:45
Definition: ToFTAGlushkov.h:22
Definition: FordFulkerson.hpp:16