Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRTESubstitution.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#include <ext/utility>
31
32namespace rte {
33
43template < class SymbolType >
44class FormalRTESubstitution : public ext::BinaryNode < FormalRTEElement < SymbolType > > {
48 FormalRTESymbolSubst < SymbolType > m_substitutionSymbol;
49
53 void accept ( typename FormalRTEElement < SymbolType >::ConstVisitor & visitor ) const override {
54 visitor.visit ( * this );
55 }
56
60 void accept ( typename FormalRTEElement < SymbolType >::Visitor & visitor ) override {
61 visitor.visit ( * this );
62 }
63
64public:
73
82
87
91 FormalRTESubstitution < SymbolType > * clone ( ) && override;
92
96 bool testSymbol ( const common::ranked_symbol < SymbolType > & symbol ) const override;
97
101 void computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType > > & alphabetF, ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
102
106 bool checkAlphabet ( const ext::set < common::ranked_symbol < SymbolType > > & alphabetF, const ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
107
113 const FormalRTEElement < SymbolType > & getLeftElement ( ) const;
114
120 const FormalRTEElement < SymbolType > & getRightElement ( ) const;
121
128
135
142
149
155 void setLeftElement ( const FormalRTEElement < SymbolType > & element );
156
162 void setLeftElement ( FormalRTEElement < SymbolType > && element );
163
169 void setRightElement ( const FormalRTEElement < SymbolType > & element );
170
176 void setRightElement ( FormalRTEElement < SymbolType > && element );
177
184
188 std::strong_ordering operator <=> ( const FormalRTEElement < SymbolType > & other ) const override {
189 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
190
191 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
192 }
193
201 std::strong_ordering operator <=> ( const FormalRTESubstitution < SymbolType > & ) const;
202
206 bool operator == ( const FormalRTEElement < SymbolType > & other ) const override {
207 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
208
209 return false;
210 }
211
220
224 void operator >>( ext::ostream & out ) const override;
225
230 FormalRTESymbolSubst < DefaultSymbolType > subst ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( m_substitutionSymbol ).getSymbol ( ) ) );
231 return ext::smart_ptr < FormalRTEElement < DefaultSymbolType > > ( new FormalRTESubstitution < DefaultSymbolType > ( std::move ( * std::move ( getLeftElement ( ) ).normalize ( ) ), std::move ( * std::move ( getRightElement ( ) ).normalize ( ) ), std::move ( subst ) ) );
232 }
233};
234
235template < class SymbolType >
236FormalRTESubstitution < SymbolType >::FormalRTESubstitution ( FormalRTEElement < SymbolType > && left, FormalRTEElement < SymbolType > && right, FormalRTESymbolSubst < SymbolType > substitutionSymbol ) : ext::BinaryNode < FormalRTEElement < SymbolType > > ( std::move ( left ), std::move ( right ) ), m_substitutionSymbol ( std::move ( substitutionSymbol ) ) {
237}
238
239template < class SymbolType >
241}
242
243template < class SymbolType >
245 return this->getLeft ( );
246}
247
248template < class SymbolType >
250 return this->getRight ( );
251}
252
253template < class SymbolType >
255 return m_substitutionSymbol;
256}
257
258template < class SymbolType >
260 return this->getLeft ( );
261}
262
263template < class SymbolType >
265 return this->getRight ( );
266}
267
268template < class SymbolType >
270 return m_substitutionSymbol;
271}
272
273template < class SymbolType >
275 setLeftElement ( ext::move_copy ( element ) );
276}
277
278template < class SymbolType >
280 this->setLeft ( std::move ( element ) );
281}
282
283template < class SymbolType >
285 setRightElement ( ext::move_copy ( element ) );
286}
287
288template < class SymbolType >
290 this->setRight ( std::move ( element ) );
291}
292
293template < class SymbolType >
295 m_substitutionSymbol = std::move ( symbol );
296}
297
298template < class SymbolType >
300 return new FormalRTESubstitution ( * this );
301}
302
303template < class SymbolType >
304FormalRTESubstitution < SymbolType > * FormalRTESubstitution < SymbolType >::clone ( ) && {
305 return new FormalRTESubstitution ( std::move ( * this ) );
306}
307
308template < class SymbolType >
310 auto first = ext::tie ( getLeftElement ( ), getRightElement ( ), getSubstitutionSymbol ( ) );
311 auto second = ext::tie ( other.getLeftElement ( ), other.getRightElement ( ), other.getSubstitutionSymbol ( ) );
312
313 return first <=> second;
314}
315
316template < class SymbolType >
318 auto first = ext::tie ( getLeftElement ( ), getRightElement ( ), getSubstitutionSymbol ( ) );
319 auto second = ext::tie ( other.getLeftElement ( ), other.getRightElement ( ), other.getSubstitutionSymbol ( ) );
320
321 return first == second;
322}
323
324template < class SymbolType >
326 out << "(FormalRTESubstitution";
327 out << " " << m_substitutionSymbol;
328 out << " " << getLeftElement ( );
329 out << " " << getRightElement ( );
330 out << ")";
331}
332
333template < class SymbolType >
335 if ( getLeftElement ( ).testSymbol ( symbol ) ) return true;
336
337 if ( getRightElement ( ).testSymbol ( symbol ) ) return true;
338
339 if ( m_substitutionSymbol.getSymbol ( ) == symbol ) return true;
340
341 return false;
342}
343
344template < class SymbolType >
346 alphabetK.insert ( m_substitutionSymbol.getSymbol ( ) );
347 getLeftElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK );
348 getRightElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK );
349}
350
351template < class SymbolType >
353 return alphabetK.count ( getSubstitutionSymbol ( ).getSymbol ( ) ) > 0 && getLeftElement ( ).checkAlphabet ( alphabetF, alphabetK ) && getRightElement ( ).checkAlphabet ( alphabetF, alphabetK );
354}
355
356} /* namespace rte */
357
359
static common::ranked_symbol< DefaultSymbolType > normalizeRankedSymbol(common::ranked_symbol< SymbolType > &&symbol)
Definition: SymbolNormalize.h:81
Definition: ranked_symbol.hpp:20
Binary node is specialisation of Anyary node to two children.
Definition: tree_base.hpp:459
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 concatenation operator in the regular tree expression. The node must have exactly two ...
Definition: FormalRTESubstitution.h:44
void setRightElement(const FormalRTEElement< SymbolType > &element)
Definition: FormalRTESubstitution.h:284
FormalRTESubstitution< SymbolType > * clone() const &override
< SymbolType >::clone ( ) const &
FormalRTESubstitution(FormalRTEElement< SymbolType > &&left, FormalRTEElement< SymbolType > &&right, FormalRTESymbolSubst< SymbolType > substitutionSymbol)
Creates a new instance of the substitution node with explicit tree to substitute in,...
Definition: FormalRTESubstitution.h:236
const FormalRTESymbolSubst< SymbolType > & getSubstitutionSymbol() const
Definition: FormalRTESubstitution.h:254
bool operator==(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator == ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTESubstitution.h:206
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: FormalRTESubstitution.h:345
void operator>>(ext::ostream &out) const override
< FormalRTEElement < SymbolType > >::operator >> ( ext::ostream & ) const
Definition: FormalRTESubstitution.h:325
const FormalRTEElement< SymbolType > & getLeftElement() const
Definition: FormalRTESubstitution.h:244
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: FormalRTESubstitution.h:352
ext::smart_ptr< FormalRTEElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: FormalRTESubstitution.h:229
bool testSymbol(const common::ranked_symbol< SymbolType > &symbol) const override
< SymbolType >::testSymbol ( const common::ranked_symbol < SymbolType > & ) const
Definition: FormalRTESubstitution.h:334
const FormalRTEElement< SymbolType > & getRightElement() const
Definition: FormalRTESubstitution.h:249
void setSubstitutionSymbol(FormalRTESymbolSubst< SymbolType > symbol)
Definition: FormalRTESubstitution.h:294
std::strong_ordering operator<=>(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTESubstitution.h:188
void setLeftElement(const FormalRTEElement< SymbolType > &element)
Definition: FormalRTESubstitution.h:274
Represents the substitution symbol in the regular tree expression. The node can't have any children.
Definition: FormalRTESymbolSubst.h:43
p second
Definition: ToRegExpAlgebraic.h:126
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: Permutation.hpp:18
Definition: sigHandler.cpp:20
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
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