Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
UnboundedRegExpAlternation.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 UnboundedRegExpAlternation : 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 UnboundedRegExpAlternation ( ) = 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 UnboundedRegExpAlternation < 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/FormalRegExpAlternation.h"
180#include "../formal/FormalRegExpEmpty.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 UnboundedRegExpAlternation ( * this );
207}
208
209template < class SymbolType >
210UnboundedRegExpAlternation < SymbolType > * UnboundedRegExpAlternation < SymbolType >::clone ( ) && {
211 return new UnboundedRegExpAlternation ( std::move ( * this ) );
212}
213
214template < class SymbolType >
216 if ( getElements ( ).empty ( ) ) return ext::smart_ptr < FormalRegExpElement < SymbolType > > ( new FormalRegExpEmpty < 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 FormalRegExpAlternation < 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 << "(UnboundedRegExpAlternation";
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 alternation operator in the regular expression. The node must have exactly two childre...
Definition: FormalRegExpAlternation.h:44
Definition: FormalRegExpElement.h:62
Represents the empty expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEmpty.h:41
Represents the alternation operator in the regular expression. The node can have 0 to n children in l...
Definition: UnboundedRegExpAlternation.h:44
bool operator==(const UnboundedRegExpElement< SymbolType > &other) const override
< SymbolType >::operator == ( const UnboundedRegExpElement < SymbolType > & other ) const;
Definition: UnboundedRegExpAlternation.h:144
ext::smart_ptr< UnboundedRegExpElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: UnboundedRegExpAlternation.h:167
ext::smart_ptr< FormalRegExpElement< SymbolType > > asFormal() const override
Definition: UnboundedRegExpAlternation.h:215
void operator>>(ext::ostream &out) const override
< UnboundedRegExpElement < SymbolType > >::operator >> ( ext::ostream & )
Definition: UnboundedRegExpAlternation.h:237
UnboundedRegExpAlternation()=default
Creates a new instance of the alternation node. By default it is semantically equivalent to empty reg...
bool checkAlphabet(const ext::set< SymbolType > &alphabet) const override
Definition: UnboundedRegExpAlternation.h:255
void computeMinimalAlphabet(ext::set< SymbolType > &alphabet) const override
Definition: UnboundedRegExpAlternation.h:263
UnboundedRegExpAlternation< SymbolType > * clone() const &override
( ) const &
void appendElement(UnboundedRegExpElement< SymbolType > &&element)
Definition: UnboundedRegExpAlternation.h:195
std::strong_ordering operator<=>(const UnboundedRegExpElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const UnboundedRegExpElement < SymbolType > & other ) const;
Definition: UnboundedRegExpAlternation.h:126
const ext::ptr_vector< UnboundedRegExpElement< SymbolType > > & getElements() const
Definition: UnboundedRegExpAlternation.h:185
bool testSymbol(const SymbolType &symbol) const override
Definition: UnboundedRegExpAlternation.h:247
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