Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
UnboundedRegExpConcatenation.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/ptr_vector>
27
29
31
32namespace regexp {
33
43template < class SymbolType >
44class UnboundedRegExpConcatenation : public ext::VararyNode < UnboundedRegExpElement < SymbolType > > {
48 void accept ( typename UnboundedRegExpElement < SymbolType >::Visitor & visitor ) const & override {
49 visitor.visit ( * this );
50 }
51
55 void accept ( typename UnboundedRegExpElement < SymbolType >::RvalueVisitor & visitor ) && override {
56 visitor.visit ( std::move ( * this ) );
57 }
58
59public:
63 explicit UnboundedRegExpConcatenation ( ) = default;
64
69
74
78 ext::smart_ptr < FormalRegExpElement < SymbolType > > asFormal ( ) const override;
79
83 bool testSymbol ( const SymbolType & symbol ) const override;
84
88 void computeMinimalAlphabet ( ext::set < SymbolType > & alphabet ) const override;
89
93 bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const override;
94
100 const ext::ptr_vector < UnboundedRegExpElement < SymbolType > > & getElements ( ) const;
101
107 const ext::ptr_vector < UnboundedRegExpElement < SymbolType > > & getElements ( );
108
114 void appendElement ( UnboundedRegExpElement < SymbolType > && element );
115
121 void appendElement ( const UnboundedRegExpElement < SymbolType > & element );
122
126 std::strong_ordering operator <=> ( const UnboundedRegExpElement < SymbolType > & other ) const override {
127 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
128
129 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
130 }
131
139 std::strong_ordering operator <=> ( const UnboundedRegExpConcatenation < SymbolType > & ) const;
140
144 bool operator == ( const UnboundedRegExpElement < SymbolType > & other ) const override {
145 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
146
147 return false;
148 }
149
158
162 void operator >>( ext::ostream & out ) const override;
163
169
170 for ( UnboundedRegExpElement < SymbolType > && element : ext::make_mover ( std::move ( * this ).getChildren ( ) ) )
171 res->appendElement ( std::move ( * std::move ( element ).normalize ( ) ) );
172
174 }
175};
176
177} /* namespace regexp */
178
179#include "../formal/FormalRegExpConcatenation.h"
180#include "../formal/FormalRegExpEpsilon.h"
181
182namespace regexp {
183
184template < class SymbolType >
186 return this->getChildren();
187}
188
189template < class SymbolType >
191 return this->getChildren();
192}
193
194template < class SymbolType >
196 this->pushBackChild ( std::move ( element ) );
197}
198
199template < class SymbolType >
201 this->appendElement ( ext::move_copy ( element ) );
202}
203
204template < class SymbolType >
206 return new UnboundedRegExpConcatenation ( * this );
207}
208
209template < class SymbolType >
210UnboundedRegExpConcatenation < SymbolType > * UnboundedRegExpConcatenation < SymbolType >::clone ( ) && {
211 return new UnboundedRegExpConcatenation ( std::move ( * this ) );
212}
213
214template < class SymbolType >
216 if ( getElements ( ).empty ( ) ) return ext::smart_ptr < FormalRegExpElement < SymbolType > > ( new FormalRegExpEpsilon < SymbolType > ( ) );
217
218 ext::smart_ptr < FormalRegExpElement < SymbolType > > res = getElements ( )[ getElements ( ).size ( ) - 1 ].asFormal ( );
219
220 for ( size_t i = getElements ( ).size ( ) - 1; i >= 1; i-- )
221 res = ext::smart_ptr < FormalRegExpElement < SymbolType > > ( new FormalRegExpConcatenation < SymbolType > ( std::move ( * getElements ( )[ i - 1 ].asFormal ( ) ), std::move ( * res ) ) );
222
223 return res;
224}
225
226template < class SymbolType >
228 return getElements ( ) <=> other.getElements ( );
229}
230
231template < class SymbolType >
233 return getElements ( ) == other.getElements ( );
234}
235
236template < class SymbolType >
238 out << "(UnboundedRegExpConcatenation";
239
240 for ( const UnboundedRegExpElement < SymbolType > & element : this->getElements ( ) )
241 out << " " << element;
242
243 out << ")";
244}
245
246template < class SymbolType >
248 for ( const UnboundedRegExpElement < SymbolType > & element : this->getElements ( ) )
249 if ( element.testSymbol ( symbol ) ) return true;
250
251 return false;
252}
253
254template < class SymbolType >
256 for ( const UnboundedRegExpElement < SymbolType > & element : this->getElements ( ) )
257 if ( ! element.checkAlphabet ( alphabet ) ) return false;
258
259 return true;
260}
261
262template < class SymbolType >
264 for ( const UnboundedRegExpElement < SymbolType > & element : this->getElements ( ) )
266}
267
268} /* namespace regexp */
269
271
Varary node is tree node that can hold any number of children.
Definition: tree_base.hpp:981
Definition: ostream.h:14
Implementation of vector storing dynamicaly allocated instances of given type. The class mimicks the ...
Definition: ptr_vector.hpp:44
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
Definition: FormalRegExpElement.h:62
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEpsilon.h:41
Represents the concatenation operator in the regular expression. The node can have 0 to n children in...
Definition: UnboundedRegExpConcatenation.h:44
UnboundedRegExpConcatenation< SymbolType > * clone() const &override
( ) const &
ext::smart_ptr< UnboundedRegExpElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: UnboundedRegExpConcatenation.h:167
void computeMinimalAlphabet(ext::set< SymbolType > &alphabet) const override
Definition: UnboundedRegExpConcatenation.h:263
void appendElement(UnboundedRegExpElement< SymbolType > &&element)
Definition: UnboundedRegExpConcatenation.h:195
void operator>>(ext::ostream &out) const override
< UnboundedRegExpElement < SymbolType > >::operator >> ( ext::ostream & )
Definition: UnboundedRegExpConcatenation.h:237
bool testSymbol(const SymbolType &symbol) const override
Definition: UnboundedRegExpConcatenation.h:247
ext::smart_ptr< FormalRegExpElement< SymbolType > > asFormal() const override
Definition: UnboundedRegExpConcatenation.h:215
std::strong_ordering operator<=>(const UnboundedRegExpElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const UnboundedRegExpElement < SymbolType > & other ) const;
Definition: UnboundedRegExpConcatenation.h:126
bool operator==(const UnboundedRegExpElement< SymbolType > &other) const override
< SymbolType >::operator == ( const UnboundedRegExpElement < SymbolType > & other ) const;
Definition: UnboundedRegExpConcatenation.h:144
const ext::ptr_vector< UnboundedRegExpElement< SymbolType > > & getElements() const
Definition: UnboundedRegExpConcatenation.h:185
bool checkAlphabet(const ext::set< SymbolType > &alphabet) const override
Definition: UnboundedRegExpConcatenation.h:255
UnboundedRegExpConcatenation()=default
Creates a new instance of the concatenation node. By default it is semantically equivalent to epsilon...
Definition: UnboundedRegExpElement.h:81
Definition: UnboundedRegExpElement.h:67
virtual void visit(const UnboundedRegExpAlternation< SymbolType > &)=0
Definition: UnboundedRegExpElement.h:62
Definition: BarSymbol.cpp:12
int i
Definition: AllEpsilonClosure.h:118
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
Definition: sigHandler.cpp:20
auto move_copy(const T &param)
Allow moving of copied instance of the source.
Definition: utility.hpp:45
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
Definition: ToAutomaton.h:15
Definition: FordFulkerson.hpp:16