Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRegExpConcatenation.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
29
30#include "FormalRegExpElement.h"
31
32namespace regexp {
33
43template < class SymbolType >
44class FormalRegExpConcatenation : public ext::BinaryNode < FormalRegExpElement < SymbolType > > {
48 void accept ( typename FormalRegExpElement < SymbolType >::Visitor & visitor ) const override {
49 visitor.visit ( * this );
50 }
51
52public:
60
68
73
78
82 ext::smart_ptr < UnboundedRegExpElement < SymbolType > > asUnbounded ( ) const override;
83
87 bool testSymbol ( const SymbolType & symbol ) const override;
88
92 void computeMinimalAlphabet ( ext::set < SymbolType > & alphabet ) const override;
93
97 bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const override;
98
104 const FormalRegExpElement < SymbolType > & getLeftElement ( ) const;
105
111 const FormalRegExpElement < SymbolType > & getRightElement ( ) const;
112
119
126
132 void setLeftElement ( FormalRegExpElement < SymbolType > && element );
133
139 void setLeftElement ( const FormalRegExpElement < SymbolType > & element );
140
146 void setRightElement ( FormalRegExpElement < SymbolType > && element );
147
153 void setRightElement ( const FormalRegExpElement < SymbolType > & element );
154
158 std::strong_ordering operator <=> ( const FormalRegExpElement < SymbolType > & other ) const override {
159 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
160
161 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
162 }
163
171 std::strong_ordering operator <=> ( const FormalRegExpConcatenation < SymbolType > & ) const;
172
176 bool operator == ( const FormalRegExpElement < SymbolType > & other ) const override {
177 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
178
179 return false;
180 }
181
190
194 void operator >>( ext::ostream & out ) const override;
195
200 return ext::smart_ptr < FormalRegExpElement < DefaultSymbolType > > ( new FormalRegExpConcatenation < DefaultSymbolType > ( std::move ( * std::move ( getLeftElement ( ) ).normalize ( ) ), std::move ( * std::move ( getRightElement ( ) ).normalize ( ) ) ) );
201 }
202};
203
204} /* namespace regexp */
205
206#include "../unbounded/UnboundedRegExpConcatenation.h"
207
208namespace regexp {
209
210template < class SymbolType >
212}
213
214template < class SymbolType >
216}
217
218template < class SymbolType >
220 return this->getLeft ( );
221}
222
223template < class SymbolType >
225 return this->getRight ( );
226}
227
228template < class SymbolType >
230 return this->getLeft ( );
231}
232
233template < class SymbolType >
235 return this->getRight ( );
236}
237
238template < class SymbolType >
240 this->setLeft ( std::move ( element ) );
241}
242
243template < class SymbolType >
245 setLeftElement ( ext::move_copy ( element ) );
246}
247
248template < class SymbolType >
250 this->setRight ( std::move ( element ) );
251}
252
253template < class SymbolType >
255 setRightElement ( ext::move_copy ( element ) );
256}
257
258template < class SymbolType >
260 return new FormalRegExpConcatenation ( * this );
261}
262
263template < class SymbolType >
264FormalRegExpConcatenation < SymbolType > * FormalRegExpConcatenation < SymbolType >::clone ( ) && {
265 return new FormalRegExpConcatenation ( std::move ( * this ) );
266}
267
268template < class SymbolType >
271
272 res->appendElement ( std::move ( * getLeftElement ( ).asUnbounded ( ) ) );
273 res->appendElement ( std::move ( * getRightElement ( ).asUnbounded ( ) ) );
274
276}
277
278template < class SymbolType >
280 return std::tie ( getLeftElement ( ), getRightElement ( ) ) <=> std::tie ( other.getLeftElement ( ), other.getRightElement ( ) );
281}
282
283template < class SymbolType >
285 return std::tie ( getLeftElement ( ), getRightElement ( ) ) == std::tie ( other.getLeftElement ( ), other.getRightElement ( ) );
286}
287
288template < class SymbolType >
290 out << "(FormalRegExpConcatenation";
291 out << " " << getLeftElement ( );
292 out << " " << getRightElement ( );
293 out << ")";
294}
295
296template < class SymbolType >
298 return getLeftElement ( ).testSymbol ( symbol ) && getRightElement ( ).testSymbol ( symbol );
299}
300
301template < class SymbolType >
303 getLeftElement ( ).computeMinimalAlphabet ( alphabet );
304 getRightElement ( ).computeMinimalAlphabet ( alphabet );
305}
306
307template < class SymbolType >
309 return getLeftElement ( ).checkAlphabet ( alphabet ) && getRightElement ( ).checkAlphabet ( alphabet );
310}
311
312} /* namespace regexp */
313
315
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 concatenation operator in the regular expression. The node must have exactly two child...
Definition: FormalRegExpConcatenation.h:44
const FormalRegExpElement< SymbolType > & getRightElement() const
Definition: FormalRegExpConcatenation.h:224
bool testSymbol(const SymbolType &symbol) const override
Definition: FormalRegExpConcatenation.h:297
FormalRegExpConcatenation(FormalRegExpElement< SymbolType > &&left, FormalRegExpElement< SymbolType > &&right)
Creates a new instance of the concatenation node with explicit concatenated elements.
Definition: FormalRegExpConcatenation.h:211
std::strong_ordering operator<=>(const FormalRegExpElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const FormalRegExpElement < SymbolType > & other ) const;
Definition: FormalRegExpConcatenation.h:158
void setRightElement(FormalRegExpElement< SymbolType > &&element)
Definition: FormalRegExpConcatenation.h:249
FormalRegExpConcatenation< SymbolType > * clone() const &override
( ) const &
ext::smart_ptr< FormalRegExpElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: FormalRegExpConcatenation.h:199
const FormalRegExpElement< SymbolType > & getLeftElement() const
Definition: FormalRegExpConcatenation.h:219
bool checkAlphabet(const ext::set< SymbolType > &alphabet) const override
Definition: FormalRegExpConcatenation.h:308
void computeMinimalAlphabet(ext::set< SymbolType > &alphabet) const override
Definition: FormalRegExpConcatenation.h:302
void operator>>(ext::ostream &out) const override
< FormalRegExpElement < SymbolType > >::operator >> ( ext::ostream & )
Definition: FormalRegExpConcatenation.h:289
void setLeftElement(FormalRegExpElement< SymbolType > &&element)
Definition: FormalRegExpConcatenation.h:239
ext::smart_ptr< UnboundedRegExpElement< SymbolType > > asUnbounded() const override
( ) const &
Definition: FormalRegExpConcatenation.h:269
bool operator==(const FormalRegExpElement< SymbolType > &other) const override
< SymbolType >::operator == ( const FormalRegExpElement < SymbolType > & other ) const;
Definition: FormalRegExpConcatenation.h:176
Definition: FormalRegExpElement.h:67
virtual void visit(const FormalRegExpAlternation< SymbolType > &)=0
Definition: FormalRegExpElement.h:62
Represents the concatenation operator in the regular expression. The node can have 0 to n children in...
Definition: UnboundedRegExpConcatenation.h:44
Definition: UnboundedRegExpElement.h:62
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
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: ToAutomaton.h:15
Definition: FordFulkerson.hpp:16