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
UnboundedRegExpSymbol.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
29
30namespace regexp {
31
41template < class SymbolType >
42class UnboundedRegExpSymbol : public ext::NullaryNode < UnboundedRegExpElement < SymbolType > > {
46 SymbolType m_symbol;
47
51 void accept ( typename UnboundedRegExpElement < SymbolType >::Visitor & visitor ) const & override {
52 visitor.visit ( * this );
53 }
54
58 void accept ( typename UnboundedRegExpElement < SymbolType >::RvalueVisitor & visitor ) && override {
59 visitor.visit ( std::move ( * this ) );
60 }
61
62public:
68 explicit UnboundedRegExpSymbol ( SymbolType symbol );
69
74
78 UnboundedRegExpSymbol < SymbolType > * clone ( ) && override;
79
83 ext::smart_ptr < FormalRegExpElement < SymbolType > > asFormal ( ) const override;
84
88 bool testSymbol ( const SymbolType & symbol ) const override;
89
93 void computeMinimalAlphabet ( ext::set < SymbolType > & alphabet ) const override;
94
98 bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const override;
99
105 const SymbolType & getSymbol ( ) const &;
106
112 SymbolType && getSymbol ( ) &&;
113
117 std::strong_ordering operator <=> ( const UnboundedRegExpElement < SymbolType > & other ) const override {
118 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
119
120 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
121 }
122
130 std::strong_ordering operator <=> ( const UnboundedRegExpSymbol < SymbolType > & ) const;
131
135 bool operator == ( const UnboundedRegExpElement < SymbolType > & other ) const override {
136 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
137
138 return false;
139 }
140
149
153 void operator >>( ext::ostream & out ) const override;
154
160 }
161};
162
163} /* namespace regexp */
164
166#include "../formal/FormalRegExpSymbol.h"
167
168namespace regexp {
169
170template < class SymbolType >
171UnboundedRegExpSymbol < SymbolType >::UnboundedRegExpSymbol ( SymbolType symbol ) : m_symbol ( std::move ( symbol ) ) {
172}
173
174template < class SymbolType >
176 return new UnboundedRegExpSymbol ( * this );
177}
178
179template < class SymbolType >
180UnboundedRegExpSymbol < SymbolType > * UnboundedRegExpSymbol < SymbolType >::clone ( ) && {
181 return new UnboundedRegExpSymbol ( std::move ( * this ) );
182}
183
184template < class SymbolType >
187}
188
189template < class SymbolType >
191 return m_symbol <=> other.m_symbol;
192}
193
194template < class SymbolType >
196 return m_symbol == other.m_symbol;
197}
198
199template < class SymbolType >
201 out << "(UnboundedRegExpSymbol " << m_symbol << ")";
202}
203
204template < class SymbolType >
206 return symbol == this->m_symbol;
207}
208
209template < class SymbolType >
211 return alphabet.count ( m_symbol );
212}
213
214template < class SymbolType >
216 alphabet.insert ( this->m_symbol );
217}
218
219template < class SymbolType >
221 return this->m_symbol;
222}
223
224template < class SymbolType >
226 return std::move ( this->m_symbol );
227}
228
229} /* namespace regexp */
230
232
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Nullary node is specialisation of Anyary node to no children.
Definition: tree_base.hpp:358
Definition: ostream.h:14
Definition: set.hpp:44
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
Definition: typeindex.h:37
Definition: FormalRegExpElement.h:62
Represents the symbol in the regular expression. The can't have any children.
Definition: FormalRegExpSymbol.h:42
Definition: UnboundedRegExpElement.h:81
Definition: UnboundedRegExpElement.h:67
virtual void visit(const UnboundedRegExpAlternation< SymbolType > &)=0
Definition: UnboundedRegExpElement.h:62
Represents the symbol in the regular expression. The can't have any children.
Definition: UnboundedRegExpSymbol.h:42
bool checkAlphabet(const ext::set< SymbolType > &alphabet) const override
Definition: UnboundedRegExpSymbol.h:210
const SymbolType & getSymbol() const &
Definition: UnboundedRegExpSymbol.h:220
ext::smart_ptr< FormalRegExpElement< SymbolType > > asFormal() const override
Definition: UnboundedRegExpSymbol.h:185
void operator>>(ext::ostream &out) const override
< UnboundedRegExpElement < SymbolType > >::operator >> ( ext::ostream & )
Definition: UnboundedRegExpSymbol.h:200
ext::smart_ptr< UnboundedRegExpElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: UnboundedRegExpSymbol.h:158
void computeMinimalAlphabet(ext::set< SymbolType > &alphabet) const override
Definition: UnboundedRegExpSymbol.h:215
bool operator==(const UnboundedRegExpElement< SymbolType > &other) const override
< SymbolType >::operator == ( const UnboundedRegExpElement < SymbolType > & other ) const;
Definition: UnboundedRegExpSymbol.h:135
bool testSymbol(const SymbolType &symbol) const override
Definition: UnboundedRegExpSymbol.h:205
UnboundedRegExpSymbol(SymbolType symbol)
Creates a new instance of the symbol node using the actual symbol to represent.
Definition: UnboundedRegExpSymbol.h:171
std::strong_ordering operator<=>(const UnboundedRegExpElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const UnboundedRegExpElement < SymbolType > & other ) const;
Definition: UnboundedRegExpSymbol.h:117
UnboundedRegExpSymbol< SymbolType > * clone() const &override
( ) const &
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: sigHandler.cpp:20
Definition: ToAutomaton.h:15
Definition: FordFulkerson.hpp:16