Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRTEAlternation.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 <ext/utility>
27
28#include "FormalRTEElement.h"
29
31
32namespace rte {
33
43template < class SymbolType >
44class FormalRTEAlternation : public ext::BinaryNode < FormalRTEElement < SymbolType > > {
48 void accept ( typename FormalRTEElement < SymbolType >::ConstVisitor & visitor ) const override {
49 visitor.visit ( * this );
50 }
51
55 void accept ( typename FormalRTEElement < SymbolType >::Visitor & visitor ) override {
56 visitor.visit ( * this );
57 }
58
59public:
67
75
80
84 FormalRTEAlternation < SymbolType > * clone ( ) && override;
85
89 bool testSymbol ( const common::ranked_symbol < SymbolType > & symbol ) const override;
90
94 void computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType > > & alphabetF, ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
95
99 bool checkAlphabet ( const ext::set < common::ranked_symbol < SymbolType > > & alphabetF, const ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
100
106 const FormalRTEElement < SymbolType > & getLeftElement ( ) const;
107
113 const FormalRTEElement < SymbolType > & getRightElement ( ) const;
114
121
128
134 void setLeftElement ( FormalRTEElement < SymbolType > && element );
135
141 void setLeftElement ( const FormalRTEElement < SymbolType > & element );
142
148 void setRightElement ( FormalRTEElement < SymbolType > && element );
149
155 void setRightElement ( const FormalRTEElement < SymbolType > & element );
156
160 std::strong_ordering operator <=> ( const FormalRTEElement < SymbolType > & other ) const override {
161 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
162
163 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
164 }
165
173 std::strong_ordering operator <=> ( const FormalRTEAlternation < SymbolType > & ) const;
174
178 bool operator == ( const FormalRTEElement < SymbolType > & other ) const override {
179 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
180
181 return false;
182 }
183
192
196 void operator >>( ext::ostream & out ) const override;
197
202 return ext::smart_ptr < FormalRTEElement < DefaultSymbolType > > ( new FormalRTEAlternation < DefaultSymbolType > ( std::move ( * std::move ( getLeftElement ( ) ).normalize ( ) ), std::move ( * std::move ( getRightElement ( ) ).normalize ( ) ) ) );
203 }
204};
205
206template < class SymbolType >
208}
209
210template < class SymbolType >
212}
213
214template < class SymbolType >
216 return this->getLeft ( );
217}
218
219template < class SymbolType >
221 return this->getRight ( );
222}
223
224template < class SymbolType >
226 return this->getLeft ( );
227}
228
229template < class SymbolType >
231 return this->getRight ( );
232}
233
234template < class SymbolType >
236 setLeftElement ( ext::move_copy ( element ) );
237}
238
239template < class SymbolType >
241 this->setLeft ( std::move ( element ) );
242}
243
244template < class SymbolType >
246 setRightElement ( ext::move_copy ( element ) );
247}
248
249template < class SymbolType >
251 this->setRight ( std::move ( element ) );
252}
253
254template < class SymbolType >
256 return new FormalRTEAlternation ( * this );
257}
258
259template < class SymbolType >
260FormalRTEAlternation < SymbolType > * FormalRTEAlternation < SymbolType >::clone ( ) && {
261 return new FormalRTEAlternation ( std::move ( * this ) );
262}
263
264template < class SymbolType >
266 return std::tie ( getLeftElement ( ), getRightElement ( ) ) <=> std::tie ( other.getLeftElement ( ), other.getRightElement ( ) );
267}
268
269template < class SymbolType >
271 return std::tie ( getLeftElement ( ), getRightElement ( ) ) == std::tie ( other.getLeftElement ( ), other.getRightElement ( ) );
272}
273
274template < class SymbolType >
276 out << "(FormalRTEAlternation";
277 out << " " << getLeftElement ( );
278 out << " " << getRightElement ( );
279 out << ")";
280}
281
282template < class SymbolType >
284 if ( getLeftElement ( ).testSymbol ( symbol ) ) return true;
285
286 if ( getRightElement ( ).testSymbol ( symbol ) ) return true;
287
288 return false;
289}
290
291template < class SymbolType >
293 getLeftElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK );
294 getRightElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK );
295}
296
297template < class SymbolType >
299 return getLeftElement ( ).checkAlphabet ( alphabetF, alphabetK ) && getRightElement ( ).checkAlphabet ( alphabetF, alphabetK );
300}
301
302} /* namespace rte */
303
305
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
Represents the alternation operator in the regular tree expression. The node must have exactly two ch...
Definition: FormalRTEAlternation.h:44
bool testSymbol(const common::ranked_symbol< SymbolType > &symbol) const override
( const common::ranked_symbol < SymbolType > & ) const
Definition: FormalRTEAlternation.h:283
const FormalRTEElement< SymbolType > & getRightElement() const
Definition: FormalRTEAlternation.h:220
void operator>>(ext::ostream &out) const override
< SymbolType >::operator == ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTEAlternation.h:275
const FormalRTEElement< SymbolType > & getLeftElement() const
Definition: FormalRTEAlternation.h:215
bool operator==(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator == ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTEAlternation.h:178
FormalRTEAlternation(FormalRTEElement< SymbolType > &&left, FormalRTEElement< SymbolType > &&right)
Creates a new instance of the alternation node with explicit alternated elements.
Definition: FormalRTEAlternation.h:207
void setLeftElement(FormalRTEElement< SymbolType > &&element)
Definition: FormalRTEAlternation.h:240
std::strong_ordering operator<=>(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTEAlternation.h:160
void computeMinimalAlphabet(ext::set< common::ranked_symbol< SymbolType > > &alphabetF, ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const override
( ext::set < common::ranked_symbol < SymbolType > > &, ext::set < common::ranked_symbol < SymbolType ...
Definition: FormalRTEAlternation.h:292
FormalRTEAlternation< SymbolType > * clone() const &override
( ) const &
ext::smart_ptr< FormalRTEElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: FormalRTEAlternation.h:201
bool checkAlphabet(const ext::set< common::ranked_symbol< SymbolType > > &alphabetF, const ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const override
( const ext::set < common::ranked_symbol < SymbolType > > &, const ext::set < common::ranked_symbol <...
Definition: FormalRTEAlternation.h:298
void setRightElement(FormalRTEElement< SymbolType > &&element)
Definition: FormalRTEAlternation.h:250
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
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